summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/string.h48
-rw-r--r--src/util/typedef.h4
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>