Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/autofill/core/common/autofill_util.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/command_line.h" | |
| 10 #include "base/i18n/case_conversion.h" | |
| 11 #include "base/strings/string_piece.h" | |
| 12 #include "base/strings/string_util.h" | |
| 13 #include "base/strings/utf_string_conversions.h" | |
| 14 #include "components/autofill/core/common/autofill_switches.h" | |
| 15 | |
| 16 namespace autofill { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 base::string16 kTokenSeperatorsUTF16 = base::ASCIIToUTF16(" .,-_@"); | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 bool IsFeatureSubstringMatchEnabled() { | |
| 25 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 26 switches::kEnableSuggestionsWithSubstringMatch); | |
| 27 } | |
| 28 | |
| 29 bool IsContentsPrefixOfSuggestionToken(const base::string16& field_suggestion, | |
|
vabr (Chromium)
2015/03/30 14:51:03
What should IsContentsPrefixOfSuggestionToken("ab@
Pritam Nikam
2015/03/30 17:35:48
You are right. I did a blunder here.
I want to ke
| |
| 30 const base::string16& field_contents, | |
| 31 bool case_sensitive) { | |
| 32 if (field_suggestion.empty() || field_contents.empty()) { | |
| 33 return false; | |
| 34 } | |
| 35 | |
| 36 bool result = false; | |
| 37 base::string16 search_string = | |
| 38 case_sensitive ? field_contents : base::i18n::ToLower(field_contents); | |
| 39 base::string16 suggestion_string = | |
| 40 case_sensitive ? field_suggestion : base::i18n::ToLower(field_suggestion); | |
| 41 base::string16::size_type offset = suggestion_string.find(search_string); | |
| 42 if (base::string16::npos != offset) { | |
| 43 // Check whether the |field_contents| begins with the |suggestion_string| or | |
| 44 // character right before |offset| is one of |kTokenSeperatorsUTF16| | |
| 45 // splitting characters. | |
| 46 if (0 == offset || | |
| 47 base::ContainsOnlyChars( | |
| 48 base::internal::substr(suggestion_string, offset - 1, 1), | |
| 49 kTokenSeperatorsUTF16)) { | |
| 50 result = true; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 return result; | |
| 55 } | |
| 56 | |
| 57 base::string16::size_type ComputeRange(const base::string16& field_suggestion, | |
| 58 const base::string16& field_contents, | |
| 59 size_t* start, | |
| 60 size_t* end) { | |
| 61 base::string16 user_input = base::i18n::ToLower(field_contents); | |
| 62 base::string16 suggestion = base::i18n::ToLower(field_suggestion); | |
| 63 base::string16::size_type offset = suggestion.find(user_input); | |
| 64 if (base::string16::npos != offset) { | |
| 65 *start = offset + user_input.size(); | |
| 66 *end = suggestion.size(); | |
| 67 } | |
| 68 | |
| 69 return offset; | |
| 70 } | |
| 71 | |
| 72 } // namespace autofill | |
| OLD | NEW |