[gnote] Added "search for phrases"
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Added "search for phrases"
- Date: Wed, 17 Feb 2010 21:42:17 +0000 (UTC)
commit 34fa546e51585ca1cbd5c4a24905fd3dab6e35a8
Author: Debarshi Ray <debarshir src gnome org>
Date: Wed Feb 17 23:36:22 2010 +0200
Added "search for phrases"
Fixes: https://bugzilla.gnome.org/551097
src/notewindow.cpp | 3 ++-
src/search.cpp | 4 ++--
src/search.hpp | 38 ++++++++++++++++++++++++++++++++++++++
src/sharp/string.cpp | 6 ------
src/sharp/string.hpp | 2 --
5 files changed, 42 insertions(+), 11 deletions(-)
---
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index d45c5b2..c317c87 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -38,6 +38,7 @@
#include "utils.hpp"
#include "undo.hpp"
#include "recentchanges.hpp"
+#include "search.hpp"
#include "actionmanager.hpp"
#include "sharp/exception.hpp"
#include "sharp/string.hpp"
@@ -834,7 +835,7 @@ namespace gnote {
text = text.lowercase();
std::vector<Glib::ustring> words;
- sharp::ustring_split(words, text, " \t\n");
+ Search::split_watching_quotes(words, text);
find_matches_in_buffer(m_note.get_buffer(), words, m_current_matches);
diff --git a/src/search.cpp b/src/search.cpp
index 0511447..d8c380d 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -39,11 +39,11 @@ namespace gnote {
const notebooks::Notebook::Ptr & selected_notebook)
{
std::vector<std::string> words;
- sharp::string_split(words, query, " \t\n");
+ Search::split_watching_quotes(words, query);
// Used for matching in the raw note XML
std::vector<std::string> encoded_words;
- sharp::string_split(encoded_words, utils::XmlEncoder::encode (query), " \t\n");
+ Search::split_watching_quotes(encoded_words, utils::XmlEncoder::encode (query));
ResultsPtr temp_matches(new Results);
// Skip over notes that are template notes
diff --git a/src/search.hpp b/src/search.hpp
index 0cea0df..8ae741a 100644
--- a/src/search.hpp
+++ b/src/search.hpp
@@ -25,6 +25,10 @@
#include <map>
#include <memory>
#include <string>
+#include <vector>
+
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/split.hpp>
#include "note.hpp"
#include "notebooks/notebook.hpp"
@@ -39,6 +43,10 @@ public:
typedef std::map<Note::Ptr,int> Results;
typedef std::tr1::shared_ptr<Results> ResultsPtr;
+ template<typename T>
+ static void split_watching_quotes(std::vector<T> & split,
+ const T & source);
+
Search(NoteManager &);
@@ -70,6 +78,36 @@ private:
NoteManager &m_manager;
};
+template<typename T>
+void Search::split_watching_quotes(std::vector<T> & split,
+ const T & source)
+{
+ boost::split(split, source, boost::is_any_of("\""));
+
+ std::vector<T> tmp;
+
+ for (typename std::vector<T>::iterator i = split.begin();
+ split.end() != i;
+ i++) {
+ const T & part = *i;
+ std::vector<T> parts;
+ boost::split(parts, part, boost::is_any_of(" \t\n"));
+
+ for (typename std::vector<T>::const_iterator j = parts.begin();
+ parts.end() != j;
+ j++) {
+ const T & s = *j;
+ if (!s.empty())
+ tmp.push_back(s);
+ }
+
+ i = split.erase(i);
+ if (split.end() == i)
+ break;
+ }
+
+ split.insert(split.end(), tmp.begin(), tmp.end());
+}
}
diff --git a/src/sharp/string.cpp b/src/sharp/string.cpp
index ba679a8..0066667 100644
--- a/src/sharp/string.cpp
+++ b/src/sharp/string.cpp
@@ -76,12 +76,6 @@ namespace sharp {
boost::split(split, source, boost::is_any_of(delimiters));
}
- void ustring_split(std::vector<Glib::ustring> & split, const Glib::ustring & source,
- const char * delimiters)
- {
- boost::split(split, source, boost::is_any_of(delimiters));
- }
-
std::string string_substring(const std::string & source, int start)
{
DBG_ASSERT(start >= 0, "start can't be negative");
diff --git a/src/sharp/string.hpp b/src/sharp/string.hpp
index 89aed99..4ef6f22 100644
--- a/src/sharp/string.hpp
+++ b/src/sharp/string.hpp
@@ -56,8 +56,6 @@ namespace sharp {
void string_split(std::vector<std::string> & split, const std::string & source,
const char * delimiters);
- void ustring_split(std::vector<Glib::ustring> & split, const Glib::ustring & source,
- const char * delimiters);
/** copy the substring for %source, starting at %start until the end */
std::string string_substring(const std::string & source, int start);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]