Refactory PinyinParser
authorPeng Huang <shawn.p.huang@gmail.com>
Tue, 13 Apr 2010 13:21:49 +0000 (21:21 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Tue, 13 Apr 2010 13:21:49 +0000 (21:21 +0800)
src/DoublePinyinEditor.cc
src/DoublePinyinEditor.h
src/FullPinyinEditor.cc
src/FullPinyinEditor.h
src/PinyinEditor.cc
src/PinyinEditor.h
src/PinyinParser.h

index 7280bb5..036b960 100644 (file)
@@ -314,7 +314,7 @@ DoublePinyinEditor::isPinyin (gint i)
         return NULL;
     }
 
-    return m_parser.isPinyin (sheng, 0, PINYIN_INCOMPLETE_PINYIN);
+    return PinyinParser::isPinyin (sheng, 0, PINYIN_INCOMPLETE_PINYIN);
 }
 
 inline const Pinyin *
@@ -330,10 +330,10 @@ DoublePinyinEditor::isPinyin (gint i, gint j)
     if (sheng == PINYIN_ID_ZERO && yun[0] == PINYIN_ID_ZERO)
         return pinyin;
 
-    pinyin = m_parser.isPinyin (sheng, yun[0],
+    pinyin = PinyinParser::isPinyin (sheng, yun[0],
                         Config::option () & PINYIN_FUZZY_ALL);
     if (pinyin == NULL && yun[1] != PINYIN_ID_VOID)
-        pinyin = m_parser.isPinyin (sheng, yun[1],
+        pinyin = PinyinParser::isPinyin (sheng, yun[1],
                         Config::option () & PINYIN_FUZZY_ALL);
     return pinyin;
 }
index c3ce400..b73a229 100644 (file)
@@ -29,8 +29,10 @@ public:
     void reset (void);
     void updateAuxiliaryTextAfter (String &buffer);
 
-private:
+protected:
     gboolean updatePinyin (gboolean all);
+
+private:
     const Pinyin *isPinyin (gint i, gint j);
     const Pinyin *isPinyin (gint i);
 
index 432dc0b..74cb4c9 100644 (file)
@@ -207,11 +207,11 @@ FullPinyinEditor::updatePinyin (void)
         m_pinyin_len = 0;
     }
     else {
-        m_pinyin_len = m_parser.parse (m_text,              // text
-                                       m_cursor,            // text length
-                                       Config::option (),   // option
-                                       m_pinyin,            // result
-                                       MAX_PHRASE_LEN);     // max result length
+        m_pinyin_len = PinyinParser::parse (m_text,              // text
+                                            m_cursor,            // text length
+                                            Config::option (),   // option
+                                            m_pinyin,            // result
+                                            MAX_PHRASE_LEN);     // max result length
     }
 
     updatePhraseEditor ();
index 9e95fa8..22b6966 100644 (file)
@@ -33,7 +33,6 @@ protected:
     gboolean moveCursorToBegin (void);
     gboolean moveCursorToEnd (void);
 
-private:
     void updatePinyin (void);
 
 };
index e05110e..f018704 100644 (file)
@@ -8,8 +8,6 @@ namespace PY {
 #define MAX_PINYIN_LEN 64
 
 /* init static members */
-PinyinParser PinyinEditor::m_parser;
-
 PinyinEditor::PinyinEditor (PinyinProperties & props)
     : Editor (props),
       m_pinyin (MAX_PHRASE_LEN),
index d237fd6..76bfe12 100644 (file)
@@ -105,9 +105,6 @@ protected:
     PhraseEditor m_phrase_editor;
     std::vector<std::string> m_special_phrases;
     std::string m_selected_special_phrase;
-
-protected:
-    static PinyinParser m_parser;
 };
 };
 
index c9ad552..e27f24b 100644 (file)
@@ -9,18 +9,13 @@
 namespace PY {
 
 class PinyinParser {
-
 public:
-    PinyinParser (void) {}
-    ~PinyinParser (void) {}
-
-    guint parse (const String &pinyin,      // pinyin string
-                 gint          len,         // length of pinyin string
-                 guint         option,      // option
-                 PinyinArray  &result,      // store pinyin in result
-                 guint         max);        // max length of the result
-    const Pinyin * isPinyin (gint sheng, gint yun, guint option);
+    static guint parse (const String &pinyin,      // pinyin string
+                        gint          len,         // length of pinyin string
+                        guint         option,      // option
+                        PinyinArray  &result,      // store pinyin in result
+                        guint         max);        // max length of the result
+    static const Pinyin * isPinyin (gint sheng, gint yun, guint option);
 };
-
 };
 #endif