| 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 27 matching lines...) Expand all Loading... |
| 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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::CoalseAndSortMatchPositions( |
| 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 } |
| OLD | NEW |