diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 1e07a873f261..88f58d1b1227 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -51,7 +51,6 @@ #include "sludge/sprites.h" #include "sludge/statusba.h" #include "sludge/sludge.h" -#include "sludge/utf8.h" #include "sludge/zbuffer.h" namespace Sludge { @@ -471,9 +470,7 @@ builtIn(substring) { wholeString = fun->stack->thisVar.getTextFromAnyVar(); trimStack(fun->stack); - UTF8Converter convert; - convert.setUTF8String(wholeString); - Common::U32String str32 = convert.getU32String(); + Common::U32String str32 = wholeString.decode(Common::kUtf8); if ((int)str32.size() < start + length) { length = str32.size() - start; @@ -485,10 +482,7 @@ builtIn(substring) { length = 0; } - int startoffset = convert.getOriginOffset(start); - int endoffset = convert.getOriginOffset(start + length); - - Common::String newString(wholeString.begin() + startoffset, wholeString.begin() + endoffset); + Common::String newString = str32.substr(start, length).encode(Common::kUtf8); fun->reg.makeTextVar(newString); return BR_CONTINUE; diff --git a/engines/sludge/fonttext.cpp b/engines/sludge/fonttext.cpp index 6163c445acde..33ac2aa03de6 100644 --- a/engines/sludge/fonttext.cpp +++ b/engines/sludge/fonttext.cpp @@ -63,7 +63,7 @@ bool TextManager::isInFont(const Common::String &theText) { if (theText.empty()) return 0; - Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText); + Common::U32String str32 = theText.decode(Common::kUtf8); // We don't want to compare strings. Only single characters allowed! if (str32.size() > 1) @@ -72,11 +72,11 @@ bool TextManager::isInFont(const Common::String &theText) { uint32 c = str32[0]; // check if font order contains the utf8 char - return _fontOrder.getU32String().contains(c); + return _fontOrder.contains(c); } int TextManager::stringLength(const Common::String &theText) { - Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText); + Common::U32String str32 = theText.decode(Common::kUtf8); return str32.size(); } @@ -86,7 +86,7 @@ int TextManager::stringWidth(const Common::String &theText) { if (_fontTable.empty()) return 0; - Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText); + Common::U32String str32 = theText.decode(Common::kUtf8); for (uint i = 0; i < str32.size(); ++i) { uint32 c = str32[i]; @@ -102,7 +102,7 @@ void TextManager::pasteString(const Common::String &theText, int xOff, int y, Sp xOff += (int)((float)(_fontSpace >> 1) / g_sludge->_gfxMan->getCamZoom()); - Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText); + Common::U32String str32 = theText.decode(Common::kUtf8); for (uint32 i = 0; i < str32.size(); ++i) { uint32 c = str32[i]; @@ -116,7 +116,7 @@ void TextManager::pasteStringToBackdrop(const Common::String &theText, int xOff, if (_fontTable.empty()) return; - Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText); + Common::U32String str32 = theText.decode(Common::kUtf8); xOff += _fontSpace >> 1; for (uint32 i = 0; i < str32.size(); ++i) { @@ -131,7 +131,7 @@ void TextManager::burnStringToBackdrop(const Common::String &theText, int xOff, if (_fontTable.empty()) return; - Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText); + Common::U32String str32 = theText.decode(Common::kUtf8); xOff += _fontSpace >> 1; for (uint i = 0; i < str32.size(); ++i) { @@ -143,14 +143,14 @@ void TextManager::burnStringToBackdrop(const Common::String &theText, int xOff, } bool TextManager::loadFont(int filenum, const Common::String &charOrder, int h) { - _fontOrder.setUTF8String(charOrder); + _fontOrder = charOrder.decode(Common::kUtf8); g_sludge->_gfxMan->forgetSpriteBank(_theFont); _loadedFontNum = filenum; // get max value among all utf8 chars - Common::U32String fontOrderString = _fontOrder.getU32String(); + Common::U32String fontOrderString = _fontOrder; // create an index table from utf8 char to the index if (!_fontTable.empty()) { @@ -178,7 +178,7 @@ void TextManager::saveFont(Common::WriteStream *stream) { if (!_fontTable.empty()) { stream->writeUint16BE(_loadedFontNum); stream->writeUint16BE(_fontHeight); - writeString(_fontOrder.getUTF8String(), stream); + writeString(_fontOrder.encode(Common::kUtf8), stream); } stream->writeSint16LE(_fontSpace); } diff --git a/engines/sludge/fonttext.h b/engines/sludge/fonttext.h index 7018c75213a8..260dd3248cd5 100644 --- a/engines/sludge/fonttext.h +++ b/engines/sludge/fonttext.h @@ -26,7 +26,6 @@ #include "common/ustr.h" #include "sludge/sprites.h" -#include "sludge/utf8.h" namespace Sludge { @@ -62,7 +61,7 @@ class TextManager { private: SpriteBank _theFont; int _fontHeight, _numFontColours, _loadedFontNum; - UTF8Converter _fontOrder; + Common::U32String _fontOrder; int16 _fontSpace; SpritePalette _pastePalette; diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp index 453e78f3e554..684e56552509 100644 --- a/engines/sludge/loadsave.cpp +++ b/engines/sludge/loadsave.cpp @@ -45,7 +45,6 @@ #include "sludge/sprites.h" #include "sludge/statusba.h" #include "sludge/speech.h" -#include "sludge/utf8.h" #include "sludge/variable.h" #include "sludge/version.h" #include "sludge/zbuffer.h" diff --git a/engines/sludge/module.mk b/engines/sludge/module.mk index 19435b559df4..ef346f590eaa 100644 --- a/engines/sludge/module.mk +++ b/engines/sludge/module.mk @@ -36,7 +36,6 @@ MODULE_OBJS := \ thumbnail.o \ timing.o \ transition.o \ - utf8.o \ variable.o \ zbuffer.o \ diff --git a/engines/sludge/utf8.cpp b/engines/sludge/utf8.cpp deleted file mode 100644 index bfcaec5ab9c8..000000000000 --- a/engines/sludge/utf8.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ -/* - Basic UTF-8 manipulation routines - by Jeff Bezanson - placed in the public domain Fall 2005 - - This code is designed to provide the utilities you need to manipulate - UTF-8 as an internal string encoding. These functions do not perform the - error checking normally needed when handling UTF-8 data, so if you happen - to be from the Unicode Consortium you will want to flay me alive. - I do this because error checking can be performed at the boundaries (I/O), - with these routines reserved for higher performance on data known to be - valid. - */ - -#include "common/debug.h" - -#include "sludge/utf8.h" - -namespace Sludge { - -const uint32 UTF8Converter::offsetsFromUTF8[6] = { - 0x00000000UL, 0x00003080UL, - 0x000E2080UL, 0x03C82080UL, - 0xFA082080UL, 0x82082080UL }; - -/* reads the next utf-8 sequence out of a string, updating an index */ -uint32 UTF8Converter::nextchar(const char *s, int *i) { - uint32 ch = 0; - int sz = 0; - - do { - ch <<= 6; - ch += (byte)s[(*i)++]; - sz++; - } while (s[*i] && !isutf(s[*i])); - ch -= offsetsFromUTF8[sz - 1]; - - return ch; -} - -Common::U32String UTF8Converter::convertUtf8ToUtf32(const Common::String &str) { - // we assume one character in a Common::String is one byte - // but in this case it's actually an UTF-8 string - // with up to 4 bytes per character. To work around this, - // convert it to an U32String before any further operation - Common::U32String u32str; - int i = 0; - while (i < (int)str.size()) { - uint32 chr = nextchar(str.c_str(), &i); - u32str += chr; - } - return u32str; -} - -/* utf32 index => original byte offset */ -int UTF8Converter::getOriginOffset(int origIdx) { - uint offs = 0; - while (origIdx > 0 && offs < _str.size()) { - // increment if it's not the start of a utf8 sequence - (void)( (++offs < _str.size() && isutf(_str[offs])) || - (++offs < _str.size() && isutf(_str[offs])) || - (++offs < _str.size() && isutf(_str[offs])) || - ++offs); - origIdx--; - } - return offs; -} - -/** Construct a UTF8String with original char array to convert */ -UTF8Converter::UTF8Converter(const char *str) { - setUTF8String(str); -} - -/** set a utf8 string to convert */ -void UTF8Converter::setUTF8String(Common::String str) { - _str32.clear(); - _str32 = convertUtf8ToUtf32(str); - _str.clear(); - _str = str; -} - -} // End of namespace Sludge diff --git a/engines/sludge/utf8.h b/engines/sludge/utf8.h deleted file mode 100644 index 26a2542afc63..000000000000 --- a/engines/sludge/utf8.h +++ /dev/null @@ -1,87 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ -#ifndef SLUDGE_UTF8_H -#define SLUDGE_UTF8_H - -#include "common/system.h" -#include "common/ustr.h" - -namespace Sludge { - -class UTF8Converter { -private: - static const uint32 offsetsFromUTF8[6]; - - /** - * we assume one character in a Common::String is one byte - * but in this case it's actually an UTF-8 string - */ - Common::String _str; - - /** - * wrap a converted U32String - */ - Common::U32String _str32; - - /** A tool function for string conversion - * return next character, updating an index variable - */ - static uint32 nextchar(const char *s, int *i); - - /** A tool function for string conversion - * is this byte the start of a utf8 sequence? - */ - static inline bool isutf(char c) { return (((c)&0xC0)!=0x80); } - -public: - /** Construct a new empty string. */ - UTF8Converter() {}; - - /** Construct a UTF8String with original char array to convert */ - UTF8Converter(const char *data); - - /** U32 character index to origin char offset */ - int getOriginOffset(int origIdx); - - /** - * set a char array to this UTF8String - */ - void setUTF8String(Common::String str); - - /** - * get converted U32String - */ - Common::U32String getU32String() const { return _str32; }; - - /** - * get origin UTF8String - */ - Common::String getUTF8String() const { return _str; }; - - /** Convert UTF8 String to UTF32 String - */ - static Common::U32String convertUtf8ToUtf32(const Common::String &str); -}; - -} // End of namespace Sludge - -#endif