summaryrefslogtreecommitdiff
path: root/libc/src/time/strftime_core/core_structs.h
blob: 9da57aa11e6c9d8a5ea02b084a78d9498fa81d96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//===-- Core Structures for strftime ----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_STDIO_STRFTIME_CORE_CORE_STRUCTS_H
#define LLVM_LIBC_SRC_STDIO_STRFTIME_CORE_CORE_STRUCTS_H

#include "hdr/stdint_proxy.h"
#include "hdr/types/struct_tm.h"
#include "src/__support/CPP/string_view.h"

namespace LIBC_NAMESPACE_DECL {
namespace strftime_core {

enum class ConvModifier { none, E, O };

// These flags intentionally have different values from the ones used by printf.
// They have different meanings.
enum FormatFlags : uint8_t {
  FORCE_SIGN = 0x01,     // +
  LEADING_ZEROES = 0x02, // 0
  // TODO: look into the glibc extension flags ('_', '-', '^', and '#')
};

struct FormatSection {
  bool has_conv = false;
  cpp::string_view raw_string = {};

  FormatFlags flags = FormatFlags(0);
  ConvModifier modifier = ConvModifier::none;
  char conv_name = '\0';
  int min_width = 0;
};

// TODO: Move this to a better spot
#define RET_IF_RESULT_NEGATIVE(func)                                           \
  {                                                                            \
    int result = (func);                                                       \
    if (result < 0)                                                            \
      return result;                                                           \
  }

constexpr int WRITE_OK = 0;

} // namespace strftime_core
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_STDIO_STRFTIME_CORE_CORE_STRUCTS_H