From 34d410da50e76f12c3d011293f4b544330e8ba3e Mon Sep 17 00:00:00 2001 From: aura Date: Tue, 17 Mar 2026 12:04:30 +0100 Subject: multi select --- src/util/string.h | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) (limited to 'src/util/string.h') diff --git a/src/util/string.h b/src/util/string.h index 672fb5d..2725fd2 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include #include @@ -65,12 +66,21 @@ struct __str : public LIST { va_start( args, fmt ); va_list args2; va_copy( args2, args ); - U32 c = vsnprintf( 0, 0, fmt, args ); - va_end( args ); - this->reserve( c * 2 ); - vsnprintf( this->data, c + 1, fmt, args2 ); - this->data[c] = 0; - this->size = c; + if constexpr( sizeof( CT ) == 1 ) { + U32 c = vsnprintf( 0, 0, fmt, args ); + va_end( args ); + this->reserve( c * 2 ); + vsnprintf( this->data, c + 1, fmt, args2 ); + this->data[c] = 0; + this->size = c; + } else { + U32 c = vswprintf( 0, 0, fmt, args ); + va_end( args ); + this->reserve( c * 2 ); + vswprintf( this->data, c + 1, fmt, args2 ); + this->data[c] = 0; + this->size = c; + } va_end( args2 ); } @@ -138,18 +148,28 @@ struct __str : public LIST { return 1; } - __str& fmt( const char* fmt, ... ) { + __str& fmt( const CT* fmt, ... ) { va_list args; va_start( args, fmt ); va_list args2; va_copy( args2, args ); - U32 c = this->size + vsnprintf( 0, 0, fmt, args ); - va_end( args ); - if( c > this->capacity ) - this->reserve( c * 2 ); - vsnprintf( this->data + this->size, c + 1, fmt, args2 ); - this->data[c] = 0; - this->size = c; + if constexpr( sizeof( CT ) == 1 ) { + U32 c = this->size + vsnprintf( 0, 0, fmt, args ); + va_end( args ); + if( c > this->capacity ) + this->reserve( c * 2 ); + vsnprintf( this->data + this->size, c + 1, fmt, args2 ); + this->data[c] = 0; + this->size = c; + } else { + U32 c = this->size + vswprintf( 0, 0, fmt, args ); + va_end( args ); + if( c > this->capacity ) + this->reserve( c * 2 ); + vswprintf( this->data + this->size, c + 1, fmt, args2 ); + this->data[c] = 0; + this->size = c; + } va_end( args2 ); return *this; -- cgit v1.2.3