Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Unified Diff: chrome/browser/history/query_parser.cc

Issue 13296: Adds QueryParser::ExtractQueryWords. For consistent this should... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/history/query_parser.h ('k') | chrome/browser/history/query_parser_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/query_parser.cc
===================================================================
--- chrome/browser/history/query_parser.cc (revision 6595)
+++ chrome/browser/history/query_parser.cc (working copy)
@@ -97,6 +97,7 @@
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 @@
(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 @@
NOTREACHED();
return false;
}
+ virtual void AppendWords(std::vector<std::wstring>* words) const;
protected:
int AppendChildrenToString(std::wstring* query) const;
@@ -175,6 +181,26 @@
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 @@
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 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;
- }
- }
-}
« no previous file with comments | « chrome/browser/history/query_parser.h ('k') | chrome/browser/history/query_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698