eliot-dev
[Top][All Lists]
Advanced

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

[Eliot-dev] eliot/dic dic_search.cpp header.cpp header.h


From: Olivier Teulière
Subject: [Eliot-dev] eliot/dic dic_search.cpp header.cpp header.h
Date: Tue, 23 Jun 2009 15:36:28 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>       09/06/23 15:36:28

Modified files:
        dic            : dic_search.cpp header.cpp header.h 

Log message:
        Little refactoring

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic_search.cpp?cvsroot=eliot&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/header.cpp?cvsroot=eliot&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/header.h?cvsroot=eliot&r1=1.5&r2=1.6

Patches:
Index: dic_search.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/dic_search.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- dic_search.cpp      23 Jun 2009 12:41:53 -0000      1.14
+++ dic_search.cpp      23 Jun 2009 15:36:28 -0000      1.15
@@ -83,19 +83,6 @@
     char search_letters[63];
 };
 
-wdstring convertToDisplay(const Header &iHeader, const wstring &iWord)
-{
-    wdstring dispStr;
-    dispStr.reserve(iWord.size());
-    for (unsigned int i = 0; i < iWord.size(); ++i)
-    {
-        const wdstring &chr =
-            iHeader.getDisplayStr(iHeader.getCodeFromChar(iWord[i]));
-        dispStr += chr;
-    }
-    return dispStr;
-}
-
 void Dictionary::searchWordByLen(struct params_7plus1_t &params,
                                  int i, const DicEdge *edgeptr) const
 {
@@ -117,7 +104,7 @@
                         // Add the solution
                         vector<wdstring> &sols = 
(*params.results)[params.added_display];
                         if (sols.empty() || sols.back() != 
params.search_wordtst)
-                            sols.push_back(convertToDisplay(getHeader(), 
params.search_wordtst));
+                            
sols.push_back(getHeader().convertToDisplay(params.search_wordtst));
                     }
                 }
                 else
@@ -140,7 +127,7 @@
                         // Add the solution
                         vector<wdstring> &sols = 
(*params.results)[params.added_display];
                         if (sols.empty() || sols.back() != 
params.search_wordtst)
-                            sols.push_back(convertToDisplay(getHeader(), 
params.search_wordtst));
+                            
sols.push_back(getHeader().convertToDisplay(params.search_wordtst));
                     }
                 }
                 else
@@ -243,7 +230,7 @@
         oWordList.reserve(DEFAULT_VECT_ALLOC);
 
     // Transform the given word to make it suitable for display
-    const wdstring &displayWord = convertToDisplay(getHeader(), iWord);
+    const wdstring &displayWord = getHeader().convertToDisplay(iWord);
 
     // Try to add a letter at the front
     const wstring &letters = getHeader().getLetters();
@@ -296,7 +283,7 @@
         oWordList.reserve(DEFAULT_VECT_ALLOC);
 
     // Transform the given word to make it suitable for display
-    const wdstring &displayWord = convertToDisplay(getHeader(), iWord);
+    const wdstring &displayWord = getHeader().convertToDisplay(iWord);
 
     const DicEdge *edge0, *edge1, *edge2, *edgetst;
     edge0 = getEdgeAt(getRoot());

Index: header.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/header.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- header.cpp  23 Jun 2009 12:41:53 -0000      1.7
+++ header.cpp  23 Jun 2009 15:36:28 -0000      1.8
@@ -273,6 +273,23 @@
 }
 
 
+wdstring Header::convertToDisplay(const wstring &iWord) const
+{
+    // TODO: if we had a flag saying that the current dictionary is
+    // such that all the display strings are equal to the internal
+    // characters themselves (which would be the case for most languages),
+    // we could simply return the given string without further processing.
+    wdstring dispStr;
+    dispStr.reserve(iWord.size());
+    for (unsigned int i = 0; i < iWord.size(); ++i)
+    {
+        const wdstring &chr = getDisplayStr(getCodeFromChar(iWord[i]));
+        dispStr += chr;
+    }
+    return dispStr;
+}
+
+
 void Header::read(istream &iStream)
 {
     Dict_header_old aHeader;

Index: header.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/header.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- header.h    23 Jun 2009 12:41:53 -0000      1.5
+++ header.h    23 Jun 2009 15:36:28 -0000      1.6
@@ -28,6 +28,9 @@
 
 using namespace std;
 
+// XXX: duplicated typedef (also present in dic.h)
+typedef wstring wdstring;
+
 
 /**
  * Structure used to create a Header object.
@@ -122,11 +125,17 @@
     unsigned int getCodeFromChar(wchar_t iChar) const;
 
     /**
-     * Return the display stirng corresponding to the given code
+     * Return the display string corresponding to the given code
      */
     wstring getDisplayStr(unsigned int iCode) const;
 
     /**
+     * Convert the given string (made of internal characters)
+     * into a string suitable for display
+     */
+    wdstring convertToDisplay(const wstring &iWord) const;
+
+    /**
      * Print a readable summary of the header on standard output
      */
     void print() const;




reply via email to

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