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

Side by Side Diff: chrome/browser/history/query_parser.cc

Issue 184663002: Omnibox: Make URLs of Bookmarks Searchable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tested; works Created 6 years, 8 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 27 matching lines...) Expand all
38 i != matches->end(); ) { 38 i != matches->end(); ) {
39 if (SnippetIntersects(mp, *i)) { 39 if (SnippetIntersects(mp, *i)) {
40 mp.second = std::max(mp.second, i->second); 40 mp.second = std::max(mp.second, i->second);
41 i = matches->erase(i); 41 i = matches->erase(i);
42 } else { 42 } else {
43 return; 43 return;
44 } 44 }
45 } 45 }
46 } 46 }
47 47
48 // Sorts the match positions in |matches| by their first index, then coalesces
49 // any match positions that intersect each other.
50 void CoalseAndSortMatchPositions(Snippet::MatchPositions* matches) {
51 std::sort(matches->begin(), matches->end(), &CompareMatchPosition);
52 // WARNING: we don't use iterator here as CoalesceMatchesFrom may remove
53 // from matches.
54 for (size_t i = 0; i < matches->size(); ++i)
55 CoalesceMatchesFrom(i, matches);
56 }
57
58 // Returns true if the character is considered a quote. 48 // Returns true if the character is considered a quote.
59 bool IsQueryQuote(wchar_t ch) { 49 bool IsQueryQuote(wchar_t ch) {
60 return ch == '"' || 50 return ch == '"' ||
61 ch == 0xab || // left pointing double angle bracket 51 ch == 0xab || // left pointing double angle bracket
62 ch == 0xbb || // right pointing double angle bracket 52 ch == 0xbb || // right pointing double angle bracket
63 ch == 0x201c || // left double quotation mark 53 ch == 0x201c || // left double quotation mark
64 ch == 0x201d || // right double quotation mark 54 ch == 0x201d || // right double quotation mark
65 ch == 0x201e; // double low-9 quotation mark 55 ch == 0x201e; // double low-9 quotation mark
66 } 56 }
67 57
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 if (!query_nodes[i]->HasMatchIn(query_words, &matches)) 374 if (!query_nodes[i]->HasMatchIn(query_words, &matches))
385 return false; 375 return false;
386 } 376 }
387 if (lower_text.length() != text.length()) { 377 if (lower_text.length() != text.length()) {
388 // The lower case string differs from the original string. The matches are 378 // The lower case string differs from the original string. The matches are
389 // meaningless. 379 // meaningless.
390 // TODO(sky): we need a better way to align the positions so that we don't 380 // TODO(sky): we need a better way to align the positions so that we don't
391 // completely punt here. 381 // completely punt here.
392 match_positions->clear(); 382 match_positions->clear();
393 } else { 383 } else {
394 CoalseAndSortMatchPositions(&matches); 384 CoalesceAndSortMatchPositions(&matches);
395 match_positions->swap(matches); 385 match_positions->swap(matches);
396 } 386 }
397 return true; 387 return true;
398 } 388 }
399 389
400 bool QueryParser::DoesQueryMatch(const std::vector<QueryWord>& query_words, 390 bool QueryParser::DoesQueryMatch(const std::vector<QueryWord>& query_words,
401 const std::vector<QueryNode*>& query_nodes) { 391 const std::vector<QueryNode*>& query_nodes) {
402 if (query_nodes.empty() || query_words.empty()) 392 if (query_nodes.empty() || query_words.empty())
403 return false; 393 return false;
404 394
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 while (iter.Advance()) { 450 while (iter.Advance()) {
461 // Just found a span between 'prev' (inclusive) and 'pos' (exclusive). It 451 // Just found a span between 'prev' (inclusive) and 'pos' (exclusive). It
462 // is not necessarily a word, but could also be a sequence of punctuation 452 // is not necessarily a word, but could also be a sequence of punctuation
463 // or whitespace. 453 // or whitespace.
464 if (iter.IsWord()) { 454 if (iter.IsWord()) {
465 base::string16 word = iter.GetString(); 455 base::string16 word = iter.GetString();
466 if (!word.empty()) { 456 if (!word.empty()) {
467 words->push_back(QueryWord()); 457 words->push_back(QueryWord());
468 words->back().word = word; 458 words->back().word = word;
469 words->back().position = iter.prev(); 459 words->back().position = iter.prev();
470 } 460 }
471 } 461 }
472 } 462 }
473 } 463 }
464
465 // static
466 void QueryParser::CoalesceAndSortMatchPositions(
467 Snippet::MatchPositions* matches) {
468 std::sort(matches->begin(), matches->end(), &CompareMatchPosition);
469 // WARNING: we don't use iterator here as CoalesceMatchesFrom may remove
470 // from matches.
471 for (size_t i = 0; i < matches->size(); ++i)
472 CoalesceMatchesFrom(i, matches);
473 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698