| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/history/query_parser.h" | 5 #include "chrome/browser/history/query_parser.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 bool QueryNodeWord::Matches(const string16& word, bool exact) const { | 119 bool QueryNodeWord::Matches(const string16& word, bool exact) const { |
| 120 if (exact || !QueryParser::IsWordLongEnoughForPrefixSearch(word_)) | 120 if (exact || !QueryParser::IsWordLongEnoughForPrefixSearch(word_)) |
| 121 return word == word_; | 121 return word == word_; |
| 122 return word.size() >= word_.size() && | 122 return word.size() >= word_.size() && |
| 123 (word_.compare(0, word_.size(), word, 0, word_.size()) == 0); | 123 (word_.compare(0, word_.size(), word, 0, word_.size()) == 0); |
| 124 } | 124 } |
| 125 | 125 |
| 126 bool QueryNodeWord::HasMatchIn(const std::vector<QueryWord>& words, | 126 bool QueryNodeWord::HasMatchIn(const std::vector<QueryWord>& words, |
| 127 Snippet::MatchPositions* match_positions) const { | 127 Snippet::MatchPositions* match_positions) const { |
| 128 bool matched = false; |
| 128 for (size_t i = 0; i < words.size(); ++i) { | 129 for (size_t i = 0; i < words.size(); ++i) { |
| 129 if (Matches(words[i].word, false)) { | 130 if (Matches(words[i].word, false)) { |
| 130 size_t match_start = words[i].position; | 131 size_t match_start = words[i].position; |
| 131 match_positions->push_back( | 132 match_positions->push_back( |
| 132 Snippet::MatchPosition(match_start, | 133 Snippet::MatchPosition(match_start, |
| 133 match_start + static_cast<int>(word_.size()))); | 134 match_start + static_cast<int>(word_.size()))); |
| 134 return true; | 135 matched = true; |
| 135 } | 136 } |
| 136 } | 137 } |
| 137 return false; | 138 return matched; |
| 138 } | 139 } |
| 139 | 140 |
| 140 void QueryNodeWord::AppendWords(std::vector<string16>* words) const { | 141 void QueryNodeWord::AppendWords(std::vector<string16>* words) const { |
| 141 words->push_back(word_); | 142 words->push_back(word_); |
| 142 } | 143 } |
| 143 | 144 |
| 144 // A QueryNodeList has a collection of QueryNodes which are deleted in the end. | 145 // A QueryNodeList has a collection of QueryNodes which are deleted in the end. |
| 145 class QueryNodeList : public QueryNode { | 146 class QueryNodeList : public QueryNode { |
| 146 public: | 147 public: |
| 147 typedef std::vector<QueryNode*> QueryNodeVector; | 148 typedef std::vector<QueryNode*> QueryNodeVector; |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 if (iter.IsWord()) { | 408 if (iter.IsWord()) { |
| 408 string16 word = iter.GetString(); | 409 string16 word = iter.GetString(); |
| 409 if (!word.empty()) { | 410 if (!word.empty()) { |
| 410 words->push_back(QueryWord()); | 411 words->push_back(QueryWord()); |
| 411 words->back().word = word; | 412 words->back().word = word; |
| 412 words->back().position = iter.prev(); | 413 words->back().position = iter.prev(); |
| 413 } | 414 } |
| 414 } | 415 } |
| 415 } | 416 } |
| 416 } | 417 } |
| OLD | NEW |