diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-09 19:16:02 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-09 19:16:02 +0000 |
commit | 7de99596feecaa24900a082a721ef8d4f57b47ee (patch) | |
tree | bee4f2c6846d15bac3880e756edc22d6c2671182 /chrome/browser/history/query_parser.cc | |
parent | 9a2e76b4ed08763e9bbecff875ad1a06a9e39f69 (diff) | |
download | chromium_src-7de99596feecaa24900a082a721ef8d4f57b47ee.zip chromium_src-7de99596feecaa24900a082a721ef8d4f57b47ee.tar.gz chromium_src-7de99596feecaa24900a082a721ef8d4f57b47ee.tar.bz2 |
Adds QueryParser::ExtractQueryWords. For consistent this should
probably be ParseQuery, but I couldn't bring myself to another
ParseQuery method. I'm going to need this for bookmark queries.
BUG=4065
TEST=none
Review URL: http://codereview.chromium.org/13296
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6604 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history/query_parser.cc')
-rw-r--r-- | chrome/browser/history/query_parser.cc | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/chrome/browser/history/query_parser.cc b/chrome/browser/history/query_parser.cc index ef40601..3ebaad9 100644 --- a/chrome/browser/history/query_parser.cc +++ b/chrome/browser/history/query_parser.cc @@ -97,6 +97,7 @@ class QueryNodeWord : public QueryNode { Snippet::MatchPositions* match_positions) const; virtual bool Matches(const std::wstring& word, bool exact) const; + virtual void AppendWords(std::vector<std::wstring>* words) const; private: std::wstring word_; @@ -124,6 +125,10 @@ bool QueryNodeWord::Matches(const std::wstring& word, bool exact) const { (word_.compare(0, word_.size(), word, 0, word_.size()) == 0); } +void QueryNodeWord::AppendWords(std::vector<std::wstring>* words) const { + words->push_back(word_); +} + int QueryNodeWord::AppendToSQLiteQuery(std::wstring* query) const { query->append(word_); @@ -162,6 +167,7 @@ class QueryNodeList : public QueryNode { NOTREACHED(); return false; } + virtual void AppendWords(std::vector<std::wstring>* words) const; protected: int AppendChildrenToString(std::wstring* query) const; @@ -175,6 +181,26 @@ QueryNodeList::~QueryNodeList() { delete *node; } +void QueryNodeList::RemoveEmptySubnodes() { + for (size_t i = 0; i < children_.size(); ++i) { + if (children_[i]->IsWord()) + continue; + + QueryNodeList* list_node = static_cast<QueryNodeList*>(children_[i]); + list_node->RemoveEmptySubnodes(); + if (list_node->children()->empty()) { + children_.erase(children_.begin() + i); + --i; + delete list_node; + } + } +} + +void QueryNodeList::AppendWords(std::vector<std::wstring>* words) const { + for (size_t i = 0; i < children_.size(); ++i) + children_[i]->AppendWords(words); +} + int QueryNodeList::AppendChildrenToString(std::wstring* query) const { int num_words = 0; for (QueryNodeVector::const_iterator node = children_.begin(); @@ -259,6 +285,15 @@ void QueryParser::ParseQuery(const std::wstring& query, nodes->swap(*root.children()); } + +void QueryParser::ExtractQueryWords(const std::wstring& query, + std::vector<std::wstring>* words) { + QueryNodeList root; + if (!ParseQueryImpl(query, &root)) + return; + root.AppendWords(words); +} + bool QueryParser::DoesQueryMatch(const std::wstring& text, const std::vector<QueryNode*>& query_nodes, Snippet::MatchPositions* match_positions) { @@ -345,18 +380,3 @@ void QueryParser::ExtractQueryWords(const std::wstring& text, } } } - -void QueryNodeList::RemoveEmptySubnodes() { - for (size_t i = 0; i < children_.size(); ++i) { - if (children_[i]->IsWord()) - continue; - - QueryNodeList* list_node = static_cast<QueryNodeList*>(children_[i]); - list_node->RemoveEmptySubnodes(); - if (list_node->children()->empty()) { - children_.erase(children_.begin() + i); - --i; - delete list_node; - } - } -} |