eliot-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Eliot-dev] eliot dic/compdic.cpp dic/compdicmain.cpp dic/e...


From: Olivier Teulière
Subject: [Eliot-dev] eliot dic/compdic.cpp dic/compdicmain.cpp dic/e...
Date: Sat, 30 Jul 2011 19:46:47 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>       11/07/30 19:46:47

Modified files:
        dic            : compdic.cpp compdicmain.cpp encoding.cpp 
                         encoding.h header.cpp 
        game           : xml_reader.cpp 

Log message:
        Simplified the readFromUTF8() prototype

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/compdic.cpp?cvsroot=eliot&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/compdicmain.cpp?cvsroot=eliot&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/encoding.cpp?cvsroot=eliot&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/encoding.h?cvsroot=eliot&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/header.cpp?cvsroot=eliot&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/eliot/game/xml_reader.cpp?cvsroot=eliot&r1=1.3&r2=1.4

Patches:
Index: dic/compdic.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/compdic.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- dic/compdic.cpp     29 Jan 2011 23:47:20 -0000      1.23
+++ dic/compdic.cpp     30 Jul 2011 19:46:47 -0000      1.24
@@ -158,8 +158,7 @@
         // 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

Index: dic/compdicmain.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/compdicmain.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- dic/compdicmain.cpp 16 Jul 2011 21:13:42 -0000      1.4
+++ dic/compdicmain.cpp 30 Jul 2011 19:46:47 -0000      1.5
@@ -80,8 +80,7 @@
         }
 
         // 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);

Index: dic/encoding.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/encoding.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- dic/encoding.cpp    30 Jul 2011 19:44:18 -0000      1.17
+++ dic/encoding.cpp    30 Jul 2011 19:46:47 -0000      1.18
@@ -312,16 +312,16 @@
 }
 
 
-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 (...)
     {

Index: dic/encoding.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/encoding.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- dic/encoding.h      20 May 2010 20:27:47 -0000      1.6
+++ dic/encoding.h      30 Jul 2011 19:46:47 -0000      1.7
@@ -101,13 +101,11 @@
  * 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

Index: dic/header.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/header.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- dic/header.cpp      2 Jan 2010 12:44:56 -0000       1.16
+++ dic/header.cpp      30 Jul 2011 19:46:47 -0000      1.17
@@ -406,15 +406,18 @@
     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 @@
         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);

Index: game/xml_reader.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/xml_reader.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- game/xml_reader.cpp 29 Jan 2011 23:47:21 -0000      1.3
+++ game/xml_reader.cpp 30 Jul 2011 19:46:47 -0000      1.4
@@ -98,7 +98,7 @@
 
 static wstring fromUtf8(const string &str)
 {
-    return readFromUTF8(str.c_str(), str.size(), "Loading game");
+    return readFromUTF8(str, "Loading game");
 }
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]