View Single Post
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 06-25-2015 , 14:47   Re: [INC] DString - Dynamic Strings
Reply With Quote #8

Try this one out, I fixed the property line and added the missing 'new' in DString_Create. Creating the methodmap first allows the stock functions to use the methodmap; if you look at the stock functions, some handles use both DataPack and DString methods.

PHP Code:
/**************************************************************************
 *                                                                        *
 *                       DString - Dynamic Strings                        *
 *                            Author: Eun                                 *
 *                           Version: 1.0.1 Emp`s changes                 *
 *                                                                        *
 **************************************************************************/

#if defined _DSTRING_INCLUDED
  #endinput
#endif
#define _DSTRING_INCLUDED

#if !defined DSTRING_BUFFERLEN
    #define DSTRING_BUFFERLEN 4048
#endif

methodmap DString DataPack
{
    public 
DString() = DString_Create;

    public 
Copy() = DString_Copy;
    public 
Format() = DString_Format;

    public 
Add() = DString_Add;
    public 
AddEx() = DString_AddEx;

    public 
Read() = DString_Read;
    public 
ReadEx() = DString_ReadEx;

    
property int Length
    
{
        public 
get() { return DString_Lengththis ); }
    }

    public 
Clear() = DString_Clear;
}

stock DString DString_Create( const char[] str "" )
{
    
DString handle view_as DString > new DataPack();
    
int len strlenstr );
    if ( 
len )
    {
        
handle.WriteCelllen );
        
handle.WriteStringstr );
    }
    return 
handle;
}

stock int DString_CopyDString handle, const char[] str )
{
    
int len strlenstr );
    if ( !
handle ) return 0;
    
handle.Resettrue );
    
handle.WriteCelllen );
    
handle.WriteStringstr );
    return 
len;
}
stock int DString_FormatDString handle, const char[] strany ... )
{
    
char bufferDSTRING_BUFFERLEN ];
    
VFormatbuffersizeof bufferstr);
    return 
handle.Copyhandlebuffer );
}

stock int DString_AddDString handle, const char[] str )
{
    
int len handle.Length();
    
int len_add strlenstr );
    if ( !
len_add ) return len;
    
int len_new len len_add
    char
[] buffer = new charlen_new ];
    if ( 
len handle.ReadStringbufferlen );
    
strcopybufferlen ], len_addstr );
    return 
handle.Copybuffer );
}
stock int DString_AddExDString handle, const char[] strany ... )
{
    
char bufferDSTRING_BUFFERLEN ];
    
VFormatbuffersizeof bufferstr);
    return 
handle.Addbuffer );
}

stock int DString_ReadDString handlechar[] bufferint buffersize )
{
    
int len handle.Length();
    if ( 
len handle.ReadStringbufferbuffersize );
    return 
len;
}
stock char[] DString_ReadExDString handle )
{
    
int len handle.Length();
    
char[] buffer = new charlen ];
    
handle.Readbufferlen );
    return 
buffer;
}

stock int DString_LengthDString handle )
{
    if ( !
handle ) return 0;
    
handle.Resetfalse );
    if ( !
handle.IsReadable) ) return 0;
    return 
handle.ReadCell();
}
stock void DString_ClearDString handle )
{
    
handle.Resettrue );
}

stock void DString_DeleteDString &handle )
{
    
delete handle;


Last edited by Emp`; 06-25-2015 at 14:51. Reason: changed code to php tag for pretty colors
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`