Skip to content

Commit 8a192dc

Browse files
committed
Fix(scan_for_text_asii): Fixed error and expanded tests with wider strings.
1 parent 209a4c2 commit 8a192dc

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/libunicode/scan.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace
5555

5656
size_t detail::scan_for_text_ascii(string_view text, size_t maxColumnCount) noexcept
5757
{
58-
#if defined(__x86_64__) || defined(_M_AMD64)
58+
#if (defined(LIBUNICODE_USE_STD_SIMD) || defined(LIBUNICODE_USE_INTRINSICS)) && defined(__x86_64__) || defined(_M_AMD64)
5959
static auto simd_size = max_simd_size();
6060
if (simd_size == 512)
6161
{

src/libunicode/scan_simd_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ size_t scan_for_text_ascii_simd(std::string_view text, size_t maxColumnCount) no
9393
#endif
9494

9595
constexpr auto is_ascii = [](char ch) noexcept {
96-
auto is_control = static_cast<uint8_t>(ch) > 0x20;
96+
auto is_control = static_cast<uint8_t>(ch) < 0x20;
9797
auto is_complex = static_cast<uint8_t>(ch) & 0x80;
9898
return !is_control && !is_complex;
9999
};

src/libunicode/scan_test.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ TEST_CASE("scan.ascii.empty")
109109

110110
TEST_CASE("scan.ascii.32")
111111
{
112-
auto const text = "0123456789ABCDEF0123456789ABCDEF"sv;
112+
auto const text = "0123456789ABCDEF0123456789ABCDEF"
113+
"0123456789ABCDEF0123456789ABCDEF"
114+
"0123456789ABCDEF0123456789ABCDEF"
115+
"0123456789ABCDEF0123456789ABCDEF"sv;
116+
CHECK(scan_for_text_ascii(text, 128) == 128);
117+
CHECK(scan_for_text_ascii(text, 64) == 64);
113118
CHECK(scan_for_text_ascii(text, 32) == 32);
114119
CHECK(scan_for_text_ascii(text, 16) == 16);
115120
CHECK(scan_for_text_ascii(text, 8) == 8);
@@ -123,12 +128,22 @@ TEST_CASE("scan.ascii.mixed_with_controls")
123128
CHECK(scan_for_text_ascii("12345678\033", 80) == 8);
124129
CHECK(scan_for_text_ascii("0123456789ABCDEF\033", 80) == 16);
125130
CHECK(scan_for_text_ascii("0123456789ABCDEF1\033", 80) == 17);
131+
constexpr auto text = "0123456789ABCDEF0\033123456789ABCDEF"
132+
"0123456789ABCDEF0123456789ABCDEF"
133+
"0123456789ABCDEF0123456789ABCDEF"
134+
"0123456789ABCDEF0123456789ABCDEF"sv;
135+
CHECK(scan_for_text_ascii(text, 80) == 17);
126136
}
127137

128138
TEST_CASE("scan.ascii.until_complex")
129139
{
130140
CHECK(scan_for_text_ascii("1234\x80", 80) == 4);
131141
CHECK(scan_for_text_ascii("0123456789{\xE2\x94\x80}ABCDEF", 80) == 11);
142+
constexpr auto text = "0123456789{\xE2\x94\x80}ABCDEF0323456789ABCDEF"
143+
"0123456789ABCDEF0123456789ABCDEF"
144+
"0123456789ABCDEF0123456789ABCDEF"
145+
"0123456789ABCDEF0123456789ABCDEF"sv;
146+
CHECK(scan_for_text_ascii(text, 80) == 11);
132147
}
133148

134149
TEST_CASE("scan.complex.grapheme_cluster.1")

0 commit comments

Comments
 (0)