View Single Post
Author Message
Eun
Member
Join Date: Jan 2011
Old 06-23-2015 , 07:04   [INC] DString - Dynamic Strings
Reply With Quote #1

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[] strany ...);

/**
 * Reads the String of a DString instance
 * Returns the characters that have been read
 */
int DString_Read(Handle handlechar[] bufferint 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(handlebufferDString_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, buffercloneDString_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(bufferhandle.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();

Attached Files
File Type: inc DString.inc (3.7 KB, 253 views)
File Type: inc DString.1.0.0.inc (2.5 KB, 172 views)

Last edited by Eun; 06-24-2015 at 04:42.
Eun is offline