mirror of
https://github.com/shadps4-emu/ext-fmt.git
synced 2024-11-23 01:39:40 +00:00
Improve debug codegen
This commit is contained in:
parent
9f29345ea0
commit
a6ecd25b80
@ -465,15 +465,14 @@ struct is_std_string_like<T, void_t<decltype(std::declval<T>().find_first_of(
|
||||
|
||||
// Returns true iff the literal encoding is UTF-8.
|
||||
constexpr auto is_utf8_enabled() -> bool { return "\u00A7"[1] == '\xA7'; }
|
||||
constexpr auto use_utf8() -> bool {
|
||||
return !FMT_MSC_VERSION || is_utf8_enabled();
|
||||
}
|
||||
// It is a macro for better debug codegen without if constexpr.
|
||||
#define FMT_USE_UTF8 (!FMT_MSC_VERSION || fmt::detail::is_utf8_enabled())
|
||||
|
||||
#ifndef FMT_UNICODE
|
||||
# define FMT_UNICODE 1
|
||||
#endif
|
||||
|
||||
static_assert(!FMT_UNICODE || use_utf8(),
|
||||
static_assert(!FMT_UNICODE || FMT_USE_UTF8,
|
||||
"Unicode support requires compiling with /utf-8");
|
||||
|
||||
template <typename Char> FMT_CONSTEXPR auto length(const Char* s) -> size_t {
|
||||
@ -3061,7 +3060,7 @@ FMT_API void vprintln(FILE* f, string_view fmt, format_args args);
|
||||
template <typename... T>
|
||||
FMT_INLINE void print(format_string<T...> fmt, T&&... args) {
|
||||
const auto& vargs = fmt::make_format_args(args...);
|
||||
if (!detail::use_utf8()) return detail::vprint_mojibake(stdout, fmt, vargs);
|
||||
if (!FMT_USE_UTF8) return detail::vprint_mojibake(stdout, fmt, vargs);
|
||||
return detail::is_locking<T...>() ? vprint_buffered(stdout, fmt, vargs)
|
||||
: vprint(fmt, vargs);
|
||||
}
|
||||
@ -3077,7 +3076,7 @@ FMT_INLINE void print(format_string<T...> fmt, T&&... args) {
|
||||
template <typename... T>
|
||||
FMT_INLINE void print(FILE* f, format_string<T...> fmt, T&&... args) {
|
||||
const auto& vargs = fmt::make_format_args(args...);
|
||||
if (!detail::use_utf8()) return detail::vprint_mojibake(f, fmt, vargs);
|
||||
if (!FMT_USE_UTF8) return detail::vprint_mojibake(f, fmt, vargs);
|
||||
return detail::is_locking<T...>() ? vprint_buffered(f, fmt, vargs)
|
||||
: vprint(f, fmt, vargs);
|
||||
}
|
||||
@ -3087,8 +3086,8 @@ FMT_INLINE void print(FILE* f, format_string<T...> fmt, T&&... args) {
|
||||
template <typename... T>
|
||||
FMT_INLINE void println(FILE* f, format_string<T...> fmt, T&&... args) {
|
||||
const auto& vargs = fmt::make_format_args(args...);
|
||||
return detail::use_utf8() ? vprintln(f, fmt, vargs)
|
||||
: detail::vprint_mojibake(f, fmt, vargs, true);
|
||||
return FMT_USE_UTF8 ? vprintln(f, fmt, vargs)
|
||||
: detail::vprint_mojibake(f, fmt, vargs, true);
|
||||
}
|
||||
|
||||
/// Formats `args` according to specifications in `fmt` and writes the output
|
||||
|
@ -357,7 +357,7 @@ void write_codecvt(codecvt_result<CodeUnit>& out, string_view in_buf,
|
||||
template <typename OutputIt>
|
||||
auto write_encoded_tm_str(OutputIt out, string_view in, const std::locale& loc)
|
||||
-> OutputIt {
|
||||
if (detail::use_utf8() && loc != get_classic_locale()) {
|
||||
if (FMT_USE_UTF8 && loc != get_classic_locale()) {
|
||||
// char16_t and char32_t codecvts are broken in MSVC (linkage errors) and
|
||||
// gcc-4.
|
||||
#if FMT_MSC_VERSION != 0 || \
|
||||
@ -651,7 +651,8 @@ FMT_CONSTEXPR inline auto get_units() -> const char* {
|
||||
if (std::is_same<Period, std::femto>::value) return "fs";
|
||||
if (std::is_same<Period, std::pico>::value) return "ps";
|
||||
if (std::is_same<Period, std::nano>::value) return "ns";
|
||||
if (std::is_same<Period, std::micro>::value) return use_utf8() ? "µs" : "us";
|
||||
if (std::is_same<Period, std::micro>::value)
|
||||
return FMT_USE_UTF8 ? "µs" : "us";
|
||||
if (std::is_same<Period, std::milli>::value) return "ms";
|
||||
if (std::is_same<Period, std::centi>::value) return "cs";
|
||||
if (std::is_same<Period, std::deci>::value) return "ds";
|
||||
|
@ -1860,7 +1860,7 @@ auto find_escape(const Char* begin, const Char* end)
|
||||
|
||||
inline auto find_escape(const char* begin, const char* end)
|
||||
-> find_escape_result<char> {
|
||||
if (!use_utf8()) return find_escape<char>(begin, end);
|
||||
if (!FMT_USE_UTF8) return find_escape<char>(begin, end);
|
||||
auto result = find_escape_result<char>{end, nullptr, 0};
|
||||
for_each_codepoint(string_view(begin, to_unsigned(end - begin)),
|
||||
[&](uint32_t cp, string_view sv) {
|
||||
|
@ -179,7 +179,7 @@ void vprint(std::basic_ostream<Char>& os,
|
||||
FMT_EXPORT template <typename... T>
|
||||
void print(std::ostream& os, format_string<T...> fmt, T&&... args) {
|
||||
const auto& vargs = fmt::make_format_args(args...);
|
||||
if (detail::use_utf8())
|
||||
if (FMT_USE_UTF8)
|
||||
vprint(os, fmt, vargs);
|
||||
else
|
||||
detail::vprint_directly(os, fmt, vargs);
|
||||
|
@ -560,7 +560,7 @@ TEST(ranges_test, escape) {
|
||||
EXPECT_EQ(fmt::format("{}", vec{"\x7f"}), "[\"\\x7f\"]");
|
||||
EXPECT_EQ(fmt::format("{}", vec{"n\xcc\x83"}), "[\"n\xcc\x83\"]");
|
||||
|
||||
if (fmt::detail::use_utf8()) {
|
||||
if (FMT_USE_UTF8) {
|
||||
EXPECT_EQ(fmt::format("{}", vec{"\xcd\xb8"}), "[\"\\u0378\"]");
|
||||
// Unassigned Unicode code points.
|
||||
EXPECT_EQ(fmt::format("{}", vec{"\xf0\xaa\x9b\x9e"}), "[\"\\U0002a6de\"]");
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
using testing::Contains;
|
||||
|
||||
TEST(unicode_test, use_utf8) { EXPECT_TRUE(fmt::detail::use_utf8()); }
|
||||
TEST(unicode_test, use_utf8) { EXPECT_TRUE(FMT_USE_UTF8); }
|
||||
|
||||
TEST(unicode_test, legacy_locale) {
|
||||
auto loc = get_locale("be_BY.CP1251", "Belarusian_Belarus.1251");
|
||||
|
Loading…
Reference in New Issue
Block a user