Fix is_printable

This commit is contained in:
Victor Zverovich 2021-08-22 10:24:51 -07:00
parent cdb4299acb
commit 07d033ecb4
3 changed files with 8 additions and 37 deletions

View File

@ -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<int>(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;

View File

@ -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<int>(x);
auto current = true;
for (size_t i = 0; i < normal_size; ++i) {
auto v = static_cast<int>(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')

View File

@ -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<std::string>;
EXPECT_EQ(fmt::format("{}", vec{"\n\r\t\"\\"}), "[\"\\n\\r\\t\\\"\\\\\"]");