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 int 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 RET_IF_RESULT_NEGATIVE(writer->write(&c, 1)); 25 RET_IF_RESULT_NEGATIVE(writer->write_chars(' ', to_conv.min_width - 1)); 26 } else { 27 RET_IF_RESULT_NEGATIVE(writer->write_chars(' ', to_conv.min_width - 1)); 28 RET_IF_RESULT_NEGATIVE(writer->write(&c, 1)); 29 } 30 } else { 31 RET_IF_RESULT_NEGATIVE(writer->write(&c, 1)); 32 } 33 return 0; 34 } 35 36 } // namespace printf_core 37 } // namespace __llvm_libc 38 39 #endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CHAR_CONVERTER_H 40