DString - Dynamic Strings
About
Allows you to use strings with dynamic lengths.
Functions
PHP Code:
/**
* Creates a new empty DString instance
*/
Handle DString_Create();
/**
* Deletes a DString instance
*/
void DString_Delete(Handle handle);
/**
* Adds String to DString instance
* Returns the characters that have been written
*/
int DString_Add(Handle handle, const char[] str);
/**
* Adds a formated String to DString instance
* Returns the characters that have been written
*/
int DString_AddEx(Handle handle, const char[] str, any ...);
/**
* Reads the String of a DString instance
* Returns the characters that have been read
*/
int DString_Read(Handle handle, char[] buffer, int buffersize);
/**
* Wipes contents of a DString instance
*/
void DString_Clear(Handle handle);
/**
* Returns the current length of a DString instance
*/
int DString_Length(Handle handle);
/**
* Returns a clone of the current instance
*/
Handle DString_Clone(Handle handle);
Example
PHP Code:
#include <sourcemod>
#include <DString.inc>
public void Test()
{
// creating instance
Handle handle = DString_Create();
// adding 'Hello!' and printing how many chars were added
PrintToServer("Written %d", DString_Add(handle, "Hello!"));
// adding formated text
PrintToServer("Written %d", DString_AddEx(handle, " The GameTime is %f", GetGameTime()));
// reading the whole string
char[] buffer = new char[DString_Length(handle)+1];
DString_Read(handle, buffer, DString_Length(handle)+1);
PrintToServer("DString is '%s'", buffer);
// cloning
Handle clone = DString_Clone(handle);
// delete the old one
DString_Delete(handle);
// reading the clone
char[] bufferclone = new char[DString_Length(clone)+1];
DString_Read(clone, bufferclone, DString_Length(clone)+1);
PrintToServer("DString clone is '%s'", bufferclone);
// delete the clone
DString_Delete(clone);
}
public void TestUsingMethodMap()
{
// creating instance
DString handle = new DString();
// adding 'Hello!' and printing how many chars were added
PrintToServer("Written %d", handle.Add("Hello!"));
// adding formated text
PrintToServer("Written %d", handle.AddEx(" The GameTime is %f", GetGameTime()));
// reading the whole string
char[] buffer = new char[handle.Length+1];
handle.Read(buffer, handle.Length+1);
PrintToServer("DString is '%s'", buffer);
// cloning
DString clone = handle.Clone();
// delete the old one
delete handle;
// reading the clone
char[] bufferclone = new char[clone.Length+1];
clone.Read(bufferclone, clone.Length+1);
PrintToServer("DString clone is '%s'", bufferclone);
// delete the clone
delete clone;
}
public void OnPluginStart()
{
Test();
TestUsingMethodMap();
}