[gnote/stable-0.6] Make TrieTree::add_keyword, TrieTree::find_matches Unicode aware
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote/stable-0.6] Make TrieTree::add_keyword, TrieTree::find_matches Unicode aware
- Date: Mon, 22 Mar 2010 15:50:22 +0000 (UTC)
commit 8f743a22908cfc2a69e89ee3d0166e291fb71ac7
Author: Aurimas Ä?ernius <aurisc4 gmail com>
Date: Fri Mar 12 19:53:14 2010 +0200
Make TrieTree::add_keyword, TrieTree::find_matches Unicode aware
Fixes: https://bugzilla.gnome.org/588537
Fixes: https://bugzilla.gnome.org/606022
Signed-off-by: Debarshi Ray <debarshir src gnome org>
(cherry picked from commit c5ed58df6fc690a3881aa495ce6a243ed65eeb5c)
src/test/trietest.cpp | 5 +++--
src/trie.hpp | 18 +++++++++---------
2 files changed, 12 insertions(+), 11 deletions(-)
---
diff --git a/src/test/trietest.cpp b/src/test/trietest.cpp
index 0435207..195e30b 100644
--- a/src/test/trietest.cpp
+++ b/src/test/trietest.cpp
@@ -9,7 +9,7 @@
int test_main(int /*argc*/, char ** /*argv*/)
{
- std::string src = "bazar this is some foo, bar, and baz bazbarfoofoo bazbazarbaz end bazar";
+ std::string src = "bazar this is some foo, bar, and baz BazBarFooFoo bazbazarbaz end bazar Ä?Ä?Ä?Ä?įŠųŪž";
printf("Searching in '%s':\n", src.c_str());
gnote::TrieTree<std::string> trie(false);
@@ -17,12 +17,13 @@ int test_main(int /*argc*/, char ** /*argv*/)
trie.add_keyword ("bar", "bar");
trie.add_keyword ("baz", "baz");
trie.add_keyword ("bazar", "bazar");
+ trie.add_keyword ("Ä?Ä?Ä?Ä?įšųūž", "Ä?Ä?Ä?Ä?įšųūž");
printf ("Starting search...\n");
gnote::TrieTree<std::string>::HitListPtr matches(trie.find_matches (src));
BOOST_CHECK( matches.get() );
- BOOST_CHECK( matches->size() == 15 );
+ BOOST_CHECK( matches->size() == 16 );
gnote::TrieTree<std::string>::HitList::const_iterator iter = matches->begin();
BOOST_CHECK( *iter );
diff --git a/src/trie.hpp b/src/trie.hpp
index 319ecea..f457ce4 100644
--- a/src/trie.hpp
+++ b/src/trie.hpp
@@ -67,7 +67,7 @@ namespace gnote {
}
TrieMatchPtr next;
TrieStatePtr state;
- char value;
+ gunichar value;
};
public:
@@ -90,7 +90,7 @@ namespace gnote {
}
private:
- TrieStatePtr insert_match_at_state(size_t depth, const TrieStatePtr & q, char c)
+ TrieStatePtr insert_match_at_state(size_t depth, const TrieStatePtr & q, gunichar c)
{
// Create a new state with a failure at %root
TrieStatePtr new_q(new TrieState ());
@@ -120,7 +120,7 @@ namespace gnote {
// Iterate the matches at state %s looking for the first match
// containing %c.
- TrieMatchPtr find_match_at_state (const TrieStatePtr & s, char c) const
+ TrieMatchPtr find_match_at_state (const TrieStatePtr & s, gunichar c) const
{
TrieMatchPtr m = s->first_match;
@@ -144,7 +144,7 @@ namespace gnote {
* final = union(final, q)
* ENDFOR
*/
- void add_keyword(const std::string & needle, const value_t & pattern_id)
+ void add_keyword(const Glib::ustring & needle, const value_t & pattern_id)
{
TrieStatePtr q = m_root;
int depth = 0;
@@ -152,9 +152,9 @@ namespace gnote {
// Step 1: add the pattern to the trie...
for (size_t idx = 0; idx < needle.size(); idx++) {
- char c = needle [idx];
+ gunichar c = needle [idx];
if (!m_case_sensitive)
- c = ::tolower(c);
+ c = g_unichar_tolower(c);
TrieMatchPtr m = find_match_at_state (q, c);
if (m == NULL) {
@@ -235,16 +235,16 @@ namespace gnote {
* ENDFOR
* RETURN FALSE
*/
- HitListPtr find_matches(const std::string & haystack)
+ HitListPtr find_matches(const Glib::ustring & haystack)
{
HitListPtr matches(new HitList());
TrieStatePtr q = m_root;
TrieMatchPtr m;
size_t idx = 0, start_idx = 0, last_idx = 0;
while (idx < haystack.size()) {
- char c = haystack [idx++];
+ gunichar c = haystack [idx++];
if (!m_case_sensitive)
- c = ::tolower (c);
+ c = g_unichar_tolower(c);
while (q) {
m = find_match_at_state (q, c);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]