forked from fmtlib/fmt
Fix is_printable
This commit is contained in:
@ -244,7 +244,7 @@ inline auto check(uint16_t x, const singleton* singletonuppers,
|
|||||||
if (xupper < su.upper) break;
|
if (xupper < su.upper) break;
|
||||||
if (xupper == su.upper) {
|
if (xupper == su.upper) {
|
||||||
for (auto j = lowerstart; j < lowerend; ++j) {
|
for (auto j = lowerstart; j < lowerend; ++j) {
|
||||||
if (singletonlowers[j] == x) return false;
|
if (singletonlowers[j] == (x & 0xff)) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lowerstart = lowerend;
|
lowerstart = lowerend;
|
||||||
@ -254,7 +254,7 @@ inline auto check(uint16_t x, const singleton* singletonuppers,
|
|||||||
auto current = true;
|
auto current = true;
|
||||||
for (size_t i = 0; i < normal_size; ++i) {
|
for (size_t i = 0; i < normal_size; ++i) {
|
||||||
auto v = static_cast<int>(normal[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;
|
xsigned -= len;
|
||||||
if (xsigned < 0) break;
|
if (xsigned < 0) break;
|
||||||
current = !current;
|
current = !current;
|
||||||
|
@ -171,41 +171,6 @@ def main():
|
|||||||
normal1 = compress_normal(normal1)
|
normal1 = compress_normal(normal1)
|
||||||
|
|
||||||
print("""\
|
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 {\
|
inline auto is_printable(uint32_t cp) -> bool {\
|
||||||
""")
|
""")
|
||||||
print_singletons(singletons0u, singletons0l, 'singletons0u', 'singletons0l')
|
print_singletons(singletons0u, singletons0l, 'singletons0u', 'singletons0l')
|
||||||
|
@ -263,6 +263,12 @@ TEST(ranges_test, join_range) {
|
|||||||
}
|
}
|
||||||
#endif // FMT_RANGES_TEST_ENABLE_JOIN
|
#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) {
|
TEST(ranges_test, escape_string) {
|
||||||
using vec = std::vector<std::string>;
|
using vec = std::vector<std::string>;
|
||||||
EXPECT_EQ(fmt::format("{}", vec{"\n\r\t\"\\"}), "[\"\\n\\r\\t\\\"\\\\\"]");
|
EXPECT_EQ(fmt::format("{}", vec{"\n\r\t\"\\"}), "[\"\\n\\r\\t\\\"\\\\\"]");
|
||||||
|
Reference in New Issue
Block a user