brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 855a441 Raw
47 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC_STDIO_STRFTIME_CORE_STRFTIME_MAIN_H10#define LLVM_LIBC_SRC_STDIO_STRFTIME_CORE_STRFTIME_MAIN_H11 12#include "hdr/types/struct_tm.h"13#include "src/__support/error_or.h"14#include "src/__support/macros/config.h"15#include "src/stdio/printf_core/writer.h"16#include "src/time/strftime_core/converter.h"17#include "src/time/strftime_core/core_structs.h"18#include "src/time/strftime_core/parser.h"19 20namespace LIBC_NAMESPACE_DECL {21namespace strftime_core {22 23template <printf_core::WriteMode write_mode>24ErrorOr<size_t> strftime_main(printf_core::Writer<write_mode> *writer,25                              const char *__restrict str, const tm *timeptr) {26  Parser parser(str);27  int result = 0;28  for (strftime_core::FormatSection cur_section = parser.get_next_section();29       !cur_section.raw_string.empty();30       cur_section = parser.get_next_section()) {31    if (cur_section.has_conv)32      result = convert(writer, cur_section, timeptr);33    else34      result = writer->write(cur_section.raw_string);35 36    if (result < 0)37      return Error(-result);38  }39 40  return writer->get_chars_written();41}42 43} // namespace strftime_core44} // namespace LIBC_NAMESPACE_DECL45 46#endif // LLVM_LIBC_SRC_STDIO_STRFTIME_CORE_STRFTIME_MAIN_H47