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