WIP port 4-d quest dialogue modules
This commit is contained in:
@@ -391,4 +391,35 @@ int WideCharToMultiByte(UINT CodePage, DWORD, LPCWSTR lpWideCharStr, int cchWide
|
||||
return int(bytes.size());
|
||||
}
|
||||
|
||||
BOOL IsDBCSLeadByteEx(UINT CodePage, BYTE TestChar)
|
||||
{
|
||||
switch (CodePage) {
|
||||
case 932: return (TestChar >= 0x81 && TestChar <= 0x9F) || (TestChar >= 0xE0 && TestChar <= 0xFC);
|
||||
case 936:
|
||||
case 949:
|
||||
case 950: return TestChar >= 0x81 && TestChar <= 0xFE;
|
||||
default: return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
LPSTR CharNextExA(WORD CodePage, LPCSTR lpCurrentChar, DWORD)
|
||||
{
|
||||
if (!*lpCurrentChar) return const_cast<LPSTR>(lpCurrentChar);
|
||||
if (IsDBCSLeadByteEx(CodePage, BYTE(*lpCurrentChar)) && lpCurrentChar[1]) return const_cast<LPSTR>(lpCurrentChar + 2);
|
||||
return const_cast<LPSTR>(lpCurrentChar + 1);
|
||||
}
|
||||
|
||||
LPSTR CharPrevExA(WORD CodePage, LPCSTR lpStart, LPCSTR lpCurrentChar, DWORD dwFlags)
|
||||
{
|
||||
// Walk forward from lpStart so a trail byte is never taken for a lead byte.
|
||||
LPCSTR prev = lpStart;
|
||||
for (LPCSTR p = lpStart; p < lpCurrentChar;) {
|
||||
prev = p;
|
||||
LPCSTR next = CharNextExA(CodePage, p, dwFlags);
|
||||
if (next == p) break;
|
||||
p = next;
|
||||
}
|
||||
return const_cast<LPSTR>(prev);
|
||||
}
|
||||
|
||||
#endif // !_WIN32
|
||||
|
||||
Reference in New Issue
Block a user