yhirose 4 years ago
parent d84c2993af
commit b3b29ce8f3
  1. 6
      peglib.h
  2. 11
      test/test1.cc

@ -180,11 +180,11 @@ inline size_t codepoint_length(const char *s8, size_t l) {
auto b = static_cast<uint8_t>(s8[0]);
if ((b & 0x80) == 0) {
return 1;
} else if ((b & 0xE0) == 0xC0) {
} else if ((b & 0xE0) == 0xC0 && l >= 2) {
return 2;
} else if ((b & 0xF0) == 0xE0) {
} else if ((b & 0xF0) == 0xE0 && l >= 3) {
return 3;
} else if ((b & 0xF8) == 0xF0) {
} else if ((b & 0xF8) == 0xF0 && l >= 4) {
return 4;
}
}

@ -45,6 +45,17 @@ TEST_CASE("Start rule with ignore operator test", "[general]")
REQUIRE(ret == false);
}
TEST_CASE("Invalid UTF-8 text test", "[general]")
{
std::string s = "a <- '";
s += static_cast<char>(0xe8); // Make invalid utf8 text...
parser parser(s.c_str());
bool ret = parser;
REQUIRE(ret == false);
}
TEST_CASE("Backslash escape sequence test", "[general]")
{
parser parser(R"(

Loading…
Cancel
Save