NGL  6.5
The NCCA Graphics Library
time.h
Go to the documentation of this file.
1 /*
2  Formatting library for C++ - time formatting
3 
4  Copyright (c) 2012 - 2016, Victor Zverovich
5  All rights reserved.
6 
7  For the license information refer to format.h.
8  */
9 
10 #ifndef FMT_TIME_H_
11 #define FMT_TIME_H_
12 
13 #include "fmt/format.h"
14 #include <ctime>
15 
16 namespace fmt {
17 template <typename ArgFormatter>
19  const char *&format_str, const std::tm &tm) {
20  if (*format_str == ':')
21  ++format_str;
22  const char *end = format_str;
23  while (*end && *end != '}')
24  ++end;
25  if (*end != '}')
26  FMT_THROW(FormatError("missing '}' in format string"));
28  format.append(format_str, end + 1);
29  format[format.size() - 1] = '\0';
30  Buffer<char> &buffer = f.writer().buffer();
31  std::size_t start = buffer.size();
32  for (;;) {
33  std::size_t size = buffer.capacity() - start;
34  std::size_t count = std::strftime(&buffer[start], size, &format[0], &tm);
35  if (count != 0) {
36  buffer.resize(start + count);
37  break;
38  }
39  if (size >= format.size() * 256) {
40  // If the buffer is 256 times larger than the format string, assume
41  // that `strftime` gives an empty result. There doesn't seem to be a
42  // better way to distinguish the two cases:
43  // https://github.com/fmtlib/fmt/issues/367
44  break;
45  }
46  const std::size_t MIN_GROWTH = 10;
47  buffer.reserve(buffer.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));
48  }
49  format_str = end + 1;
50 }
51 }
52 
53 #endif // FMT_TIME_H_
BasicWriter< Char > & writer()
Definition: format.h:2069
void format_arg(BasicFormatter< Char, ArgFormatter > &f, const Char *&format_str, const T &value)
Definition: ostream.h:76
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3175
#define FMT_THROW(x)
Definition: format.h:172
GLuint GLuint end
Definition: glew.h:1256
GLuint start
Definition: glew.h:1256
void reserve(std::size_t capacity)
Definition: format.h:634
GLuint GLuint GLsizei count
Definition: glew.h:1256
GLuint buffer
Definition: glew.h:1683
std::size_t capacity() const
Definition: format.h:618
void resize(std::size_t new_size)
Definition: format.h:623
GLsizeiptr size
Definition: glew.h:1684
void append(const U *begin, const U *end)
Definition: format.h:657
Definition: format.cc:82
std::size_t size() const
Definition: format.h:615
GLclampf f
Definition: glew.h:3511