Simplified the readFromUTF8() prototype

This commit is contained in:
Olivier Teulière 2011-07-30 19:46:47 +00:00
parent 03d93c9360
commit 9e71372c42
6 changed files with 17 additions and 18 deletions

View file

@ -158,8 +158,7 @@ void CompDic::loadWordList(const string &iFileName, vector<wstring> &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

View file

@ -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<wchar_t> sep(L" ");
Tokenizer tok(wline, sep);

View file

@ -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 (...)
{

View file

@ -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

View file

@ -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);

View file

@ -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");
}