diff options
author | Filippos Karapetis | 2013-11-08 12:17:48 +0200 |
---|---|---|
committer | Filippos Karapetis | 2013-11-08 12:17:48 +0200 |
commit | 4af998b96cc2b0d3513ded57985c4d434cd362a4 (patch) | |
tree | 00f9c3dcf59120d5afa7d9aa784e6480fc6dd776 /engines | |
parent | 492cefacb6a242dc9a7eca3bbfe8f8bace635bd4 (diff) | |
download | scummvm-rg350-4af998b96cc2b0d3513ded57985c4d434cd362a4.tar.gz scummvm-rg350-4af998b96cc2b0d3513ded57985c4d434cd362a4.tar.bz2 scummvm-rg350-4af998b96cc2b0d3513ded57985c4d434cd362a4.zip |
WINTERMUTE: Move the isAscii() string changing code to another function
Diffstat (limited to 'engines')
-rw-r--r-- | engines/wintermute/utils/string_util.cpp | 22 | ||||
-rw-r--r-- | engines/wintermute/utils/string_util.h | 3 |
2 files changed, 20 insertions, 5 deletions
diff --git a/engines/wintermute/utils/string_util.cpp b/engines/wintermute/utils/string_util.cpp index c359b1f961..d5d6c7f702 100644 --- a/engines/wintermute/utils/string_util.cpp +++ b/engines/wintermute/utils/string_util.cpp @@ -48,11 +48,14 @@ bool StringUtil::compareNoCase(const AnsiString &str1, const AnsiString &str2) { return (str1lc == str2lc); }*/ -bool StringUtil::isAscii(Common::String &str) { +Common::String StringUtil::substituteUtf8Characters(Common::String &str) { uint strSize = str.size(); Common::String punctuation("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"); - for (uint32 i = 0; i < str.size(); i++) { + if (isAscii(str)) + return str; + + for (uint32 i = 0; i < strSize; i++) { if (!Common::isAlnum(str[i]) && str[i] != ' ' && !punctuation.contains(str[i])) { // Replace some UTF-8 characters with (almost) equivalent ANSII ones if ((byte)str[i] == 0xc2 && i + 1 < str.size() && (byte)str[i + 1] == 0xa9) { @@ -60,12 +63,21 @@ bool StringUtil::isAscii(Common::String &str) { str.deleteChar(i); str.setChar('c', i); strSize--; - } else { - return false; } } } + return str; +} + +bool StringUtil::isAscii(const Common::String &str) { + Common::String punctuation("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"); + + for (uint32 i = 0; i < str.size(); i++) { + if (!Common::isAlnum(str[i]) && str[i] != ' ' && !punctuation.contains(str[i])) + return false; + } + return true; } @@ -74,6 +86,7 @@ WideString StringUtil::utf8ToWide(const Utf8String &Utf8Str) { // WORKAROUND: Since wide strings aren't supported yet, we make this function // work at least with ASCII strings. This should cover all English versions. Common::String asciiString = Utf8Str; + asciiString = substituteUtf8Characters(asciiString); if (isAscii(asciiString)) { // No special (UTF-8) characters found, just return the string return asciiString; @@ -134,6 +147,7 @@ Utf8String StringUtil::wideToUtf8(const WideString &WideStr) { // WORKAROUND: Since UTF-8 strings aren't supported yet, we make this function // work at least with ASCII strings. This should cover all English versions. Common::String asciiString = WideStr; + asciiString = substituteUtf8Characters(asciiString); if (isAscii(asciiString)) { // No special (UTF-8) characters found, just return the string return asciiString; diff --git a/engines/wintermute/utils/string_util.h b/engines/wintermute/utils/string_util.h index 3ced6aa933..05931beb79 100644 --- a/engines/wintermute/utils/string_util.h +++ b/engines/wintermute/utils/string_util.h @@ -37,7 +37,8 @@ class StringUtil { public: static bool compareNoCase(const AnsiString &str1, const AnsiString &str2); //static bool compareNoCase(const WideString &str1, const WideString &str2); - static bool isAscii(Common::String &str); + static bool isAscii(const Common::String &str); + static Common::String substituteUtf8Characters(Common::String &str); static WideString utf8ToWide(const Utf8String &Utf8Str); static Utf8String wideToUtf8(const WideString &WideStr); static WideString ansiToWide(const AnsiString &str); |