| 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/url_prefix.h" | 5 #include "chrome/browser/autocomplete/url_prefix.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 9 | 10 |
| 10 URLPrefix::URLPrefix(const string16& prefix, size_t num_components) | 11 URLPrefix::URLPrefix(const string16& prefix, size_t num_components) |
| 11 : prefix(prefix), | 12 : prefix(prefix), |
| 12 num_components(num_components) { | 13 num_components(num_components) { |
| 13 } | 14 } |
| 14 | 15 |
| 15 // static | 16 // static |
| 16 const URLPrefixes& URLPrefix::GetURLPrefixes() { | 17 const URLPrefixes& URLPrefix::GetURLPrefixes() { |
| 17 CR_DEFINE_STATIC_LOCAL(URLPrefixes, prefixes, ()); | 18 CR_DEFINE_STATIC_LOCAL(URLPrefixes, prefixes, ()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 33 const URLPrefixes& list = GetURLPrefixes(); | 34 const URLPrefixes& list = GetURLPrefixes(); |
| 34 for (URLPrefixes::const_iterator i = list.begin(); i != list.end(); ++i) | 35 for (URLPrefixes::const_iterator i = list.begin(); i != list.end(); ++i) |
| 35 if (i->prefix == prefix) | 36 if (i->prefix == prefix) |
| 36 return true; | 37 return true; |
| 37 return false; | 38 return false; |
| 38 } | 39 } |
| 39 | 40 |
| 40 // static | 41 // static |
| 41 const URLPrefix* URLPrefix::BestURLPrefix(const string16& text, | 42 const URLPrefix* URLPrefix::BestURLPrefix(const string16& text, |
| 42 const string16& prefix_suffix) { | 43 const string16& prefix_suffix) { |
| 43 const URLPrefix* best_prefix = NULL; | |
| 44 const URLPrefixes& list = GetURLPrefixes(); | 44 const URLPrefixes& list = GetURLPrefixes(); |
| 45 for (URLPrefixes::const_iterator i = list.begin(); i != list.end(); ++i) { | 45 for (URLPrefixes::const_iterator i = list.begin(); i != list.end(); ++i) |
| 46 if (!best_prefix || (i->num_components > best_prefix->num_components)) { | 46 if (StartsWith(text, i->prefix + prefix_suffix, false)) |
| 47 string16 prefix_with_suffix(i->prefix + prefix_suffix); | 47 return &(*i); |
| 48 if ((text.length() >= prefix_with_suffix.length()) && | 48 return NULL; |
| 49 !text.compare(0, prefix_with_suffix.length(), prefix_with_suffix)) | |
| 50 best_prefix = &(*i); | |
| 51 } | |
| 52 } | |
| 53 return best_prefix; | |
| 54 } | 49 } |
| OLD | NEW |