Public Member Functions | Public Attributes | List of all members
formatter< std::tm, Char > Struct Template Reference

#include <time.h>

Public Member Functions

template<typename ParseContext >
auto parse (ParseContext &ctx) -> decltype(ctx.begin())
 
template<typename FormatContext >
auto format (const std::tm &tm, FormatContext &ctx) -> decltype(ctx.out())
 

Public Attributes

basic_memory_buffer< Char > tm_format
 

Detailed Description

template<typename Char>
struct formatter< std::tm, Char >

Definition at line 116 of file time.h.

Member Function Documentation

template<typename Char >
template<typename FormatContext >
auto formatter< std::tm, Char >::format ( const std::tm &  tm,
FormatContext &  ctx 
) -> decltype(ctx.out())
inline

Definition at line 132 of file time.h.

132  {
134  std::size_t start = buf.size();
135  for (;;) {
136  std::size_t size = buf.capacity() - start;
137  std::size_t count =
138  internal::strftime(&buf[start], size, &tm_format[0], &tm);
139  if (count != 0) {
140  buf.resize(start + count);
141  break;
142  }
143  if (size >= tm_format.size() * 256) {
144  // If the buffer is 256 times larger than the format string, assume
145  // that `strftime` gives an empty result. There doesn't seem to be a
146  // better way to distinguish the two cases:
147  // https://github.com/fmtlib/fmt/issues/367
148  break;
149  }
150  const std::size_t MIN_GROWTH = 10;
151  buf.reserve(buf.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));
152  }
153  return std::copy(buf.begin(), buf.end(), ctx.out());
154  }
T * begin() FMT_NOEXCEPT
Definition: core.h:246
void resize(std::size_t new_size)
Definition: core.h:264
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:87
std::size_t strftime(char *str, std::size_t count, const char *format, const std::tm *time)
Definition: time.h:104
std::size_t size() const FMT_NOEXCEPT
Definition: core.h:250
std::size_t capacity() const FMT_NOEXCEPT
Definition: core.h:253
void reserve(std::size_t new_capacity)
Definition: core.h:273
basic_memory_buffer< Char > tm_format
Definition: time.h:156
T copy(T const &v)
T * end() FMT_NOEXCEPT
Definition: core.h:247
template<typename Char >
template<typename ParseContext >
auto formatter< std::tm, Char >::parse ( ParseContext &  ctx) -> decltype(ctx.begin())
inline

Definition at line 118 of file time.h.

118  {
119  auto it = ctx.begin();
120  if (it != ctx.end() && *it == ':')
121  ++it;
122  auto end = it;
123  while (end != ctx.end() && *end != '}')
124  ++end;
126  tm_format.append(it, end);
127  tm_format.push_back('\0');
128  return end;
129  }
void append(const U *begin, const U *end)
Definition: format.h:394
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:72
void push_back(const T &value)
Definition: core.h:278
void reserve(std::size_t new_capacity)
Definition: core.h:273
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
Definition: core.h:208
basic_memory_buffer< Char > tm_format
Definition: time.h:156

Member Data Documentation

template<typename Char >
basic_memory_buffer<Char> formatter< std::tm, Char >::tm_format

Definition at line 156 of file time.h.


The documentation for this struct was generated from the following file: