5extern bool digit_valid(
char digit,
int base);
9 type_signed_int, type_unsigned_int,
10 type_signed_long, type_unsigned_long,
11 type_signed_long_long, type_unsigned_long_long,
12 type_signed_int32, type_unsigned_int32,
13 type_signed_int64, type_unsigned_int64,
14 type_signed_size, type_unsigned_size,
22 enum format_type type : 5;
23 unsigned int max_precision: 12;
24 unsigned int pad_width: 6;
26 unsigned int zero_pad: 1;
27 unsigned int capitalise: 1;
28 unsigned int have_precision: 1;
39 case '0': specifier.zero_pad =
true;
break;
40 case 'X': specifier.base = 16; specifier.capitalise =
true;
break;
41 case 'x': specifier.base = 16;
break;
42 case 'o': specifier.base = 8;
break;
43 case 'b': specifier.base = 2;
break;
44 default:
goto read_width;
57 specifier.have_precision = 1;
59 specifier.max_precision = 0;
60 specifier.have_precision =
false;
66 specifier.type = type_signed_size;
68 specifier.type = type_unsigned_size;
70 specifier.type = type_signed_int32;
72 specifier.type = type_unsigned_int32;
74 specifier.type = type_signed_int64;
76 specifier.type = type_unsigned_int64;
78 specifier.type = type_ptr;
80 specifier.type = type_clod_string;
82 specifier.type = type_signed_long_long;
84 specifier.type = type_unsigned_long_long;
86 specifier.type = type_signed_long;
88 specifier.type = type_unsigned_long;
90 specifier.type = type_signed_int;
92 specifier.type = type_unsigned_int;
94 specifier.type = type_double;
96 specifier.type = type_string;
106 size_t size = clod_string_vformat(dst, fmt, args);
129 if (specifier.base == 0) {
130 if (specifier.type == type_ptr) {
137 const struct clod_string digit_alphabet = specifier.capitalise ? CLOD_STRING_DIGIT_ALPHABET_CAPS : CLOD_STRING_DIGIT_ALPHABET;
139 switch (specifier.type) {
140 case type_signed_int:
142 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
144 case type_unsigned_int:
146 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
148 case type_signed_long:
150 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
152 case type_unsigned_long:
154 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
156 case type_signed_long_long:
158 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
160 case type_unsigned_long_long:
162 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
164 case type_signed_int32:
166 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
168 case type_unsigned_int32:
170 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
172 case type_signed_int64:
174 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
176 case type_unsigned_int64:
178 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
180 case type_signed_size:
182 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
184 case type_unsigned_size:
186 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
192 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
196 digit_alphabet, specifier.base, specifier.pad_width, (
unsigned char)specifier.max_precision);
198 case type_clod_string:
CLOD_API bool clod_string_remove_prefix(struct clod_string *str, struct clod_string prefix)
#define CLOD_STRING_C(cstr)
String literal constant.
size_t clod_string_cat(struct clod_string *dst, struct clod_string src)
CLOD_API size_t clod_string_put_int(struct clod_string *dst, intmax_t val, struct clod_string alphabet, unsigned char base, unsigned char min_digits, unsigned char max_digits)
CLOD_API size_t clod_string_put_uint(struct clod_string *dst, uintmax_t val, struct clod_string alphabet, unsigned char base, unsigned char min_digits, unsigned char max_digits)
CLOD_API size_t clod_string_put_double(struct clod_string *dst, double val, struct clod_string alphabet, unsigned char base, unsigned char min_digits, unsigned char max_digits)
struct clod_string clod_string_from_cstr(const char *cstr)
Make a string from a C string.
char clod_string_get_char(struct clod_string *str)
Remove a single char from the start of the string.
CLOD_API uintmax_t clod_string_get_uint(struct clod_string *str, struct clod_string alphabet, unsigned char base)
char clod_string_peek_char(struct clod_string str)
Get the first char in the string.
void clod_string_put_char(struct clod_string *str, char c)
Append a single char to the end of the string.