2022-05-26 19:17:29 -04:00
|
|
|
#include <kernaux/printf_fmt.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2022-05-26 21:25:58 -04:00
|
|
|
{
|
|
|
|
const char *format = "s";
|
|
|
|
|
|
|
|
struct KernAux_PrintfFmt_Spec spec = KernAux_PrintfFmt_Spec_create();
|
2022-05-28 05:08:48 -04:00
|
|
|
|
2022-05-28 05:16:38 -04:00
|
|
|
format = KernAux_PrintfFmt_Spec_parse(&spec, format);
|
2022-05-28 05:08:48 -04:00
|
|
|
|
|
|
|
if (spec.set_width) {
|
2022-05-26 21:25:58 -04:00
|
|
|
// Actually this line won't be executed.
|
2022-05-28 04:56:48 -04:00
|
|
|
KernAux_PrintfFmt_Spec_set_width(&spec, 0);
|
2022-05-26 21:25:58 -04:00
|
|
|
}
|
2022-05-28 05:08:48 -04:00
|
|
|
if (spec.set_precision) {
|
2022-05-26 21:25:58 -04:00
|
|
|
// Actually this line won't be executed.
|
2022-05-28 04:56:48 -04:00
|
|
|
KernAux_PrintfFmt_Spec_set_precision(&spec, 0);
|
2022-05-26 21:25:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(spec.flags == 0);
|
|
|
|
assert(spec.width == 0);
|
|
|
|
assert(spec.precision == 0);
|
|
|
|
assert(spec.type == KERNAUX_PRINTF_FMT_TYPE_STR);
|
|
|
|
assert(spec.base == 0);
|
|
|
|
}
|
|
|
|
|
2022-05-26 19:17:29 -04:00
|
|
|
{
|
|
|
|
const char *format = "012.34f";
|
|
|
|
|
|
|
|
struct KernAux_PrintfFmt_Spec spec = KernAux_PrintfFmt_Spec_create();
|
2022-05-28 05:08:48 -04:00
|
|
|
|
2022-05-28 05:16:38 -04:00
|
|
|
// Parsing of each part may be done separately.
|
2022-05-28 04:56:48 -04:00
|
|
|
KernAux_PrintfFmt_Spec_parse_flags(&spec, &format);
|
2022-05-28 05:08:48 -04:00
|
|
|
KernAux_PrintfFmt_Spec_parse_width(&spec, &format);
|
|
|
|
KernAux_PrintfFmt_Spec_parse_precision(&spec, &format);
|
|
|
|
KernAux_PrintfFmt_Spec_parse_length(&spec, &format);
|
|
|
|
KernAux_PrintfFmt_Spec_parse_type(&spec, &format);
|
|
|
|
|
|
|
|
if (spec.set_width) {
|
2022-05-26 21:25:58 -04:00
|
|
|
// Actually this line won't be executed.
|
2022-05-28 04:56:48 -04:00
|
|
|
KernAux_PrintfFmt_Spec_set_width(&spec, 0);
|
2022-05-26 19:17:29 -04:00
|
|
|
}
|
2022-05-28 05:08:48 -04:00
|
|
|
if (spec.set_precision) {
|
2022-05-26 21:25:58 -04:00
|
|
|
// Actually this line won't be executed.
|
2022-05-28 04:56:48 -04:00
|
|
|
KernAux_PrintfFmt_Spec_set_precision(&spec, 0);
|
2022-05-26 19:17:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(
|
|
|
|
spec.flags ==
|
|
|
|
(
|
|
|
|
KERNAUX_PRINTF_FMT_FLAGS_ZEROPAD |
|
|
|
|
KERNAUX_PRINTF_FMT_FLAGS_PRECISION
|
|
|
|
)
|
|
|
|
);
|
|
|
|
assert(spec.width == 12);
|
|
|
|
assert(spec.precision == 34);
|
|
|
|
assert(spec.type == KERNAUX_PRINTF_FMT_TYPE_FLOAT);
|
|
|
|
assert(spec.base == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2022-05-28 05:16:38 -04:00
|
|
|
const char *const format = " *.*ld";
|
2022-05-26 19:17:29 -04:00
|
|
|
|
|
|
|
struct KernAux_PrintfFmt_Spec spec = KernAux_PrintfFmt_Spec_create();
|
2022-05-28 05:08:48 -04:00
|
|
|
|
2022-05-28 05:16:38 -04:00
|
|
|
// Returning value may be ignored.
|
|
|
|
KernAux_PrintfFmt_Spec_parse(&spec, format);
|
2022-05-28 05:08:48 -04:00
|
|
|
|
|
|
|
if (spec.set_width) {
|
2022-05-28 04:56:48 -04:00
|
|
|
KernAux_PrintfFmt_Spec_set_width(&spec, 12);
|
2022-05-26 19:17:29 -04:00
|
|
|
}
|
2022-05-28 05:08:48 -04:00
|
|
|
if (spec.set_precision) {
|
2022-05-28 04:56:48 -04:00
|
|
|
KernAux_PrintfFmt_Spec_set_precision(&spec, 34);
|
2022-05-26 19:17:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(
|
|
|
|
spec.flags ==
|
|
|
|
(
|
|
|
|
KERNAUX_PRINTF_FMT_FLAGS_SPACE |
|
|
|
|
KERNAUX_PRINTF_FMT_FLAGS_LONG |
|
|
|
|
KERNAUX_PRINTF_FMT_FLAGS_PRECISION
|
|
|
|
)
|
|
|
|
);
|
|
|
|
assert(spec.width == 12);
|
|
|
|
assert(spec.precision == 34);
|
|
|
|
assert(spec.type == KERNAUX_PRINTF_FMT_TYPE_INT);
|
|
|
|
assert(spec.base == 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|