OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/query_parser/query_parser.h" | 5 #include "components/query_parser/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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 class QueryNodeWord : public QueryNode { | 67 class QueryNodeWord : public QueryNode { |
68 public: | 68 public: |
69 explicit QueryNodeWord(const base::string16& word); | 69 explicit QueryNodeWord(const base::string16& word); |
70 virtual ~QueryNodeWord(); | 70 virtual ~QueryNodeWord(); |
71 | 71 |
72 const base::string16& word() const { return word_; } | 72 const base::string16& word() const { return word_; } |
73 | 73 |
74 void set_literal(bool literal) { literal_ = literal; } | 74 void set_literal(bool literal) { literal_ = literal; } |
75 | 75 |
76 // QueryNode: | 76 // QueryNode: |
77 virtual int AppendToSQLiteQuery(base::string16* query) const OVERRIDE; | 77 virtual int AppendToSQLiteQuery(base::string16* query) const override; |
78 virtual bool IsWord() const OVERRIDE; | 78 virtual bool IsWord() const override; |
79 virtual bool Matches(const base::string16& word, bool exact) const OVERRIDE; | 79 virtual bool Matches(const base::string16& word, bool exact) const override; |
80 virtual bool HasMatchIn( | 80 virtual bool HasMatchIn( |
81 const QueryWordVector& words, | 81 const QueryWordVector& words, |
82 Snippet::MatchPositions* match_positions) const OVERRIDE; | 82 Snippet::MatchPositions* match_positions) const override; |
83 virtual bool HasMatchIn( | 83 virtual bool HasMatchIn( |
84 const QueryWordVector& words) const OVERRIDE; | 84 const QueryWordVector& words) const override; |
85 virtual void AppendWords(std::vector<base::string16>* words) const OVERRIDE; | 85 virtual void AppendWords(std::vector<base::string16>* words) const override; |
86 | 86 |
87 private: | 87 private: |
88 base::string16 word_; | 88 base::string16 word_; |
89 bool literal_; | 89 bool literal_; |
90 | 90 |
91 DISALLOW_COPY_AND_ASSIGN(QueryNodeWord); | 91 DISALLOW_COPY_AND_ASSIGN(QueryNodeWord); |
92 }; | 92 }; |
93 | 93 |
94 QueryNodeWord::QueryNodeWord(const base::string16& word) | 94 QueryNodeWord::QueryNodeWord(const base::string16& word) |
95 : word_(word), | 95 : word_(word), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 virtual ~QueryNodeList(); | 151 virtual ~QueryNodeList(); |
152 | 152 |
153 QueryNodeStarVector* children() { return &children_; } | 153 QueryNodeStarVector* children() { return &children_; } |
154 | 154 |
155 void AddChild(QueryNode* node); | 155 void AddChild(QueryNode* node); |
156 | 156 |
157 // Remove empty subnodes left over from other parsing. | 157 // Remove empty subnodes left over from other parsing. |
158 void RemoveEmptySubnodes(); | 158 void RemoveEmptySubnodes(); |
159 | 159 |
160 // QueryNode: | 160 // QueryNode: |
161 virtual int AppendToSQLiteQuery(base::string16* query) const OVERRIDE; | 161 virtual int AppendToSQLiteQuery(base::string16* query) const override; |
162 virtual bool IsWord() const OVERRIDE; | 162 virtual bool IsWord() const override; |
163 virtual bool Matches(const base::string16& word, bool exact) const OVERRIDE; | 163 virtual bool Matches(const base::string16& word, bool exact) const override; |
164 virtual bool HasMatchIn( | 164 virtual bool HasMatchIn( |
165 const QueryWordVector& words, | 165 const QueryWordVector& words, |
166 Snippet::MatchPositions* match_positions) const OVERRIDE; | 166 Snippet::MatchPositions* match_positions) const override; |
167 virtual bool HasMatchIn(const QueryWordVector& words) const OVERRIDE; | 167 virtual bool HasMatchIn(const QueryWordVector& words) const override; |
168 virtual void AppendWords(std::vector<base::string16>* words) const OVERRIDE; | 168 virtual void AppendWords(std::vector<base::string16>* words) const override; |
169 | 169 |
170 protected: | 170 protected: |
171 int AppendChildrenToString(base::string16* query) const; | 171 int AppendChildrenToString(base::string16* query) const; |
172 | 172 |
173 QueryNodeStarVector children_; | 173 QueryNodeStarVector children_; |
174 | 174 |
175 private: | 175 private: |
176 DISALLOW_COPY_AND_ASSIGN(QueryNodeList); | 176 DISALLOW_COPY_AND_ASSIGN(QueryNodeList); |
177 }; | 177 }; |
178 | 178 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 return num_words; | 241 return num_words; |
242 } | 242 } |
243 | 243 |
244 // A QueryNodePhrase is a phrase query ("quoted"). | 244 // A QueryNodePhrase is a phrase query ("quoted"). |
245 class QueryNodePhrase : public QueryNodeList { | 245 class QueryNodePhrase : public QueryNodeList { |
246 public: | 246 public: |
247 QueryNodePhrase(); | 247 QueryNodePhrase(); |
248 virtual ~QueryNodePhrase(); | 248 virtual ~QueryNodePhrase(); |
249 | 249 |
250 // QueryNodeList: | 250 // QueryNodeList: |
251 virtual int AppendToSQLiteQuery(base::string16* query) const OVERRIDE; | 251 virtual int AppendToSQLiteQuery(base::string16* query) const override; |
252 virtual bool HasMatchIn( | 252 virtual bool HasMatchIn( |
253 const QueryWordVector& words, | 253 const QueryWordVector& words, |
254 Snippet::MatchPositions* match_positions) const OVERRIDE; | 254 Snippet::MatchPositions* match_positions) const override; |
255 virtual bool HasMatchIn(const QueryWordVector& words) const OVERRIDE; | 255 virtual bool HasMatchIn(const QueryWordVector& words) const override; |
256 | 256 |
257 private: | 257 private: |
258 bool MatchesAll(const QueryWordVector& words, | 258 bool MatchesAll(const QueryWordVector& words, |
259 const QueryWord** first_word, | 259 const QueryWord** first_word, |
260 const QueryWord** last_word) const; | 260 const QueryWord** last_word) const; |
261 DISALLOW_COPY_AND_ASSIGN(QueryNodePhrase); | 261 DISALLOW_COPY_AND_ASSIGN(QueryNodePhrase); |
262 }; | 262 }; |
263 | 263 |
264 QueryNodePhrase::QueryNodePhrase() {} | 264 QueryNodePhrase::QueryNodePhrase() {} |
265 | 265 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 void QueryParser::SortAndCoalesceMatchPositions( | 463 void QueryParser::SortAndCoalesceMatchPositions( |
464 Snippet::MatchPositions* matches) { | 464 Snippet::MatchPositions* matches) { |
465 std::sort(matches->begin(), matches->end(), &CompareMatchPosition); | 465 std::sort(matches->begin(), matches->end(), &CompareMatchPosition); |
466 // WARNING: we don't use iterator here as CoalesceMatchesFrom may remove | 466 // WARNING: we don't use iterator here as CoalesceMatchesFrom may remove |
467 // from matches. | 467 // from matches. |
468 for (size_t i = 0; i < matches->size(); ++i) | 468 for (size_t i = 0; i < matches->size(); ++i) |
469 CoalesceMatchesFrom(i, matches); | 469 CoalesceMatchesFrom(i, matches); |
470 } | 470 } |
471 | 471 |
472 } // namespace query_parser | 472 } // namespace query_parser |
OLD | NEW |