commit 0e2c89a: [Minor] Update fmt to 8.1.1
Vsevolod Stakhov
vsevolod at rspamd.com
Thu Apr 28 19:21:04 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-04-28 20:18:57 +0100
URL: https://github.com/rspamd/rspamd/commit/0e2c89a34ad89cf170ff4dc9c058abfecb938ab9 (HEAD -> master)
[Minor] Update fmt to 8.1.1
Issue: #4162
---
contrib/DEPENDENCY_INFO.md | 12 +-
contrib/fmt/include/fmt/chrono.h | 1181 ++++++++++++++++++++++++++++------
contrib/fmt/include/fmt/color.h | 35 +-
contrib/fmt/include/fmt/compile.h | 25 +-
contrib/fmt/include/fmt/core.h | 746 +++++++++++++--------
contrib/fmt/include/fmt/format-inl.h | 549 ++++++++--------
contrib/fmt/include/fmt/format.h | 902 +++++++++++++++++---------
contrib/fmt/include/fmt/os.h | 48 +-
contrib/fmt/include/fmt/ostream.h | 108 +---
contrib/fmt/include/fmt/printf.h | 19 +-
contrib/fmt/include/fmt/ranges.h | 547 ++++++++++++----
contrib/fmt/src/format.cc | 46 ++
contrib/fmt/src/os.cc | 17 +-
13 files changed, 2941 insertions(+), 1294 deletions(-)
diff --git a/contrib/DEPENDENCY_INFO.md b/contrib/DEPENDENCY_INFO.md
index f539d3238..fd01fa5ae 100644
--- a/contrib/DEPENDENCY_INFO.md
+++ b/contrib/DEPENDENCY_INFO.md
@@ -1,7 +1,7 @@
# Rspamd Dependency Info
| Name | Version | License | Patched | Notes |
-| --- | --- | --- | --- | --- |
+| --- |---------| --- | --- | --- |
| aho-corasick | ? | LGPL-3.0 | YES | lowercase support |
| cdb | 1.1.0 | Public Domain / CC0 | NO | |
| hiredis | 0.13.3 | BSD-3-Clause | YES | many changes |
@@ -10,7 +10,7 @@
| libottery | ? | Public Domain / CC0 | YES | many changes |
| librdns | ? | BSD-2-Clause | YES | |
| libucl | ? | BSD-2-Clause | YES | |
-| replxx | 6d93360 | BSD-2-Clause | YES | libicu usage |
+| replxx | 6d93360 | BSD-2-Clause | YES | libicu usage |
| lua-argparse | 0.7.1 | MIT | NO | |
| lua-bit | 1.0.2 | MIT | YES | build fixes |
| lua-fun | ? | MIT | YES | rspamd text |
@@ -19,20 +19,20 @@
| lua-lupa | ? | MIT | NO | |
| lua-tableshape | ae67256 | MIT | NO | |
| mumhash | ? | MIT | NO | |
-| ngx-http-parser | 2.2.0 | MIT | YES | spamc support |
-| Mozilla-PublicSuffix | ? | MIT | NO | |
+| ngx-http-parser | 2.2.0 | MIT | YES | spamc support |
+| Mozilla-PublicSuffix | ? | MIT | NO | |
| snowball | ? | BSD-3-Clause | NO | |
| t1ha | ? | Zlib | NO | |
| uthash | 1.9.8 | BSD | YES | |
| xxhash | 0.8.1 | BSD | NO | |
| zstd | 1.4.5 | BSD | NO | |
| google-ced | 37529e6 | Apache 2 | YES | build fixes |
-| kann | ? | MIT | YES | blas/lapack changes|
+| kann | ? | MIT | YES | blas/lapack changes|
| fpconv | ? | Boost | YES | many changes |
| fastutf8 | ? | MIT | YES | many changes |
| expected | v1.0 | Public Domain / CC0 | NO | |
| robin-hood | 3.9.1 | MIT | NO | |
| frozen | 1.0.1 | Apache 2 | NO | |
-| fmt | 7.1.3 | MIT | NO | |
+| fmt | 8.1.1 | MIT | NO | |
| doctest | 2.4.6 | MIT | NO | |
| function2 | 4.1.0 | Boost | NO | |
diff --git a/contrib/fmt/include/fmt/chrono.h b/contrib/fmt/include/fmt/chrono.h
index c024fd710..682efd8d2 100644
--- a/contrib/fmt/include/fmt/chrono.h
+++ b/contrib/fmt/include/fmt/chrono.h
@@ -11,13 +11,29 @@
#include <algorithm>
#include <chrono>
#include <ctime>
+#include <iterator>
#include <locale>
-#include <sstream>
+#include <ostream>
+#include <type_traits>
#include "format.h"
FMT_BEGIN_NAMESPACE
+// Enable tzset.
+#ifndef FMT_USE_TZSET
+// UWP doesn't provide _tzset.
+# if FMT_HAS_INCLUDE("winapifamily.h")
+# include <winapifamily.h>
+# endif
+# if defined(_WIN32) && (!defined(WINAPI_FAMILY) || \
+ (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
+# define FMT_USE_TZSET 1
+# else
+# define FMT_USE_TZSET 0
+# endif
+#endif
+
// Enable safe chrono durations, unless explicitly disabled.
#ifndef FMT_SAFE_DURATION_CAST
# define FMT_SAFE_DURATION_CAST 1
@@ -44,7 +60,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
static_assert(T::is_integer, "To must be integral");
// A and B are both signed, or both unsigned.
- if (F::digits <= T::digits) {
+ if (detail::const_check(F::digits <= T::digits)) {
// From fits in To without any problem.
} else {
// From does not always fit in To, resort to a dynamic check.
@@ -79,14 +95,15 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
return {};
}
// From is positive. Can it always fit in To?
- if (F::digits > T::digits &&
+ if (detail::const_check(F::digits > T::digits) &&
from > static_cast<From>(detail::max_value<To>())) {
ec = 1;
return {};
}
}
- if (!F::is_signed && T::is_signed && F::digits >= T::digits &&
+ if (detail::const_check(!F::is_signed && T::is_signed &&
+ F::digits >= T::digits) &&
from > static_cast<From>(detail::max_value<To>())) {
ec = 1;
return {};
@@ -243,7 +260,7 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
}
// multiply with Factor::num without overflow or underflow
- if (Factor::num != 1) {
+ if (detail::const_check(Factor::num != 1)) {
constexpr auto max1 = detail::max_value<IntermediateRep>() /
static_cast<IntermediateRep>(Factor::num);
if (count > max1) {
@@ -260,7 +277,7 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
}
// this can't go wrong, right? den>0 is checked earlier.
- if (Factor::den != 1) {
+ if (detail::const_check(Factor::den != 1)) {
using common_t = typename std::common_type<IntermediateRep, intmax_t>::type;
count /= static_cast<common_t>(Factor::den);
}
@@ -288,74 +305,139 @@ inline null<> localtime_s(...) { return null<>(); }
inline null<> gmtime_r(...) { return null<>(); }
inline null<> gmtime_s(...) { return null<>(); }
-inline auto do_write(const std::tm& time, const std::locale& loc, char format,
- char modifier) -> std::string {
- auto&& os = std::ostringstream();
- os.imbue(loc);
- using iterator = std::ostreambuf_iterator<char>;
- const auto& facet = std::use_facet<std::time_put<char, iterator>>(loc);
- auto end = facet.put(os, os, ' ', &time, format, modifier);
- if (end.failed()) FMT_THROW(format_error("failed to format time"));
- auto str = os.str();
- if (!detail::is_utf8() || loc == std::locale::classic()) return str;
- // char16_t and char32_t codecvts are broken in MSVC (linkage errors) and
- // gcc-4.
-#if FMT_MSC_VER != 0 || \
- (defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI))
- // The _GLIBCXX_USE_DUAL_ABI macro is always defined in libstdc++ from gcc-5
- // and newer.
- using code_unit = wchar_t;
+inline const std::locale& get_classic_locale() {
+ static const auto& locale = std::locale::classic();
+ return locale;
+}
+
+template <typename CodeUnit> struct codecvt_result {
+ static constexpr const size_t max_size = 32;
+ CodeUnit buf[max_size];
+ CodeUnit* end;
+};
+template <typename CodeUnit>
+constexpr const size_t codecvt_result<CodeUnit>::max_size;
+
+template <typename CodeUnit>
+void write_codecvt(codecvt_result<CodeUnit>& out, string_view in_buf,
+ const std::locale& loc) {
+ using codecvt = std::codecvt<CodeUnit, char, std::mbstate_t>;
+#if FMT_CLANG_VERSION
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated"
+ auto& f = std::use_facet<codecvt>(loc);
+# pragma clang diagnostic pop
#else
- using code_unit = char32_t;
+ auto& f = std::use_facet<codecvt>(loc);
#endif
- auto& f = std::use_facet<std::codecvt<code_unit, char, std::mbstate_t>>(loc);
auto mb = std::mbstate_t();
const char* from_next = nullptr;
- code_unit* to_next = nullptr;
- constexpr size_t buf_size = 32;
- code_unit buf[buf_size] = {};
- auto result = f.in(mb, str.data(), str.data() + str.size(), from_next, buf,
- buf + buf_size, to_next);
+ auto result = f.in(mb, in_buf.begin(), in_buf.end(), from_next,
+ std::begin(out.buf), std::end(out.buf), out.end);
if (result != std::codecvt_base::ok)
FMT_THROW(format_error("failed to format time"));
- str.clear();
- for (code_unit* p = buf; p != to_next; ++p) {
- uint32_t c = static_cast<uint32_t>(*p);
- if (sizeof(code_unit) == 2 && c >= 0xd800 && c <= 0xdfff) {
- // surrogate pair
- ++p;
- if (p == to_next || (c & 0xfc00) != 0xd800 || (*p & 0xfc00) != 0xdc00) {
+}
+
+template <typename OutputIt>
+auto write_encoded_tm_str(OutputIt out, string_view in, const std::locale& loc)
+ -> OutputIt {
+ if (detail::is_utf8() && loc != get_classic_locale()) {
+ // char16_t and char32_t codecvts are broken in MSVC (linkage errors) and
+ // gcc-4.
+#if FMT_MSC_VER != 0 || \
+ (defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI))
+ // The _GLIBCXX_USE_DUAL_ABI macro is always defined in libstdc++ from gcc-5
+ // and newer.
+ using code_unit = wchar_t;
+#else
+ using code_unit = char32_t;
+#endif
+
+ using unit_t = codecvt_result<code_unit>;
+ unit_t unit;
+ write_codecvt(unit, in, loc);
+ // In UTF-8 is used one to four one-byte code units.
+ auto&& buf = basic_memory_buffer<char, unit_t::max_size * 4>();
+ for (code_unit* p = unit.buf; p != unit.end; ++p) {
+ uint32_t c = static_cast<uint32_t>(*p);
+ if (sizeof(code_unit) == 2 && c >= 0xd800 && c <= 0xdfff) {
+ // surrogate pair
+ ++p;
+ if (p == unit.end || (c & 0xfc00) != 0xd800 ||
+ (*p & 0xfc00) != 0xdc00) {
+ FMT_THROW(format_error("failed to format time"));
+ }
+ c = (c << 10) + static_cast<uint32_t>(*p) - 0x35fdc00;
+ }
+ if (c < 0x80) {
+ buf.push_back(static_cast<char>(c));
+ } else if (c < 0x800) {
+ buf.push_back(static_cast<char>(0xc0 | (c >> 6)));
+ buf.push_back(static_cast<char>(0x80 | (c & 0x3f)));
+ } else if ((c >= 0x800 && c <= 0xd7ff) || (c >= 0xe000 && c <= 0xffff)) {
+ buf.push_back(static_cast<char>(0xe0 | (c >> 12)));
+ buf.push_back(static_cast<char>(0x80 | ((c & 0xfff) >> 6)));
+ buf.push_back(static_cast<char>(0x80 | (c & 0x3f)));
+ } else if (c >= 0x10000 && c <= 0x10ffff) {
+ buf.push_back(static_cast<char>(0xf0 | (c >> 18)));
+ buf.push_back(static_cast<char>(0x80 | ((c & 0x3ffff) >> 12)));
+ buf.push_back(static_cast<char>(0x80 | ((c & 0xfff) >> 6)));
+ buf.push_back(static_cast<char>(0x80 | (c & 0x3f)));
+ } else {
FMT_THROW(format_error("failed to format time"));
}
- c = (c << 10) + static_cast<uint32_t>(*p) - 0x35fdc00;
- }
- if (c < 0x80) {
- str.push_back(static_cast<char>(c));
- } else if (c < 0x800) {
- str.push_back(static_cast<char>(0xc0 | (c >> 6)));
- str.push_back(static_cast<char>(0x80 | (c & 0x3f)));
- } else if ((c >= 0x800 && c <= 0xd7ff) || (c >= 0xe000 && c <= 0xffff)) {
- str.push_back(static_cast<char>(0xe0 | (c >> 12)));
- str.push_back(static_cast<char>(0x80 | ((c & 0xfff) >> 6)));
- str.push_back(static_cast<char>(0x80 | (c & 0x3f)));
- } else if (c >= 0x10000 && c <= 0x10ffff) {
- str.push_back(static_cast<char>(0xf0 | (c >> 18)));
- str.push_back(static_cast<char>(0x80 | ((c & 0x3ffff) >> 12)));
- str.push_back(static_cast<char>(0x80 | ((c & 0xfff) >> 6)));
- str.push_back(static_cast<char>(0x80 | (c & 0x3f)));
- } else {
- FMT_THROW(format_error("failed to format time"));
}
+ return copy_str<char>(buf.data(), buf.data() + buf.size(), out);
}
- return str;
+ return copy_str<char>(in.data(), in.data() + in.size(), out);
}
-template <typename OutputIt>
+template <typename Char, typename OutputIt,
+ FMT_ENABLE_IF(!std::is_same<Char, char>::value)>
+auto write_tm_str(OutputIt out, string_view sv, const std::locale& loc)
+ -> OutputIt {
+ codecvt_result<Char> unit;
+ write_codecvt(unit, sv, loc);
+ return copy_str<Char>(unit.buf, unit.end, out);
+}
+
+template <typename Char, typename OutputIt,
+ FMT_ENABLE_IF(std::is_same<Char, char>::value)>
+auto write_tm_str(OutputIt out, string_view sv, const std::locale& loc)
+ -> OutputIt {
+ return write_encoded_tm_str(out, sv, loc);
+}
+
+template <typename Char>
+inline void do_write(buffer<Char>& buf, const std::tm& time,
+ const std::locale& loc, char format, char modifier) {
+ auto&& format_buf = formatbuf<std::basic_streambuf<Char>>(buf);
+ auto&& os = std::basic_ostream<Char>(&format_buf);
+ os.imbue(loc);
+ using iterator = std::ostreambuf_iterator<Char>;
+ const auto& facet = std::use_facet<std::time_put<Char, iterator>>(loc);
+ auto end = facet.put(os, os, Char(' '), &time, format, modifier);
+ if (end.failed()) FMT_THROW(format_error("failed to format time"));
+}
+
+template <typename Char, typename OutputIt,
+ FMT_ENABLE_IF(!std::is_same<Char, char>::value)>
+auto write(OutputIt out, const std::tm& time, const std::locale& loc,
+ char format, char modifier = 0) -> OutputIt {
+ auto&& buf = get_buffer<Char>(out);
+ do_write<Char>(buf, time, loc, format, modifier);
+ return buf.out();
+}
+
+template <typename Char, typename OutputIt,
+ FMT_ENABLE_IF(std::is_same<Char, char>::value)>
auto write(OutputIt out, const std::tm& time, const std::locale& loc,
char format, char modifier = 0) -> OutputIt {
- auto str = do_write(time, loc, format, modifier);
- return std::copy(str.begin(), str.end(), out);
+ auto&& buf = basic_memory_buffer<Char>();
+ do_write<char>(buf, time, loc, format, modifier);
+ return write_encoded_tm_str(out, string_view(buf.data(), buf.size()), loc);
}
+
} // namespace detail
FMT_MODULE_EXPORT_BEGIN
@@ -453,102 +535,39 @@ inline std::tm gmtime(
FMT_BEGIN_DETAIL_NAMESPACE
-inline size_t strftime(char* str, size_t count, const char* format,
- const std::tm* time) {
- // Assign to a pointer to suppress GCCs -Wformat-nonliteral
- // First assign the nullptr to suppress -Wsuggest-attribute=format
- std::size_t (*strftime)(char*, std::size_t, const char*, const std::tm*) =
- nullptr;
- strftime = std::strftime;
- return strftime(str, count, format, time);
-}
-
-inline size_t strftime(wchar_t* str, size_t count, const wchar_t* format,
- const std::tm* time) {
- // See above
- std::size_t (*wcsftime)(wchar_t*, std::size_t, const wchar_t*,
- const std::tm*) = nullptr;
- wcsftime = std::wcsftime;
- return wcsftime(str, count, format, time);
-}
-
-FMT_END_DETAIL_NAMESPACE
-
-template <typename Char, typename Duration>
-struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
- Char> : formatter<std::tm, Char> {
- FMT_CONSTEXPR formatter() {
- this->specs = {default_specs, sizeof(default_specs) / sizeof(Char)};
- }
-
- template <typename ParseContext>
- FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
- auto it = ctx.begin();
- if (it != ctx.end() && *it == ':') ++it;
- auto end = it;
- while (end != ctx.end() && *end != '}') ++end;
- if (end != it) this->specs = {it, detail::to_unsigned(end - it)};
- return end;
- }
-
- template <typename FormatContext>
- auto format(std::chrono::time_point<std::chrono::system_clock> val,
- FormatContext& ctx) -> decltype(ctx.out()) {
- std::tm time = localtime(val);
- return formatter<std::tm, Char>::format(time, ctx);
- }
-
- static constexpr Char default_specs[] = {'%', 'Y', '-', '%', 'm', '-',
- '%', 'd', ' ', '%', 'H', ':',
- '%', 'M', ':', '%', 'S'};
-};
-
-template <typename Char, typename Duration>
-constexpr Char
- formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
- Char>::default_specs[];
-
-template <typename Char> struct formatter<std::tm, Char> {
- template <typename ParseContext>
- FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
- auto it = ctx.begin();
- if (it != ctx.end() && *it == ':') ++it;
- auto end = it;
- while (end != ctx.end() && *end != '}') ++end;
- specs = {it, detail::to_unsigned(end - it)};
- return end;
- }
-
- template <typename FormatContext>
- auto format(const std::tm& tm, FormatContext& ctx) const
- -> decltype(ctx.out()) {
- basic_memory_buffer<Char> tm_format;
- tm_format.append(specs.begin(), specs.end());
- // By appending an extra space we can distinguish an empty result that
- // indicates insufficient buffer size from a guaranteed non-empty result
- // https://github.com/fmtlib/fmt/issues/2238
- tm_format.push_back(' ');
- tm_format.push_back('\0');
- basic_memory_buffer<Char> buf;
- size_t start = buf.size();
- for (;;) {
- size_t size = buf.capacity() - start;
- size_t count = detail::strftime(&buf[start], size, &tm_format[0], &tm);
- if (count != 0) {
- buf.resize(start + count);
- break;
- }
- const size_t MIN_GROWTH = 10;
- buf.reserve(buf.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));
- }
- // Remove the extra space.
- return std::copy(buf.begin(), buf.end() - 1, ctx.out());
+// Writes two-digit numbers a, b and c separated by sep to buf.
+// The method by Pavel Novikov based on
+// https://johnnylee-sde.github.io/Fast-unsigned-integer-to-time-string/.
+inline void write_digit2_separated(char* buf, unsigned a, unsigned b,
+ unsigned c, char sep) {
+ unsigned long long digits =
+ a | (b << 24) | (static_cast<unsigned long long>(c) << 48);
+ // Convert each value to BCD.
+ // We have x = a * 10 + b and we want to convert it to BCD y = a * 16 + b.
+ // The difference is
+ // y - x = a * 6
+ // a can be found from x:
+ // a = floor(x / 10)
+ // then
+ // y = x + a * 6 = x + floor(x / 10) * 6
+ // floor(x / 10) is (x * 205) >> 11 (needs 16 bits).
+ digits += (((digits * 205) >> 11) & 0x000f00000f00000f) * 6;
+ // Put low nibbles to high bytes and high nibbles to low bytes.
+ digits = ((digits & 0x00f00000f00000f0) >> 4) |
+ ((digits & 0x000f00000f00000f) << 8);
+ auto usep = static_cast<unsigned long long>(sep);
+ // Add ASCII '0' to each digit byte and insert separators.
+ digits |= 0x3030003030003030 | (usep << 16) | (usep << 40);
+
+ constexpr const size_t len = 8;
+ if (const_check(is_big_endian())) {
+ char tmp[len];
+ memcpy(tmp, &digits, len);
+ std::reverse_copy(tmp, tmp + len, buf);
+ } else {
+ memcpy(buf, &digits, len);
}
-
- basic_string_view<Char> specs;
-};
-
-FMT_BEGIN_DETAIL_NAMESPACE
+}
template <typename Period> FMT_CONSTEXPR inline const char* get_units() {
if (std::is_same<Period, std::atto>::value) return "as";
@@ -610,6 +629,22 @@ FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin,
handler.on_text(tab, tab + 1);
break;
}
+ // Year:
+ case 'Y':
+ handler.on_year(numeric_system::standard);
+ break;
+ case 'y':
+ handler.on_short_year(numeric_system::standard);
+ break;
+ case 'C':
+ handler.on_century(numeric_system::standard);
+ break;
+ case 'G':
+ handler.on_iso_week_based_year();
+ break;
+ case 'g':
+ handler.on_iso_week_based_short_year();
+ break;
// Day of the week:
case 'a':
handler.on_abbr_weekday();
@@ -625,11 +660,34 @@ FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin,
break;
// Month:
case 'b':
+ case 'h':
handler.on_abbr_month();
break;
case 'B':
handler.on_full_month();
break;
+ case 'm':
+ handler.on_dec_month(numeric_system::standard);
+ break;
+ // Day of the year/month:
+ case 'U':
+ handler.on_dec0_week_of_year(numeric_system::standard);
+ break;
+ case 'W':
+ handler.on_dec1_week_of_year(numeric_system::standard);
+ break;
+ case 'V':
+ handler.on_iso_week_of_year(numeric_system::standard);
+ break;
+ case 'j':
+ handler.on_day_of_year();
+ break;
+ case 'd':
+ handler.on_day_of_month(numeric_system::standard);
+ break;
+ case 'e':
+ handler.on_day_of_month_space(numeric_system::standard);
+ break;
// Hour, minute, second:
case 'H':
handler.on_24_hour(numeric_system::standard);
@@ -688,6 +746,15 @@ FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin,
if (ptr == end) FMT_THROW(format_error("invalid format"));
c = *ptr++;
switch (c) {
+ case 'Y':
+ handler.on_year(numeric_system::alternative);
+ break;
+ case 'y':
+ handler.on_offset_year();
+ break;
+ case 'C':
+ handler.on_century(numeric_system::alternative);
+ break;
case 'c':
handler.on_datetime(numeric_system::alternative);
break;
@@ -706,6 +773,27 @@ FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin,
if (ptr == end) FMT_THROW(format_error("invalid format"));
c = *ptr++;
switch (c) {
+ case 'y':
+ handler.on_short_year(numeric_system::alternative);
+ break;
+ case 'm':
+ handler.on_dec_month(numeric_system::alternative);
+ break;
+ case 'U':
+ handler.on_dec0_week_of_year(numeric_system::alternative);
+ break;
+ case 'W':
+ handler.on_dec1_week_of_year(numeric_system::alternative);
+ break;
+ case 'V':
+ handler.on_iso_week_of_year(numeric_system::alternative);
+ break;
+ case 'd':
+ handler.on_day_of_month(numeric_system::alternative);
+ break;
+ case 'e':
+ handler.on_day_of_month_space(numeric_system::alternative);
+ break;
case 'w':
handler.on_dec0_weekday(numeric_system::alternative);
break;
@@ -741,12 +829,25 @@ template <typename Derived> struct null_chrono_spec_handler {
FMT_CONSTEXPR void unsupported() {
static_cast<Derived*>(this)->unsupported();
}
+ FMT_CONSTEXPR void on_year(numeric_system) { unsupported(); }
+ FMT_CONSTEXPR void on_short_year(numeric_system) { unsupported(); }
+ FMT_CONSTEXPR void on_offset_year() { unsupported(); }
+ FMT_CONSTEXPR void on_century(numeric_system) { unsupported(); }
+ FMT_CONSTEXPR void on_iso_week_based_year() { unsupported(); }
+ FMT_CONSTEXPR void on_iso_week_based_short_year() { unsupported(); }
FMT_CONSTEXPR void on_abbr_weekday() { unsupported(); }
FMT_CONSTEXPR void on_full_weekday() { unsupported(); }
FMT_CONSTEXPR void on_dec0_weekday(numeric_system) { unsupported(); }
FMT_CONSTEXPR void on_dec1_weekday(numeric_system) { unsupported(); }
FMT_CONSTEXPR void on_abbr_month() { unsupported(); }
FMT_CONSTEXPR void on_full_month() { unsupported(); }
+ FMT_CONSTEXPR void on_dec_month(numeric_system) { unsupported(); }
+ FMT_CONSTEXPR void on_dec0_week_of_year(numeric_system) { unsupported(); }
+ FMT_CONSTEXPR void on_dec1_week_of_year(numeric_system) { unsupported(); }
+ FMT_CONSTEXPR void on_iso_week_of_year(numeric_system) { unsupported(); }
+ FMT_CONSTEXPR void on_day_of_year() { unsupported(); }
+ FMT_CONSTEXPR void on_day_of_month(numeric_system) { unsupported(); }
+ FMT_CONSTEXPR void on_day_of_month_space(numeric_system) { unsupported(); }
FMT_CONSTEXPR void on_24_hour(numeric_system) { unsupported(); }
FMT_CONSTEXPR void on_12_hour(numeric_system) { unsupported(); }
FMT_CONSTEXPR void on_minute(numeric_system) { unsupported(); }
@@ -766,6 +867,509 @@ template <typename Derived> struct null_chrono_spec_handler {
FMT_CONSTEXPR void on_tz_name() { unsupported(); }
};
+struct tm_format_checker : null_chrono_spec_handler<tm_format_checker> {
+ FMT_NORETURN void unsupported() { FMT_THROW(format_error("no format")); }
+
+ template <typename Char>
+ FMT_CONSTEXPR void on_text(const Char*, const Char*) {}
+ FMT_CONSTEXPR void on_year(numeric_system) {}
+ FMT_CONSTEXPR void on_short_year(numeric_system) {}
+ FMT_CONSTEXPR void on_offset_year() {}
+ FMT_CONSTEXPR void on_century(numeric_system) {}
+ FMT_CONSTEXPR void on_iso_week_based_year() {}
+ FMT_CONSTEXPR void on_iso_week_based_short_year() {}
+ FMT_CONSTEXPR void on_abbr_weekday() {}
+ FMT_CONSTEXPR void on_full_weekday() {}
+ FMT_CONSTEXPR void on_dec0_weekday(numeric_system) {}
+ FMT_CONSTEXPR void on_dec1_weekday(numeric_system) {}
+ FMT_CONSTEXPR void on_abbr_month() {}
+ FMT_CONSTEXPR void on_full_month() {}
+ FMT_CONSTEXPR void on_dec_month(numeric_system) {}
+ FMT_CONSTEXPR void on_dec0_week_of_year(numeric_system) {}
+ FMT_CONSTEXPR void on_dec1_week_of_year(numeric_system) {}
+ FMT_CONSTEXPR void on_iso_week_of_year(numeric_system) {}
+ FMT_CONSTEXPR void on_day_of_year() {}
+ FMT_CONSTEXPR void on_day_of_month(numeric_system) {}
+ FMT_CONSTEXPR void on_day_of_month_space(numeric_system) {}
+ FMT_CONSTEXPR void on_24_hour(numeric_system) {}
+ FMT_CONSTEXPR void on_12_hour(numeric_system) {}
+ FMT_CONSTEXPR void on_minute(numeric_system) {}
+ FMT_CONSTEXPR void on_second(numeric_system) {}
+ FMT_CONSTEXPR void on_datetime(numeric_system) {}
+ FMT_CONSTEXPR void on_loc_date(numeric_system) {}
+ FMT_CONSTEXPR void on_loc_time(numeric_system) {}
+ FMT_CONSTEXPR void on_us_date() {}
+ FMT_CONSTEXPR void on_iso_date() {}
+ FMT_CONSTEXPR void on_12_hour_time() {}
+ FMT_CONSTEXPR void on_24_hour_time() {}
+ FMT_CONSTEXPR void on_iso_time() {}
+ FMT_CONSTEXPR void on_am_pm() {}
+ FMT_CONSTEXPR void on_utc_offset() {}
+ FMT_CONSTEXPR void on_tz_name() {}
+};
+
+inline const char* tm_wday_full_name(int wday) {
+ static constexpr const char* full_name_list[] = {
+ "Sunday", "Monday", "Tuesday", "Wednesday",
+ "Thursday", "Friday", "Saturday"};
+ return wday >= 0 && wday <= 6 ? full_name_list[wday] : "?";
+}
+inline const char* tm_wday_short_name(int wday) {
+ static constexpr const char* short_name_list[] = {"Sun", "Mon", "Tue", "Wed",
+ "Thu", "Fri", "Sat"};
+ return wday >= 0 && wday <= 6 ? short_name_list[wday] : "???";
+}
+
+inline const char* tm_mon_full_name(int mon) {
+ static constexpr const char* full_name_list[] = {
+ "January", "February", "March", "April", "May", "June",
+ "July", "August", "September", "October", "November", "December"};
+ return mon >= 0 && mon <= 11 ? full_name_list[mon] : "?";
+}
+inline const char* tm_mon_short_name(int mon) {
+ static constexpr const char* short_name_list[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
+ };
+ return mon >= 0 && mon <= 11 ? short_name_list[mon] : "???";
+}
+
+template <typename T, typename = void>
+struct has_member_data_tm_gmtoff : std::false_type {};
+template <typename T>
+struct has_member_data_tm_gmtoff<T, void_t<decltype(T::tm_gmtoff)>>
+ : std::true_type {};
+
+template <typename T, typename = void>
+struct has_member_data_tm_zone : std::false_type {};
+template <typename T>
+struct has_member_data_tm_zone<T, void_t<decltype(T::tm_zone)>>
+ : std::true_type {};
+
+#if FMT_USE_TZSET
+inline void tzset_once() {
+ static bool init = []() -> bool {
+ _tzset();
+ return true;
+ }();
+ ignore_unused(init);
+}
+#endif
+
+template <typename OutputIt, typename Char> class tm_writer {
*** OUTPUT TRUNCATED, 5961 LINES SKIPPED ***
More information about the Commits
mailing list