1 //===-- Format specifier converter implmentation for printf -----*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/stdio/printf_core/converter.h"
11 #include "src/stdio/printf_core/core_structs.h"
12 #include "src/stdio/printf_core/writer.h"
14 // This option allows for replacing all of the conversion functions with custom
15 // replacements. This allows conversions to be replaced at compile time.
16 #ifndef LIBC_COPT_PRINTF_CONV_ATLAS
17 #include "src/stdio/printf_core/converter_atlas.h"
19 #include LIBC_COPT_PRINTF_CONV_ATLAS
24 namespace LIBC_NAMESPACE
{
25 namespace printf_core
{
27 int convert(Writer
*writer
, const FormatSection
&to_conv
) {
28 if (!to_conv
.has_conv
)
29 return writer
->write(to_conv
.raw_string
);
31 #if !defined(LIBC_COPT_PRINTF_DISABLE_FLOAT) && \
32 defined(LIBC_COPT_PRINTF_HEX_LONG_DOUBLE)
33 if (to_conv
.length_modifier
== LengthModifier::L
) {
34 switch (to_conv
.conv_name
) {
41 return convert_float_hex_exp(writer
, to_conv
);
46 #endif // LIBC_COPT_PRINTF_DISABLE_FLOAT
48 switch (to_conv
.conv_name
) {
50 return writer
->write("%");
52 return convert_char(writer
, to_conv
);
54 return convert_string(writer
, to_conv
);
61 return convert_int(writer
, to_conv
);
62 #ifndef LIBC_COPT_PRINTF_DISABLE_FLOAT
65 return convert_float_decimal(writer
, to_conv
);
68 return convert_float_dec_exp(writer
, to_conv
);
71 return convert_float_hex_exp(writer
, to_conv
);
74 return convert_float_dec_auto(writer
, to_conv
);
75 #endif // LIBC_COPT_PRINTF_DISABLE_FLOAT
76 #ifndef LIBC_COPT_PRINTF_DISABLE_WRITE_INT
78 return convert_write_int(writer
, to_conv
);
79 #endif // LIBC_COPT_PRINTF_DISABLE_WRITE_INT
81 return convert_pointer(writer
, to_conv
);
83 return writer
->write(to_conv
.raw_string
);
88 } // namespace printf_core
89 } // namespace LIBC_NAMESPACE