[Workflow] Roll back some settings since they caused more issues
[llvm-project.git] / libc / src / stdio / printf_core / char_converter.h
blobffd2422c822f7e6f681f160b402b026fa9557f98
1 //===-- String Converter for printf -----------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CHAR_CONVERTER_H
10 #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CHAR_CONVERTER_H
12 #include "src/__support/CPP/string_view.h"
13 #include "src/__support/common.h"
14 #include "src/stdio/printf_core/converter_utils.h"
15 #include "src/stdio/printf_core/core_structs.h"
16 #include "src/stdio/printf_core/writer.h"
18 namespace __llvm_libc {
19 namespace printf_core {
21 LIBC_INLINE int convert_char(Writer *writer, const FormatSection &to_conv) {
22 char c = static_cast<char>(to_conv.conv_val_raw);
24 constexpr int string_len = 1;
26 size_t padding_spaces =
27 to_conv.min_width > string_len ? to_conv.min_width - string_len : 0;
29 // If the padding is on the left side, write the spaces first.
30 if (padding_spaces > 0 &&
31 (to_conv.flags & FormatFlags::LEFT_JUSTIFIED) == 0) {
32 RET_IF_RESULT_NEGATIVE(writer->write(' ', padding_spaces));
35 RET_IF_RESULT_NEGATIVE(writer->write(c));
37 // If the padding is on the right side, write the spaces last.
38 if (padding_spaces > 0 &&
39 (to_conv.flags & FormatFlags::LEFT_JUSTIFIED) != 0) {
40 RET_IF_RESULT_NEGATIVE(writer->write(' ', padding_spaces));
43 return WRITE_OK;
46 } // namespace printf_core
47 } // namespace __llvm_libc
49 #endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CHAR_CONVERTER_H