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/__support/macros/config.h"
12 #include "src/stdio/printf_core/core_structs.h"
13 #include "src/stdio/printf_core/printf_config.h"
14 #include "src/stdio/printf_core/strerror_converter.h"
15 #include "src/stdio/printf_core/writer.h"
17 // This option allows for replacing all of the conversion functions with custom
18 // replacements. This allows conversions to be replaced at compile time.
19 #ifndef LIBC_COPT_PRINTF_CONV_ATLAS
20 #include "src/stdio/printf_core/converter_atlas.h"
22 #include LIBC_COPT_PRINTF_CONV_ATLAS
27 namespace LIBC_NAMESPACE_DECL
{
28 namespace printf_core
{
30 int convert(Writer
*writer
, const FormatSection
&to_conv
) {
31 if (!to_conv
.has_conv
)
32 return writer
->write(to_conv
.raw_string
);
34 #if !defined(LIBC_COPT_PRINTF_DISABLE_FLOAT) && \
35 defined(LIBC_COPT_PRINTF_HEX_LONG_DOUBLE)
36 if (to_conv
.length_modifier
== LengthModifier::L
) {
37 switch (to_conv
.conv_name
) {
44 return convert_float_hex_exp(writer
, to_conv
);
49 #endif // LIBC_COPT_PRINTF_DISABLE_FLOAT
51 switch (to_conv
.conv_name
) {
53 return writer
->write("%");
55 return convert_char(writer
, to_conv
);
57 return convert_string(writer
, to_conv
);
66 return convert_int(writer
, to_conv
);
67 #ifndef LIBC_COPT_PRINTF_DISABLE_FLOAT
70 return convert_float_decimal(writer
, to_conv
);
73 return convert_float_dec_exp(writer
, to_conv
);
76 return convert_float_hex_exp(writer
, to_conv
);
79 return convert_float_dec_auto(writer
, to_conv
);
80 #endif // LIBC_COPT_PRINTF_DISABLE_FLOAT
81 #ifdef LIBC_INTERNAL_PRINTF_HAS_FIXED_POINT
86 return convert_fixed(writer
, to_conv
);
87 #endif // LIBC_INTERNAL_PRINTF_HAS_FIXED_POINT
88 #ifndef LIBC_COPT_PRINTF_DISABLE_STRERROR
90 return convert_strerror(writer
, to_conv
);
91 #endif // LIBC_COPT_PRINTF_DISABLE_STRERROR
92 #ifndef LIBC_COPT_PRINTF_DISABLE_WRITE_INT
94 return convert_write_int(writer
, to_conv
);
95 #endif // LIBC_COPT_PRINTF_DISABLE_WRITE_INT
97 return convert_pointer(writer
, to_conv
);
99 return writer
->write(to_conv
.raw_string
);
104 } // namespace printf_core
105 } // namespace LIBC_NAMESPACE_DECL