mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Fix #122
This commit is contained in:
parent
d84c2993af
commit
b3b29ce8f3
6
peglib.h
6
peglib.h
@ -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…
Reference in New Issue
Block a user