From 88df5e430bf5f29dd52202c9ee84079e92c3a04e Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 4 May 2024 23:11:25 -0400 Subject: [PATCH 1/3] Update ut_CharStrmReader.cpp --- src/nw4r/ut/ut_CharStrmReader.cpp | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/nw4r/ut/ut_CharStrmReader.cpp b/src/nw4r/ut/ut_CharStrmReader.cpp index e69de29b..647875de 100644 --- a/src/nw4r/ut/ut_CharStrmReader.cpp +++ b/src/nw4r/ut/ut_CharStrmReader.cpp @@ -0,0 +1,61 @@ +#include + +namespace nw4r { +namespace ut { +namespace { + +bool IsSJISLeadByte(u8 c) { + // Idk how to force the comparison correctly + return ((c >= 0x81) && (c < 0xA0)) || c >= 0xe0; +} + +} // namespace + +u16 CharStrmReader::ReadNextCharUTF8() { + u16 code; + + if (!(GetChar(0) & 0x80)) { + code = GetChar(0); + StepStrm(1); + } else if ((GetChar(0) & 0xe0) == 0xC0) { + code = ((GetChar(0) & 0x1F) << 6) | GetChar(1) & 0x3F; + StepStrm(2); + } else { + code = ((GetChar(0) & 0x1F) << 12) | ((GetChar(1) & 0x3F) << 6) | (GetChar(2) & 0x3F); + StepStrm(3); + } + return code; +} + +u16 CharStrmReader::ReadNextCharUTF16() { + u16 code = GetChar(0); + StepStrm(1); + return code; +} +u16 CharStrmReader::ReadNextCharCP1252() { + u16 code = GetChar(0); + StepStrm(1); + return code; +} +u16 CharStrmReader::ReadNextCharSJIS() { + u16 code = GetChar(0); + + bool isLead = false; + + if ((((u8)GetChar(0) >= 0x81) && ((u8)GetChar(0) <= 0xA0)) || (u8)GetChar(0) >= 0xe0) { + isLead = true; + } + + if (isLead) { + code = GetChar(1) | (GetChar(0) << 8); + StepStrm(2); + } else { + code = GetChar(0); + StepStrm(1); + } + return code; +} + +} // namespace ut + +} // namespace nw4r From 282402ff85bb22480933ffa810bed022172adb8d Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 09:25:21 +0200 Subject: [PATCH 2/3] Match ut_CharStreamReader --- configure.py | 2 +- src/nw4r/ut/ut_CharStrmReader.cpp | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/configure.py b/configure.py index 5336a084..547c57d3 100644 --- a/configure.py +++ b/configure.py @@ -320,7 +320,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(NonMatching, "nw4r/ut/ut_TagProcessorBase.cpp"), Object(NonMatching, "nw4r/ut/ut_IOStream.cpp"), Object(NonMatching, "nw4r/ut/ut_FileStream.cpp"), diff --git a/src/nw4r/ut/ut_CharStrmReader.cpp b/src/nw4r/ut/ut_CharStrmReader.cpp index 647875de..b8f96984 100644 --- a/src/nw4r/ut/ut_CharStrmReader.cpp +++ b/src/nw4r/ut/ut_CharStrmReader.cpp @@ -40,13 +40,7 @@ u16 CharStrmReader::ReadNextCharCP1252() { u16 CharStrmReader::ReadNextCharSJIS() { u16 code = GetChar(0); - bool isLead = false; - - if ((((u8)GetChar(0) >= 0x81) && ((u8)GetChar(0) <= 0xA0)) || (u8)GetChar(0) >= 0xe0) { - isLead = true; - } - - if (isLead) { + if (IsSJISLeadByte((u8)code)) { code = GetChar(1) | (GetChar(0) << 8); StepStrm(2); } else { From bb65dd55186cf631b473f53b141fa418bb08cd3c Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 09:30:54 +0200 Subject: [PATCH 3/3] Drop comment --- src/nw4r/ut/ut_CharStrmReader.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/nw4r/ut/ut_CharStrmReader.cpp b/src/nw4r/ut/ut_CharStrmReader.cpp index b8f96984..81bb80fa 100644 --- a/src/nw4r/ut/ut_CharStrmReader.cpp +++ b/src/nw4r/ut/ut_CharStrmReader.cpp @@ -5,7 +5,6 @@ namespace ut { namespace { bool IsSJISLeadByte(u8 c) { - // Idk how to force the comparison correctly return ((c >= 0x81) && (c < 0xA0)) || c >= 0xe0; }