utf-8 hexdump implmented

This commit is contained in:
2026-07-19 19:56:17 -06:00
parent 09d117debf
commit b30a59accd
6 changed files with 545 additions and 156 deletions
+19 -17
View File
@@ -29,18 +29,20 @@ namespace spider {
}
bool TextReader::eat(const std::string& chars) {
isize index = 0, count = 0;
u32 _char;
while(index < chars.length()) {
if(!utf8::charAt(chars, index, _char)) return false;
if(_char != peekChar(count)) return false;
count++;
// instead of whatever that was, convert to UTF-32
// and then do an easy compare!
std::u32string str;
if(!utf8::toUTF32(chars, str)) throw std::runtime_error("Specified invalid UTF-8 string!");
// compare now
isize index;
for(index = 0; index < str.size(); index++) {
if(str[index] != peekChar(index)) return false;
}
if(index == chars.length()) {
nextChar(count);
return true;
}
return false;
// success!
nextChar(index);
return true;
}
char TextReader::readByte() {
@@ -164,14 +166,14 @@ namespace spider {
bytes[bindex] = readByte();
if (err) return false;
if (eof) return false;
if (!utf8::isCont(u8(bytes[bindex]))) {
err = true;
errmsg = "Invalid continuation of UTF-8 sequence.";
return false;
}
}
u32 decodedChar = utf8::decodeArr(bytes, chsize);
u32 decodedChar;
if(!utf8::decodeArr(bytes, chsize, decodedChar)) {
err = true;
errmsg = "Invalid UTF-8 sequence.";
return false;
}
buffer.push_back(decodedChar);
return true;
}