CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
format_private.h
1#pragma once
2
3#include "cx/container.h"
4#include "cx/string.h"
5#include "format.h"
6
7enum FORMAT_TYPES {
8 FMT_string,
9 FMT_int,
10 FMT_uint,
11 FMT_float,
12 FMT_ptr,
13 FMT_suid,
14 FMT_object,
15 FMT_count
16};
17extern strref _fmtTypeNames[FMT_count];
18extern uint32 _fmtTypeIdMask[FMT_count][2];
19extern bool (*_fmtTypeParseOpt[FMT_count])(FMTVar* v, strref opt);
20extern bool (*_fmtTypeParseFinalize[FMT_count])(FMTVar* v);
21extern bool (*_fmtTypeFormat[FMT_count])(FMTVar* v, string* out);
22
23typedef struct FMTContext {
24 int32 nargs;
25 stvar* args;
26 int32 startarg[FMT_count]; // where to start searching for each type
27 int32 arrayidx; // arrary index counter
28
29 string tmp; // temporary storage for high-level operations
30 string* dest; // output string so far
31
32 string fmt; // format string parse state
33 int32 vstart;
34 int32 vend;
35 int32 flen;
36
37 FMTVar v; // current variable
38} FMTContext;
39
40bool _fmtExtractVar(_Inout_ FMTContext* ctx);
41bool _fmtParseVar(_Inout_ FMTContext* ctx);
42bool _fmtFindData(_Inout_ FMTContext* ctx);
43void _fmtFormat(_Inout_ FMTContext* ctx);
44
45// Locate a keyed argument by name. Returns its index, or -1 if no argument carries that
46// key. Scans the whole list and touches no per-type cursor -- keyed arguments are
47// order-free by design.
48int32 _fmtFindKeyed(_In_ FMTContext* ctx, _In_ strref key);
49
50// Map a keyed argument's runtime type onto a FORMAT_TYPES value, for "${:key}" where the
51// type name is omitted. When the placeholder subscripts a container, the container's
52// element/value type is used instead. Returns -1 if the argument is missing, is not the
53// container kind the placeholder expects, or has a type the formatter cannot render.
54int _fmtTypeFromKey(_In_ FMTContext* ctx, _In_ strref key, bool isarray, bool ishash);
55
56// type-specific formatters
57bool _fmtParseStringOpt(_Inout_ FMTVar* v, _In_ strref opt);
58bool _fmtString(_Inout_ FMTVar* v, _Inout_ string* out);
59bool _fmtParseIntOpt(_Inout_ FMTVar* v, _In_ strref opt);
60bool _fmtParseIntFinalize(_Inout_ FMTVar* v);
61bool _fmtInt(_Inout_ FMTVar* v, _Inout_ string* out);
62bool _fmtParseFloatOpt(_Inout_ FMTVar* v, _In_ strref opt);
63bool _fmtParseFloatFinalize(_Inout_ FMTVar* v);
64bool _fmtFloat(_Inout_ FMTVar* v, _Inout_ string* out);
65bool _fmtParsePtrOpt(_Inout_ FMTVar* v, _In_ strref opt);
66bool _fmtParsePtrFinalize(_Inout_ FMTVar* v);
67bool _fmtParseObjectOpt(_Inout_ FMTVar* v, _In_ strref opt);
68bool _fmtPtr(_Inout_ FMTVar* v, _Inout_ string* out);
69bool _fmtSUID(_Inout_ FMTVar* v, _Inout_ string* out);
70bool _fmtObject(_Inout_ FMTVar* v, _Inout_ string* out);
Generic type-safe containers with runtime type system integration.
#define stvar(typen, val)
Definition stvar.h:162
Copy-on-write strings with automatic memory management and rope optimization.
Format variable descriptor for Formattable interface implementations.
Definition format.h:226