1111
1212#include " src/__support/macros/config.h"
1313#include " src/stdio/printf_core/core_structs.h"
14+ #include " src/stdio/printf_core/printf_config.h"
15+ #include " src/stdio/printf_core/strerror_converter.h"
1416#include " src/stdio/printf_core/writer.h"
1517
18+ // This option allows for replacing all of the conversion functions with custom
19+ // replacements. This allows conversions to be replaced at compile time.
20+ #ifndef LIBC_COPT_PRINTF_CONV_ATLAS
21+ #include " src/stdio/printf_core/converter_atlas.h"
22+ #else
23+ #include LIBC_COPT_PRINTF_CONV_ATLAS
24+ #endif
25+
1626#include < stddef.h>
1727
1828namespace LIBC_NAMESPACE_DECL {
@@ -21,7 +31,80 @@ namespace printf_core {
2131// convert will call a conversion function to convert the FormatSection into
2232// its string representation, and then that will write the result to the
2333// writer.
24- int convert (Writer *writer, const FormatSection &to_conv);
34+ template <WriteMode write_mode>
35+ int convert (Writer<write_mode> *writer, const FormatSection &to_conv) {
36+ if (!to_conv.has_conv )
37+ return writer->write (to_conv.raw_string );
38+
39+ #if !defined(LIBC_COPT_PRINTF_DISABLE_FLOAT) && \
40+ defined (LIBC_COPT_PRINTF_HEX_LONG_DOUBLE)
41+ if (to_conv.length_modifier == LengthModifier::L) {
42+ switch (to_conv.conv_name ) {
43+ case ' f' :
44+ case ' F' :
45+ case ' e' :
46+ case ' E' :
47+ case ' g' :
48+ case ' G' :
49+ return convert_float_hex_exp (writer, to_conv);
50+ default :
51+ break ;
52+ }
53+ }
54+ #endif // LIBC_COPT_PRINTF_DISABLE_FLOAT
55+
56+ switch (to_conv.conv_name ) {
57+ case ' %' :
58+ return writer->write (" %" );
59+ case ' c' :
60+ return convert_char (writer, to_conv);
61+ case ' s' :
62+ return convert_string (writer, to_conv);
63+ case ' d' :
64+ case ' i' :
65+ case ' u' :
66+ case ' o' :
67+ case ' x' :
68+ case ' X' :
69+ case ' b' :
70+ case ' B' :
71+ return convert_int (writer, to_conv);
72+ #ifndef LIBC_COPT_PRINTF_DISABLE_FLOAT
73+ case ' f' :
74+ case ' F' :
75+ return convert_float_decimal (writer, to_conv);
76+ case ' e' :
77+ case ' E' :
78+ return convert_float_dec_exp (writer, to_conv);
79+ case ' a' :
80+ case ' A' :
81+ return convert_float_hex_exp (writer, to_conv);
82+ case ' g' :
83+ case ' G' :
84+ return convert_float_dec_auto (writer, to_conv);
85+ #endif // LIBC_COPT_PRINTF_DISABLE_FLOAT
86+ #ifdef LIBC_INTERNAL_PRINTF_HAS_FIXED_POINT
87+ case ' r' :
88+ case ' R' :
89+ case ' k' :
90+ case ' K' :
91+ return convert_fixed (writer, to_conv);
92+ #endif // LIBC_INTERNAL_PRINTF_HAS_FIXED_POINT
93+ #ifndef LIBC_COPT_PRINTF_DISABLE_STRERROR
94+ case ' m' :
95+ return convert_strerror (writer, to_conv);
96+ #endif // LIBC_COPT_PRINTF_DISABLE_STRERROR
97+ #ifndef LIBC_COPT_PRINTF_DISABLE_WRITE_INT
98+ case ' n' :
99+ return convert_write_int (writer, to_conv);
100+ #endif // LIBC_COPT_PRINTF_DISABLE_WRITE_INT
101+ case ' p' :
102+ return convert_pointer (writer, to_conv);
103+ default :
104+ return writer->write (to_conv.raw_string );
105+ }
106+ return -1 ;
107+ }
25108
26109} // namespace printf_core
27110} // namespace LIBC_NAMESPACE_DECL
0 commit comments