| 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;
|
| - }
|
| - }
|
| -}
|
|
|