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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 // completely punt here. | 347 // completely punt here. |
348 match_positions->clear(); | 348 match_positions->clear(); |
349 } else { | 349 } else { |
350 CoalseAndSortMatchPositions(&matches); | 350 CoalseAndSortMatchPositions(&matches); |
351 match_positions->swap(matches); | 351 match_positions->swap(matches); |
352 } | 352 } |
353 return true; | 353 return true; |
354 } | 354 } |
355 | 355 |
356 bool QueryParser::ParseQueryImpl(const string16& query, QueryNodeList* root) { | 356 bool QueryParser::ParseQueryImpl(const string16& query, QueryNodeList* root) { |
357 base::i18n::BreakIterator iter(&query, base::i18n::BreakIterator::BREAK_WORD); | 357 base::i18n::BreakIterator iter(query, base::i18n::BreakIterator::BREAK_WORD); |
358 // TODO(evanm): support a locale here | 358 // TODO(evanm): support a locale here |
359 if (!iter.Init()) | 359 if (!iter.Init()) |
360 return false; | 360 return false; |
361 | 361 |
362 // To handle nesting, we maintain a stack of QueryNodeLists. | 362 // To handle nesting, we maintain a stack of QueryNodeLists. |
363 // The last element (back) of the stack contains the current, deepest node. | 363 // The last element (back) of the stack contains the current, deepest node. |
364 std::vector<QueryNodeList*> query_stack; | 364 std::vector<QueryNodeList*> query_stack; |
365 query_stack.push_back(root); | 365 query_stack.push_back(root); |
366 | 366 |
367 bool in_quotes = false; // whether we're currently in a quoted phrase | 367 bool in_quotes = false; // whether we're currently in a quoted phrase |
(...skipping 20 matching lines...) Expand all Loading... |
388 } | 388 } |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 root->RemoveEmptySubnodes(); | 392 root->RemoveEmptySubnodes(); |
393 return true; | 393 return true; |
394 } | 394 } |
395 | 395 |
396 void QueryParser::ExtractQueryWords(const string16& text, | 396 void QueryParser::ExtractQueryWords(const string16& text, |
397 std::vector<QueryWord>* words) { | 397 std::vector<QueryWord>* words) { |
398 base::i18n::BreakIterator iter(&text, base::i18n::BreakIterator::BREAK_WORD); | 398 base::i18n::BreakIterator iter(text, base::i18n::BreakIterator::BREAK_WORD); |
399 // TODO(evanm): support a locale here | 399 // TODO(evanm): support a locale here |
400 if (!iter.Init()) | 400 if (!iter.Init()) |
401 return; | 401 return; |
402 | 402 |
403 while (iter.Advance()) { | 403 while (iter.Advance()) { |
404 // Just found a span between 'prev' (inclusive) and 'pos' (exclusive). It | 404 // Just found a span between 'prev' (inclusive) and 'pos' (exclusive). It |
405 // is not necessarily a word, but could also be a sequence of punctuation | 405 // is not necessarily a word, but could also be a sequence of punctuation |
406 // or whitespace. | 406 // or whitespace. |
407 if (iter.IsWord()) { | 407 if (iter.IsWord()) { |
408 string16 word = iter.GetString(); | 408 string16 word = iter.GetString(); |
409 if (!word.empty()) { | 409 if (!word.empty()) { |
410 words->push_back(QueryWord()); | 410 words->push_back(QueryWord()); |
411 words->back().word = word; | 411 words->back().word = word; |
412 words->back().position = iter.prev(); | 412 words->back().position = iter.prev(); |
413 } | 413 } |
414 } | 414 } |
415 } | 415 } |
416 } | 416 } |
OLD | NEW |