mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-25 21:59:30 +01:00
Simplified the readFromUTF8() prototype
This commit is contained in:
parent
03d93c9360
commit
9e71372c42
6 changed files with 17 additions and 18 deletions
|
@ -158,8 +158,7 @@ void CompDic::loadWordList(const string &iFileName, vector<wstring> &oWordList)
|
||||||
// Ignore empty lines
|
// Ignore empty lines
|
||||||
if (line == "")
|
if (line == "")
|
||||||
continue;
|
continue;
|
||||||
oWordList.push_back(readFromUTF8(line.data(),
|
oWordList.push_back(readFromUTF8(line, "loadWordList"));
|
||||||
line.size(), "loadWordList"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the word list, to perform a better compression
|
// Sort the word list, to perform a better compression
|
||||||
|
|
|
@ -80,8 +80,7 @@ void readLetters(const string &iFileName, CompDic &ioBuilder)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the line to a wstring
|
// Convert the line to a wstring
|
||||||
const wstring &wline =
|
const wstring &wline = readFromUTF8(line, "readLetters (1)");
|
||||||
readFromUTF8(line.c_str(), line.size(), "readLetters (1)");
|
|
||||||
// Split the lines on space characters
|
// Split the lines on space characters
|
||||||
boost::char_separator<wchar_t> sep(L" ");
|
boost::char_separator<wchar_t> sep(L" ");
|
||||||
Tokenizer tok(wline, sep);
|
Tokenizer tok(wline, sep);
|
||||||
|
|
|
@ -312,16 +312,16 @@ unsigned int readFromUTF8(wchar_t *oString, unsigned int iWideSize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wstring readFromUTF8(const char *iBuffer, unsigned int iBufSize,
|
wstring readFromUTF8(const string &iString, const string &iContext)
|
||||||
const string &iContext)
|
|
||||||
{
|
{
|
||||||
|
const int size = iString.size();
|
||||||
// Temporary buffer for output
|
// Temporary buffer for output
|
||||||
// We will have at most as many characters as in the UTF-8 string
|
// 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;
|
unsigned int number;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
number = readFromUTF8(wideBuf, iBufSize, iBuffer, iBufSize, iContext);
|
number = readFromUTF8(wideBuf, size, iString.data(), size, iContext);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
|
|
@ -101,13 +101,11 @@ unsigned int readFromUTF8(wchar_t *oString, unsigned int iWideSize,
|
||||||
* Same as the other readFromUTF8 function, dealing with a wstring
|
* Same as the other readFromUTF8 function, dealing with a wstring
|
||||||
* instead of a wchar_t*. Note that it performs an additional copy
|
* instead of a wchar_t*. Note that it performs an additional copy
|
||||||
* of the output string...
|
* of the output string...
|
||||||
* @param iBuffer: UTF-8 string to convert
|
* @param iString: UTF-8 string to convert
|
||||||
* @param iBufSize: available size in iBuffer
|
|
||||||
* @param iContext: free text used in case of exception
|
* @param iContext: free text used in case of exception
|
||||||
* @return: the converted wide string
|
* @return: the converted wide string
|
||||||
*/
|
*/
|
||||||
wstring readFromUTF8(const char *iBuffer, unsigned int iBufSize,
|
wstring readFromUTF8(const string &iString, const string &iContext);
|
||||||
const string &iContext);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility function to convert a wstring into an UTF-8 char* buffer
|
* Utility function to convert a wstring into an UTF-8 char* buffer
|
||||||
|
|
|
@ -406,15 +406,18 @@ void Header::read(istream &iStream)
|
||||||
else
|
else
|
||||||
throw DicException("Header::read: unrecognized algorithm type");
|
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");
|
"user and host information");
|
||||||
|
|
||||||
// Convert the dictionary letters from UTF-8 to wchar_t*
|
// 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");
|
"dictionary name");
|
||||||
|
|
||||||
// Convert the dictionary letters from UTF-8 to wchar_t*
|
// 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");
|
"dictionary letters");
|
||||||
// Safety check: correct number of letters?
|
// Safety check: correct number of letters?
|
||||||
if (m_letters.size() != aHeaderExt.nbLetters)
|
if (m_letters.size() != aHeaderExt.nbLetters)
|
||||||
|
@ -449,8 +452,8 @@ void Header::read(istream &iStream)
|
||||||
aHeaderExt2.displayAndInputSize = ntohs(aHeaderExt2.displayAndInputSize);
|
aHeaderExt2.displayAndInputSize = ntohs(aHeaderExt2.displayAndInputSize);
|
||||||
|
|
||||||
// Convert the dictionary letters from UTF-8 to wchar_t*
|
// Convert the dictionary letters from UTF-8 to wchar_t*
|
||||||
wstring serialized = readFromUTF8(aHeaderExt2.displayAndInput,
|
wstring serialized = readFromUTF8(string(aHeaderExt2.displayAndInput,
|
||||||
aHeaderExt2.displayAndInputSize,
|
aHeaderExt2.displayAndInputSize),
|
||||||
"display and input data");
|
"display and input data");
|
||||||
// Parse this string and structure the data
|
// Parse this string and structure the data
|
||||||
readDisplayAndInput(serialized);
|
readDisplayAndInput(serialized);
|
||||||
|
|
|
@ -98,7 +98,7 @@ Game * XmlReader::read(const string &iFileName, const Dictionary &iDic)
|
||||||
|
|
||||||
static wstring fromUtf8(const string &str)
|
static wstring fromUtf8(const string &str)
|
||||||
{
|
{
|
||||||
return readFromUTF8(str.c_str(), str.size(), "Loading game");
|
return readFromUTF8(str, "Loading game");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue