diff --git a/dic/compdic.cpp b/dic/compdic.cpp index d8233c2..f2bb73a 100644 --- a/dic/compdic.cpp +++ b/dic/compdic.cpp @@ -158,8 +158,7 @@ void CompDic::loadWordList(const string &iFileName, vector &oWordList) // Ignore empty lines if (line == "") continue; - oWordList.push_back(readFromUTF8(line.data(), - line.size(), "loadWordList")); + oWordList.push_back(readFromUTF8(line, "loadWordList")); } // Sort the word list, to perform a better compression diff --git a/dic/compdicmain.cpp b/dic/compdicmain.cpp index 696c2a5..991b300 100644 --- a/dic/compdicmain.cpp +++ b/dic/compdicmain.cpp @@ -80,8 +80,7 @@ void readLetters(const string &iFileName, CompDic &ioBuilder) } // Convert the line to a wstring - const wstring &wline = - readFromUTF8(line.c_str(), line.size(), "readLetters (1)"); + const wstring &wline = readFromUTF8(line, "readLetters (1)"); // Split the lines on space characters boost::char_separator sep(L" "); Tokenizer tok(wline, sep); diff --git a/dic/encoding.cpp b/dic/encoding.cpp index ba8fecd..8ad04f5 100644 --- a/dic/encoding.cpp +++ b/dic/encoding.cpp @@ -312,16 +312,16 @@ unsigned int readFromUTF8(wchar_t *oString, unsigned int iWideSize, } -wstring readFromUTF8(const char *iBuffer, unsigned int iBufSize, - const string &iContext) +wstring readFromUTF8(const string &iString, const string &iContext) { + const int size = iString.size(); // Temporary buffer for output // We will have at most as many characters as in the UTF-8 string - wchar_t *wideBuf = new wchar_t[iBufSize]; + wchar_t *wideBuf = new wchar_t[size]; unsigned int number; try { - number = readFromUTF8(wideBuf, iBufSize, iBuffer, iBufSize, iContext); + number = readFromUTF8(wideBuf, size, iString.data(), size, iContext); } catch (...) { diff --git a/dic/encoding.h b/dic/encoding.h index 50806cb..2b872cb 100644 --- a/dic/encoding.h +++ b/dic/encoding.h @@ -101,13 +101,11 @@ unsigned int readFromUTF8(wchar_t *oString, unsigned int iWideSize, * Same as the other readFromUTF8 function, dealing with a wstring * instead of a wchar_t*. Note that it performs an additional copy * of the output string... - * @param iBuffer: UTF-8 string to convert - * @param iBufSize: available size in iBuffer + * @param iString: UTF-8 string to convert * @param iContext: free text used in case of exception * @return: the converted wide string */ -wstring readFromUTF8(const char *iBuffer, unsigned int iBufSize, - const string &iContext); +wstring readFromUTF8(const string &iString, const string &iContext); /** * Utility function to convert a wstring into an UTF-8 char* buffer diff --git a/dic/header.cpp b/dic/header.cpp index 45752ca..9c7fdeb 100644 --- a/dic/header.cpp +++ b/dic/header.cpp @@ -406,15 +406,18 @@ void Header::read(istream &iStream) else throw DicException("Header::read: unrecognized algorithm type"); - m_userHost = readFromUTF8(aHeaderExt.userHost, aHeaderExt.userHostSize, + m_userHost = readFromUTF8(string(aHeaderExt.userHost, + aHeaderExt.userHostSize), "user and host information"); // Convert the dictionary letters from UTF-8 to wchar_t* - m_dicName = readFromUTF8(aHeaderExt.dicName, aHeaderExt.dicNameSize, + m_dicName = readFromUTF8(string(aHeaderExt.dicName, + aHeaderExt.dicNameSize), "dictionary name"); // Convert the dictionary letters from UTF-8 to wchar_t* - m_letters = readFromUTF8(aHeaderExt.letters, aHeaderExt.lettersSize, + m_letters = readFromUTF8(string(aHeaderExt.letters, + aHeaderExt.lettersSize), "dictionary letters"); // Safety check: correct number of letters? if (m_letters.size() != aHeaderExt.nbLetters) @@ -449,8 +452,8 @@ void Header::read(istream &iStream) aHeaderExt2.displayAndInputSize = ntohs(aHeaderExt2.displayAndInputSize); // Convert the dictionary letters from UTF-8 to wchar_t* - wstring serialized = readFromUTF8(aHeaderExt2.displayAndInput, - aHeaderExt2.displayAndInputSize, + wstring serialized = readFromUTF8(string(aHeaderExt2.displayAndInput, + aHeaderExt2.displayAndInputSize), "display and input data"); // Parse this string and structure the data readDisplayAndInput(serialized); diff --git a/game/xml_reader.cpp b/game/xml_reader.cpp index 5fdc66b..aaf6bab 100644 --- a/game/xml_reader.cpp +++ b/game/xml_reader.cpp @@ -98,7 +98,7 @@ Game * XmlReader::read(const string &iFileName, const Dictionary &iDic) static wstring fromUtf8(const string &str) { - return readFromUTF8(str.c_str(), str.size(), "Loading game"); + return readFromUTF8(str, "Loading game"); }