CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
format.h
1#pragma once
2
4#include <cx/cx.h>
5#include <cx/stype/stvar.h>
6
170
171CX_C bool _strFormat(_Inout_ string* out, _In_ strref fmt, int n, _In_ stvar* args);
172
191#define strFormat(out, fmt, ...) \
192 _strFormat(out, fmt, count_macro_args(__VA_ARGS__), (stvar[]) { __VA_ARGS__ })
193
194// strFormat previously used the sizeof((stvariant[]){ __VA_ARGS__ })/sizeof(stvar)
195// contruction to count the arguments, but this caused MSVC to allocate double the stack
196// space and push duplicate argument lists for no reason! Falling back to the old school
197// macro trick instead.
198
206
211
215
216 FMTVar_Left = 0x0100,
217 FMTVar_Center = 0x0200,
218 FMTVar_Right = 0x0400,
219 FMTVar_Upper = 0x0800,
220 FMTVar_Lower = 0x1000,
221
222 // type-specific flags may use 0x00010000 - 0xffff0000
223};
224
226typedef struct FMTVar {
227 string var;
228 int32 vtype;
229 int32 idx;
230 int32 width;
231 sa_string fmtopts;
232 string def;
233 string tmp;
234
235 int32 arrayidx;
236 string hashkey;
237 string key;
238
239 uint32 flags;
240 uintptr fmtdata[4];
241
243 void* data;
245
247
FMTVarFlags
Format variable flags for Formattable interface implementations.
Definition format.h:208
@ FMTVar_NoGenWidth
no generic width handling
Definition format.h:210
@ FMTVar_Upper
uppercase option
Definition format.h:219
@ FMTVar_Right
right format option
Definition format.h:218
@ FMTVar_SignPrefix
had the - prefix to leave space for sign
Definition format.h:212
@ FMTVar_Left
left format option
Definition format.h:216
@ FMTVar_NoGenCase
no generic case conversions
Definition format.h:209
@ FMTVar_LeadingZeros
had the 0 prefix to add leading zeros
Definition format.h:214
@ FMTVar_SignAlways
had the + prefix to always print sign
Definition format.h:213
@ FMTVar_Center
center format option
Definition format.h:217
@ FMTVar_Lower
lowercase option
Definition format.h:220
#define stvar(typen, val)
Definition stvar.h:162
Dynamic arrays with type-safe generic programming.
Format variable descriptor for Formattable interface implementations.
Definition format.h:226
string tmp
temporary storage for variable-level operations
Definition format.h:233
string def
default text
Definition format.h:232
int32 width
field width
Definition format.h:230
string hashkey
hashtable lookup key, from ${type[key]}
Definition format.h:236
uintptr fmtdata[4]
type-specific format data
Definition format.h:240
string var
(unparsed) variable descriptor
Definition format.h:227
sa_string fmtopts
variable format options (other than width)
Definition format.h:231
int32 idx
explicit index (1-based)
Definition format.h:229
uint32 flags
format flags
Definition format.h:239
int32 vtype
variable type
Definition format.h:228
stype type
original type
Definition format.h:242
string key
keyed-argument name, from ${type:key}
Definition format.h:237
int32 arrayidx
array index (or -1)
Definition format.h:235
void * data
data backing up this variable
Definition format.h:243
Variant type containers and type-safe variadic argument support.