Skip to content

Commit

Permalink
Fix chrono_test.locale on libc++
Browse files Browse the repository at this point in the history
  • Loading branch information
phprus committed Jun 10, 2021
1 parent 36c2948 commit f4a634b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ inline auto do_write(const std::tm& time, const std::locale& loc, char format,
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).
using code_unit = conditional_t<FMT_MSC_VER != 0, wchar_t, char16_t>;
using code_unit = conditional_t<FMT_MSC_VER != 0, wchar_t, char32_t>;
auto& f = std::use_facet<std::codecvt<code_unit, char, std::mbstate_t>>(loc);
auto mb = std::mbstate_t();
const char* from_next = nullptr;
Expand All @@ -317,6 +317,15 @@ inline auto do_write(const std::tm& time, const std::locale& loc, char format,
} 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"));
}
Expand Down

0 comments on commit f4a634b

Please sign in to comment.