• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- Starting point for strftime ------------------------------*- 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_STRFTIME_CORE_STRFTIME_MAIN_H
10 #define LLVM_LIBC_SRC_STDIO_STRFTIME_CORE_STRFTIME_MAIN_H
11 
12 #include "hdr/types/struct_tm.h"
13 #include "src/__support/macros/config.h"
14 #include "src/stdio/printf_core/writer.h"
15 #include "src/time/strftime_core/converter.h"
16 #include "src/time/strftime_core/core_structs.h"
17 #include "src/time/strftime_core/parser.h"
18 
19 namespace LIBC_NAMESPACE_DECL {
20 namespace strftime_core {
21 
22 template <printf_core::WriteMode write_mode>
strftime_main(printf_core::Writer<write_mode> * writer,const char * __restrict str,const tm * timeptr)23 int strftime_main(printf_core::Writer<write_mode> *writer,
24                   const char *__restrict str, const tm *timeptr) {
25   Parser parser(str);
26   int result = 0;
27   for (strftime_core::FormatSection cur_section = parser.get_next_section();
28        !cur_section.raw_string.empty();
29        cur_section = parser.get_next_section()) {
30     if (cur_section.has_conv)
31       result = convert(writer, cur_section, timeptr);
32     else
33       result = writer->write(cur_section.raw_string);
34 
35     if (result < 0)
36       return result;
37   }
38 
39   return writer->get_chars_written();
40 }
41 
42 } // namespace strftime_core
43 } // namespace LIBC_NAMESPACE_DECL
44 
45 #endif // LLVM_LIBC_SRC_STDIO_STRFTIME_CORE_STRFTIME_MAIN_H
46