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
109
110CX_C bool _strFormat(_Inout_ string* out, _In_ strref fmt, int n, _In_ stvar* args);
111
130#define strFormat(out, fmt, ...) \
131 _strFormat(out, fmt, count_macro_args(__VA_ARGS__), (stvar[]) { __VA_ARGS__ })
132
133// strFormat previously used the sizeof((stvariant[]){ __VA_ARGS__ })/sizeof(stvar)
134// contruction to count the arguments, but this caused MSVC to allocate double the stack
135// space and push duplicate argument lists for no reason! Falling back to the old school
136// macro trick instead.
137
145
150
154
155 FMTVar_Left = 0x0100,
156 FMTVar_Center = 0x0200,
157 FMTVar_Right = 0x0400,
158 FMTVar_Upper = 0x0800,
159 FMTVar_Lower = 0x1000,
160
161 // type-specific flags may use 0x00010000 - 0xffff0000
162};
163
165typedef struct FMTVar {
166 string var;
167 int32 vtype;
168 int32 idx;
169 int32 width;
170 sa_string fmtopts;
171 string def;
172 string tmp;
173
174 int32 arrayidx;
175 string hashkey;
176
177 uint32 flags;
178 uintptr fmtdata[4];
179
180 stype type;
181 void* data;
183
185
FMTVarFlags
Format variable flags for Formattable interface implementations.
Definition format.h:147
@ FMTVar_NoGenWidth
no generic width handling
Definition format.h:149
@ FMTVar_Upper
uppercase option
Definition format.h:158
@ FMTVar_Right
right format option
Definition format.h:157
@ FMTVar_SignPrefix
had the - prefix to leave space for sign
Definition format.h:151
@ FMTVar_Left
left format option
Definition format.h:155
@ FMTVar_NoGenCase
no generic case conversions
Definition format.h:148
@ FMTVar_LeadingZeros
had the 0 prefix to add leading zeros
Definition format.h:153
@ FMTVar_SignAlways
had the + prefix to always print sign
Definition format.h:152
@ FMTVar_Center
center format option
Definition format.h:156
@ FMTVar_Lower
lowercase option
Definition format.h:159
#define stvar(typen, val)
Definition stvar.h:153
Dynamic arrays with type-safe generic programming.
Format variable descriptor for Formattable interface implementations.
Definition format.h:165
string tmp
temporary storage for variable-level operations
Definition format.h:172
string def
default text
Definition format.h:171
int32 width
field width
Definition format.h:169
string hashkey
hash key
Definition format.h:175
uintptr fmtdata[4]
type-specific format data
Definition format.h:178
string var
(unparsed) variable descriptor
Definition format.h:166
sa_string fmtopts
variable format options (other than width)
Definition format.h:170
int32 idx
explicit index (1-based)
Definition format.h:168
uint32 flags
format flags
Definition format.h:177
int32 vtype
variable type
Definition format.h:167
stype type
original type
Definition format.h:180
int32 arrayidx
array index (or -1)
Definition format.h:174
void * data
data backing up this variable
Definition format.h:181
Variant type containers and type-safe variadic argument support.