aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarisa-Chan2014-03-09 23:19:17 +0700
committerMarisa-Chan2014-03-09 23:19:17 +0700
commit6ca301c3205cf04e4aa37c16e21224223233ea9b (patch)
tree32b59fcf4c0138c883001b11bf951d4490d999c2
parentea6e151047641563f588b6578aea80141f51bbd0 (diff)
downloadscummvm-rg350-6ca301c3205cf04e4aa37c16e21224223233ea9b.tar.gz
scummvm-rg350-6ca301c3205cf04e4aa37c16e21224223233ea9b.tar.bz2
scummvm-rg350-6ca301c3205cf04e4aa37c16e21224223233ea9b.zip
ZVISION: Add utf8 char length and utf8->uint16 functions
-rw-r--r--engines/zvision/text.cpp30
-rw-r--r--engines/zvision/text.h2
2 files changed, 32 insertions, 0 deletions
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