diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 116cf3b6..79136530 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -244,7 +244,7 @@ inline auto check(uint16_t x, const singleton* singletonuppers, if (xupper < su.upper) break; if (xupper == su.upper) { for (auto j = lowerstart; j < lowerend; ++j) { - if (singletonlowers[j] == x) return false; + if (singletonlowers[j] == (x & 0xff)) return false; } } lowerstart = lowerend; @@ -254,7 +254,7 @@ inline auto check(uint16_t x, const singleton* singletonuppers, auto current = true; for (size_t i = 0; i < normal_size; ++i) { auto v = static_cast(normal[i]); - auto len = (v & 0x80) != 0 ? (v & 0x7f) << 8 | normal[i++] : v; + auto len = (v & 0x80) != 0 ? (v & 0x7f) << 8 | normal[++i] : v; xsigned -= len; if (xsigned < 0) break; current = !current; diff --git a/support/printable.py b/support/printable.py index 192e89d6..ccb36e11 100755 --- a/support/printable.py +++ b/support/printable.py @@ -171,41 +171,6 @@ def main(): normal1 = compress_normal(normal1) print("""\ -struct singleton { - unsigned char upper; - unsigned char lowercount; -}; - -inline auto check(uint16_t x, const singleton* singletonuppers, - size_t singletonuppers_size, - const unsigned char* singletonlowers, - const unsigned char* normal, size_t normal_size) -> bool { - auto xupper = x >> 8; - auto lowerstart = 0; - for (size_t i = 0; i < singletonuppers_size; ++i) { - auto su = singletonuppers[i]; - auto lowerend = lowerstart + su.lowercount; - if (xupper < su.upper) break; - if (xupper == su.upper) { - for (auto j = lowerstart; j < lowerend; ++j) { - if (singletonlowers[j] == x) return false; - } - } - lowerstart = lowerend; - } - - auto xsigned = static_cast(x); - auto current = true; - for (size_t i = 0; i < normal_size; ++i) { - auto v = static_cast(normal[i]); - auto len = v & 0x80 != 0 ? (v & 0x7f) << 8 | normal[i++] : v; - xsigned -= len; - if (xsigned < 0) break; - current = !current; - } - return current; -} - inline auto is_printable(uint32_t cp) -> bool {\ """) print_singletons(singletons0u, singletons0l, 'singletons0u', 'singletons0l') diff --git a/test/ranges-test.cc b/test/ranges-test.cc index 1addbf5f..1d908b40 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -263,6 +263,12 @@ TEST(ranges_test, join_range) { } #endif // FMT_RANGES_TEST_ENABLE_JOIN +TEST(ranges_test, is_printable) { + using fmt::detail::is_printable; + EXPECT_TRUE(is_printable(0x0323)); + EXPECT_FALSE(is_printable(0x0378)); +} + TEST(ranges_test, escape_string) { using vec = std::vector; EXPECT_EQ(fmt::format("{}", vec{"\n\r\t\"\\"}), "[\"\\n\\r\\t\\\"\\\\\"]");