| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/autocomplete/history_provider.h" | 5 #include "chrome/browser/autocomplete/history_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 matches_.erase(i); | 73 matches_.erase(i); |
| 74 } | 74 } |
| 75 break; | 75 break; |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; | 78 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; |
| 79 } | 79 } |
| 80 | 80 |
| 81 // static | 81 // static |
| 82 ACMatchClassifications HistoryProvider::SpansFromTermMatch( | 82 ACMatchClassifications HistoryProvider::SpansFromTermMatch( |
| 83 const history::TermMatches& matches, | 83 const TermMatches& matches, |
| 84 size_t text_length, | 84 size_t text_length, |
| 85 bool is_url) { | 85 bool is_url) { |
| 86 ACMatchClassification::Style url_style = | 86 ACMatchClassification::Style url_style = |
| 87 is_url ? ACMatchClassification::URL : ACMatchClassification::NONE; | 87 is_url ? ACMatchClassification::URL : ACMatchClassification::NONE; |
| 88 ACMatchClassifications spans; | 88 ACMatchClassifications spans; |
| 89 if (matches.empty()) { | 89 if (matches.empty()) { |
| 90 if (text_length) | 90 if (text_length) |
| 91 spans.push_back(ACMatchClassification(0, url_style)); | 91 spans.push_back(ACMatchClassification(0, url_style)); |
| 92 return spans; | 92 return spans; |
| 93 } | 93 } |
| 94 if (matches[0].offset) | 94 if (matches[0].offset) |
| 95 spans.push_back(ACMatchClassification(0, url_style)); | 95 spans.push_back(ACMatchClassification(0, url_style)); |
| 96 size_t match_count = matches.size(); | 96 size_t match_count = matches.size(); |
| 97 for (size_t i = 0; i < match_count;) { | 97 for (size_t i = 0; i < match_count;) { |
| 98 size_t offset = matches[i].offset; | 98 size_t offset = matches[i].offset; |
| 99 spans.push_back(ACMatchClassification(offset, | 99 spans.push_back(ACMatchClassification(offset, |
| 100 ACMatchClassification::MATCH | url_style)); | 100 ACMatchClassification::MATCH | url_style)); |
| 101 // Skip all adjacent matches. | 101 // Skip all adjacent matches. |
| 102 do { | 102 do { |
| 103 offset += matches[i].length; | 103 offset += matches[i].length; |
| 104 ++i; | 104 ++i; |
| 105 } while ((i < match_count) && (offset == matches[i].offset)); | 105 } while ((i < match_count) && (offset == matches[i].offset)); |
| 106 if (offset < text_length) | 106 if (offset < text_length) |
| 107 spans.push_back(ACMatchClassification(offset, url_style)); | 107 spans.push_back(ACMatchClassification(offset, url_style)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 return spans; | 110 return spans; |
| 111 } | 111 } |
| OLD | NEW |