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 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CHAR_CONVERTER_H
10 #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CHAR_CONVERTER_H
11 
12 #include "src/stdio/printf_core/core_structs.h"
13 #include "src/stdio/printf_core/writer.h"
14 
15 namespace __llvm_libc {
16 namespace printf_core {
17 
18 void inline convert_char(Writer *writer, const FormatSection &to_conv) {
19   char c = to_conv.conv_val_raw;
20 
21   if (to_conv.min_width > 1) {
22     if ((to_conv.flags & FormatFlags::LEFT_JUSTIFIED) ==
23         FormatFlags::LEFT_JUSTIFIED) {
24       writer->write(&c, 1);
25       writer->write_chars(' ', to_conv.min_width - 1);
26     } else {
27       writer->write_chars(' ', to_conv.min_width - 1);
28       writer->write(&c, 1);
29     }
30   } else {
31     writer->write(&c, 1);
32   }
33 }
34 
35 } // namespace printf_core
36 } // namespace __llvm_libc
37 
38 #endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CHAR_CONVERTER_H
39