diff options
| author | aura <nw@moneybot.cc> | 2026-03-16 10:15:01 +0100 |
|---|---|---|
| committer | aura <nw@moneybot.cc> | 2026-03-16 10:15:01 +0100 |
| commit | fdc5e8760fb7ac0af8e7ebb98a2076db15e31082 (patch) | |
| tree | c94991e1e594c7703295aa413caf40786f343c1f /src/util/string.h | |
| parent | e2829336cfedb39d23263f75b61ed969c8193534 (diff) | |
giga refactor, fix ALL the leaks
Diffstat (limited to 'src/util/string.h')
| -rw-r--r-- | src/util/string.h | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/util/string.h b/src/util/string.h index 6d44b53..7dfab69 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -54,23 +54,19 @@ struct ARRSTR { template <typename CT> struct __str : public LIST<CT> { __str() : LIST<CT>() {} - __str( U32 count, const CT* str ) { - this->data = 0; - this->capacity = this->size = 0; + __str( U32 count, const CT* str ) : LIST<CT>() { this->reserve( count * 2 ); memcpy( this->data, str, count ); this->size = count; this->data[this->size] = 0; } - __str( const CT* fmt, ... ) { + __str( const CT* fmt, ... ) : LIST<CT>() { va_list args; va_start( args, fmt ); va_list args2; va_copy( args2, args ); U32 c = vsnprintf( 0, 0, fmt, args ); va_end( args ); - this->data = 0; - this->capacity = this->size = 0; this->reserve( c * 2 ); vsnprintf( this->data, c + 1, fmt, args2 ); this->data[c] = 0; @@ -89,8 +85,6 @@ struct __str : public LIST<CT> { if( this->data && this->data != other.data ) free( this->data ); - this->data = 0; - if( !other.capacity || !other.size ) { this->capacity = 1; this->size = 0; @@ -116,8 +110,9 @@ struct __str : public LIST<CT> { __str<CT> operator+( const CT rhs ) { __str<CT> ret = *this; ret.push( rhs ); return ret; } __str<CT>& operator+=( const __str<CT>& rhs ) { return this->append( rhs ); } __str<CT>& operator+=( const CT* rhs ) { return this->append( rhs ); } - __str<CT>& operator+=( const CT rhs ) { this->push( rhs ); return this; } + __str<CT>& operator+=( const CT rhs ) { this->push( rhs ); return *this; } + operator const CT*() { return this->data; } operator CT*() { return this->data; } CT operator[]( U32 i ) { @@ -128,10 +123,8 @@ struct __str : public LIST<CT> { if( rhs.size != this->size ) return 0; - for( U32 i = 0; i < this->size; ++i ) { - if( this->data[i] != rhs.data[i] ) - return 0; - } + if( !!memcmp( this->data, rhs.data, this->size ) ) + return 0; return 1; } @@ -165,7 +158,7 @@ struct __str : public LIST<CT> { __str<CT>& append( const CT* str ) { U32 len; for( len = 0; !!str[len]; ++len ); - if( this->size + len + 1 > this->capacity ) + if( this->size + len + 1 >= this->capacity ) this->reserve( this->size + len + 1 ); memcpy( this->data + this->size, str, len * sizeof(CT) ); @@ -179,7 +172,7 @@ struct __str : public LIST<CT> { if( this->size + len + 1 >= this->capacity ) this->reserve( this->size + len + 1 ); - memcpy( this->data + this->size, str, len * sizeof(CT) ); + memcpy( this->data + this->size, str.data, len * sizeof(CT) ); this->size += len; this->data[this->size] = 0; return *this; |
