diff options
author | Peng Huang <shawn.p.huang@gmail.com> | 2010-04-15 12:09:35 +0800 |
---|---|---|
committer | Peng Huang <shawn.p.huang@gmail.com> | 2010-04-15 12:09:35 +0800 |
commit | 593375cfeaee95ff25778c06c784900a95301ec0 (patch) | |
tree | 5f12a073a7eacaa8ba338b612efa203b3ac7cda5 /src/SpecialPhraseTable.cc | |
parent | 3543873912a94b38853769c4bb9c81264a54337b (diff) | |
download | ibus-libpinyin-593375cfeaee95ff25778c06c784900a95301ec0.tar.gz ibus-libpinyin-593375cfeaee95ff25778c06c784900a95301ec0.tar.xz ibus-libpinyin-593375cfeaee95ff25778c06c784900a95301ec0.zip |
Add clear of SpecialPhraseTable
Diffstat (limited to 'src/SpecialPhraseTable.cc')
-rw-r--r-- | src/SpecialPhraseTable.cc | 80 |
1 files changed, 49 insertions, 31 deletions
diff --git a/src/SpecialPhraseTable.cc b/src/SpecialPhraseTable.cc index 7b98bf1..28ade93 100644 --- a/src/SpecialPhraseTable.cc +++ b/src/SpecialPhraseTable.cc @@ -12,6 +12,7 @@ class StaticSpecialPhrase : public SpecialPhrase { public: StaticSpecialPhrase (const std::string &text, guint pos) : SpecialPhrase (pos), m_text (text) { } + ~StaticSpecialPhrase (void) { } std::string text (void) { return m_text; } @@ -30,37 +31,6 @@ SpecialPhraseTable::SpecialPhraseTable (void) g_free (path); } -gboolean -SpecialPhraseTable::load (const gchar *file) -{ - std::ifstream in (file); - if (in.fail ()) - return FALSE; - - std::string line; - while (!in.eof ()) { - getline (in, line); - if (line.size () == 0 || line[0] == ';') - continue; - size_t pos = line.find ('='); - if (pos == line.npos) - continue; - - std::string command = line.substr(0, pos); - std::string phrase = line.substr(pos + 1); - if (command.empty () || phrase.empty ()) - continue; - - if (phrase[0] != '#') { - insert (command, new StaticSpecialPhrase (phrase, 0)); - } - else if (phrase.size () > 1) { - insert (command, new DynamicSpecialPhrase (phrase.substr (1), 0)); - } - } - return TRUE; -} - #if 0 static bool phraseCmp (const SpecialPhrase *first, @@ -101,5 +71,53 @@ SpecialPhraseTable::lookup (const std::string &command, return result.size () > 0; } +gboolean +SpecialPhraseTable::load (const gchar *file) +{ + clear (); + + std::ifstream in (file); + if (in.fail ()) + return FALSE; + + std::string line; + while (!in.eof ()) { + getline (in, line); + if (line.size () == 0 || line[0] == ';') + continue; + size_t pos = line.find ('='); + if (pos == line.npos) + continue; + + std::string command = line.substr(0, pos); + std::string phrase = line.substr(pos + 1); + if (command.empty () || phrase.empty ()) + continue; + + if (phrase[0] != '#') { + insert (command, new StaticSpecialPhrase (phrase, 0)); + } + else if (phrase.size () > 1) { + insert (command, new DynamicSpecialPhrase (phrase.substr (1), 0)); + } + } + return TRUE; +} + +void +SpecialPhraseTable::clear (void) +{ + Map::iterator it; + + for (it = m_map.begin (); it != m_map.end (); it ++) { + std::list<SpecialPhrase *>::iterator pit; + for (pit = (*it).second.begin (); pit != (*it).second.end (); pit ++) { + delete *pit; + } + } + + m_map.clear (); +} + }; |