diff options
| author | aura <nw@moneybot.cc> | 2026-03-17 12:04:30 +0100 |
|---|---|---|
| committer | day <day@national.shitposting.agency> | 2026-03-20 22:52:49 +0100 |
| commit | 34d410da50e76f12c3d011293f4b544330e8ba3e (patch) | |
| tree | c8335b5699dc40e5de6233891a3cbe154612a224 /src/util | |
| parent | 7cc07134a9759ed196b0fe5ea26c18d76e232952 (diff) | |
multi select
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/string.h | 48 | ||||
| -rw-r--r-- | src/util/typedef.h | 4 |
2 files changed, 38 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; diff --git a/src/util/typedef.h b/src/util/typedef.h index 53c4010..4a28624 100644 --- a/src/util/typedef.h +++ b/src/util/typedef.h @@ -29,7 +29,11 @@ typedef double F64; typedef unsigned long PTR; +// lambda macro - captures all by ref #define fn( ... ) [&]( __VA_ARGS__ ) +// lambda macro - captures all by copy +#define cfn( ... ) [=]( __VA_ARGS__ ) +// lambda macro - raw pointer func #define pfn( ... ) []( __VA_ARGS__ ) template <typename T> |
