diff options
Diffstat (limited to 'src/util/string.h')
| -rw-r--r-- | src/util/string.h | 48 |
1 files changed, 34 insertions, 14 deletions
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 <cstdio> +#include <wchar.h> #include <stdarg.h> #include <string.h> @@ -65,12 +66,21 @@ struct __str : public LIST<CT> { 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<CT> { return 1; } - __str<CT>& fmt( const char* fmt, ... ) { + __str<CT>& 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; |
