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 "format.h"
14 #include <ctime>
15 
16 namespace fmt
17 {
18 template <typename ArgFormatter>
20  const char *&format_str, const std::tm &tm)
21 {
22  if (*format_str == ':')
23  ++format_str;
24  const char *end = format_str;
25  while (*end && *end != '}')
26  ++end;
27  if (*end != '}')
28  FMT_THROW(FormatError("missing '}' in format string"));
30  format.append(format_str, end + 1);
31  format[format.size() - 1] = '\0';
32  Buffer<char> &buffer = f.writer().buffer();
33  std::size_t start = buffer.size();
34  for (;;)
35  {
36  std::size_t size = buffer.capacity() - start;
37  std::size_t count = std::strftime(&buffer[start], size, &format[0], &tm);
38  if (count != 0)
39  {
40  buffer.resize(start + count);
41  break;
42  }
43  if (size >= format.size() * 256)
44  {
45  // If the buffer is 256 times larger than the format string, assume
46  // that `strftime` gives an empty result. There doesn't seem to be a
47  // better way to distinguish the two cases:
48  // https://github.com/fmtlib/fmt/issues/367
49  break;
50  }
51  const std::size_t MIN_GROWTH = 10;
52  buffer.reserve(buffer.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));
53  }
54  format_str = end + 1;
55 }
56 }
57 
58 #endif // FMT_TIME_H_
int * count
ROSCPP_DECL void start()
void resize(std::size_t new_size)
Definition: format.h:706
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3686
std::size_t capacity() const
Definition: format.h:698
BasicWriter< Char > & writer()
Definition: format.h:2440
#define FMT_THROW(x)
Definition: format.h:172
void append(const U *begin, const U *end)
Definition: format.h:749
std::size_t size() const
Definition: format.h:692
void reserve(std::size_t capacity)
Definition: format.h:718
Definition: format.cc:81


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:08