diff --git a/cpp/src/strings/regex/regcomp.cpp b/cpp/src/strings/regex/regcomp.cpp index 065c358d08b..6f36658523b 100644 --- a/cpp/src/strings/regex/regcomp.cpp +++ b/cpp/src/strings/regex/regcomp.cpp @@ -280,15 +280,15 @@ class regex_parser { yy = 0; if (a >= '0' && a <= '9') yy += (a - '0') << 4; - else if (a > 'a' && a <= 'f') + else if (a >= 'a' && a <= 'f') yy += (a - 'a' + 10) << 4; - else if (a > 'A' && a <= 'F') + else if (a >= 'A' && a <= 'F') yy += (a - 'A' + 10) << 4; if (b >= '0' && b <= '9') yy += b - '0'; - else if (b > 'a' && b <= 'f') + else if (b >= 'a' && b <= 'f') yy += b - 'a' + 10; - else if (b > 'A' && b <= 'F') + else if (b >= 'A' && b <= 'F') yy += b - 'A' + 10; break; } diff --git a/cpp/tests/strings/contains_tests.cpp b/cpp/tests/strings/contains_tests.cpp index a72ec61dd8f..bacd62ac86e 100644 --- a/cpp/tests/strings/contains_tests.cpp +++ b/cpp/tests/strings/contains_tests.cpp @@ -14,12 +14,12 @@ * limitations under the License. */ +#include #include #include #include #include #include -#include #include #include @@ -250,6 +250,33 @@ TEST_F(StringsContainsTests, OctalTest) CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected); } +TEST_F(StringsContainsTests, HexTest) +{ + std::vector ascii_chars( // all possible matchable chars + {thrust::make_counting_iterator(0), thrust::make_counting_iterator(127)}); + auto const count = static_cast(ascii_chars.size()); + std::vector offsets( + {thrust::make_counting_iterator(0), + thrust::make_counting_iterator(0) + count + 1}); + auto d_chars = cudf::detail::make_device_uvector_sync(ascii_chars); + auto d_offsets = cudf::detail::make_device_uvector_sync(offsets); + auto input = cudf::make_strings_column(d_chars, d_offsets); + + auto strings_view = cudf::strings_column_view(input->view()); + for (auto ch : ascii_chars) { + std::stringstream str; + str << "\\x" << std::setfill('0') << std::setw(2) << std::hex << static_cast(ch); + std::string pattern = str.str(); + + auto results = cudf::strings::contains_re(strings_view, pattern); + // only one element in the input should match ch + auto true_dat = cudf::detail::make_counting_transform_iterator( + 0, [ch](auto idx) { return ch == static_cast(idx); }); + cudf::test::fixed_width_column_wrapper expected(true_dat, true_dat + count); + CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected); + } +} + TEST_F(StringsContainsTests, EmbeddedNullCharacter) { std::vector data(10);