Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cpp] Implement UTF-8 check with the Bjoern DFA
- Loading branch information
Andy C
committed
Jan 6, 2024
1 parent
3e66096
commit 6772c74
Showing
4 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "cpp/data_lang.h" | ||
|
||
#include "vendor/greatest.h" | ||
|
||
TEST part_is_utf8_test() { | ||
BigStr* s = StrFromC("hi"); | ||
|
||
ASSERT(pyj8::PartIsUtf8(s, 0, 2)); | ||
|
||
// empty string is trivially UTF-8 | ||
ASSERT(pyj8::PartIsUtf8(s, 0, 0)); | ||
|
||
BigStr* binary = StrFromC("h\xff"); | ||
ASSERT(!pyj8::PartIsUtf8(binary, 0, len(binary))); | ||
|
||
// first byte is UTF-8 | ||
ASSERT(pyj8::PartIsUtf8(binary, 0, 1)); | ||
// second byte isn't | ||
ASSERT(!pyj8::PartIsUtf8(binary, 1, 2)); | ||
|
||
PASS(); | ||
} | ||
|
||
GREATEST_MAIN_DEFS(); | ||
|
||
int main(int argc, char** argv) { | ||
GREATEST_MAIN_BEGIN(); | ||
|
||
RUN_TEST(part_is_utf8_test); | ||
|
||
GREATEST_MAIN_END(); | ||
return 0; | ||
} |