From 6ca301c3205cf04e4aa37c16e21224223233ea9b Mon Sep 17 00:00:00 2001 From: Marisa-Chan Date: Sun, 9 Mar 2014 23:19:17 +0700 Subject: ZVISION: Add utf8 char length and utf8->uint16 functions --- engines/zvision/text.cpp | 30 ++++++++++++++++++++++++++++++ engines/zvision/text.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/engines/zvision/text.cpp b/engines/zvision/text.cpp index e96bf4b32c..2fdfafcdf6 100644 --- a/engines/zvision/text.cpp +++ b/engines/zvision/text.cpp @@ -515,5 +515,35 @@ Common::String readWideLine(Common::SeekableReadStream &stream) { return asciiString; } +int8 getUtf8CharSize(char chr) { + if ((chr & 0x80) == 0) + return 1; + else if ((chr & 0xE0) == 0xC0) + return 2; + else if ((chr & 0xF0) == 0xE0) + return 3; + else if ((chr & 0xF8) == 0xF0) + return 4; + else if ((chr & 0xFC) == 0xF8) + return 5; + else if ((chr & 0xFE) == 0xFC) + return 6; + + return 1; +} + +uint16 readUtf8Char(const char *chr) { + uint16 result = 0; + if ((chr[0] & 0x80) == 0) + result = chr[0]; + else if ((chr[0] & 0xE0) == 0xC0) + result = ((chr[0] & 0x1F) << 6) | (chr[1] & 0x3F); + else if ((chr[0] & 0xF0) == 0xE0) + result = ((chr[0] & 0x0F) << 12) | ((chr[1] & 0x3F) << 6) | (chr[2] & 0x3F); + else + result = chr[0]; + + return result; +} } // End of namespace ZVision diff --git a/engines/zvision/text.h b/engines/zvision/text.h index 6937832335..c1dc0c167c 100644 --- a/engines/zvision/text.h +++ b/engines/zvision/text.h @@ -92,6 +92,8 @@ private: }; Common::String readWideLine(Common::SeekableReadStream &stream); +int8 getUtf8CharSize(char chr); +uint16 readUtf8Char(const char *chr); } // End of namespace ZVision -- cgit v1.2.3