Merge pull request #23 from elijah-thomas774/ut_CharStrmReader

ut_CharStrmReader
This commit is contained in:
Elijah Thomas
2024-05-05 12:33:37 -04:00
committed by GitHub
2 changed files with 55 additions and 1 deletions
+1 -1
View File
@@ -330,7 +330,7 @@ config.libs = [
Object(Matching, "nw4r/ut/ut_list.cpp"),
Object(Matching, "nw4r/ut/ut_LinkList.cpp"),
Object(Matching, "nw4r/ut/ut_binaryFileFormat.cpp"),
Object(NonMatching, "nw4r/ut/ut_CharStrmReader.cpp"),
Object(Matching, "nw4r/ut/ut_CharStrmReader.cpp"),
Object(Matching, "nw4r/ut/ut_IOStream.cpp"),
Object(Matching, "nw4r/ut/ut_TagProcessorBase.cpp"),
Object(Matching, "nw4r/ut/ut_FileStream.cpp"),
+54
View File
@@ -0,0 +1,54 @@
#include <nw4r/ut/ut_CharStrmReader.h>
namespace nw4r {
namespace ut {
namespace {
bool IsSJISLeadByte(u8 c) {
return ((c >= 0x81) && (c < 0xA0)) || c >= 0xe0;
}
} // namespace
u16 CharStrmReader::ReadNextCharUTF8() {
u16 code;
if (!(GetChar<u8>(0) & 0x80)) {
code = GetChar<u8>(0);
StepStrm<u8>(1);
} else if ((GetChar<u8>(0) & 0xe0) == 0xC0) {
code = ((GetChar<u8>(0) & 0x1F) << 6) | GetChar<u8>(1) & 0x3F;
StepStrm<u8>(2);
} else {
code = ((GetChar<u8>(0) & 0x1F) << 12) | ((GetChar<u8>(1) & 0x3F) << 6) | (GetChar<u8>(2) & 0x3F);
StepStrm<u8>(3);
}
return code;
}
u16 CharStrmReader::ReadNextCharUTF16() {
u16 code = GetChar<u16>(0);
StepStrm<u16>(1);
return code;
}
u16 CharStrmReader::ReadNextCharCP1252() {
u16 code = GetChar<u8>(0);
StepStrm<u8>(1);
return code;
}
u16 CharStrmReader::ReadNextCharSJIS() {
u16 code = GetChar<u8>(0);
if (IsSJISLeadByte((u8)code)) {
code = GetChar<u8>(1) | (GetChar<u8>(0) << 8);
StepStrm<u8>(2);
} else {
code = GetChar<u8>(0);
StepStrm<u8>(1);
}
return code;
}
} // namespace ut
} // namespace nw4r