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

Side by Side Diff: components/autofill/core/common/autofill_util.cc

Issue 962673004: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses Vaclav's inputs unittests. Created 5 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
OLDNEW
(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(" .,-_@");
vabr (Chromium) 2015/03/31 09:38:07 I'm surprised none of the compilers complained abo
Pritam Nikam 2015/03/31 14:26:12 Done. Removed it and used in-place substitution.
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,
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);
vabr (Chromium) 2015/03/31 09:38:07 Why are you doing this pre-search? If it is just f
Pritam Nikam 2015/03/31 14:26:11 Done.
42 if (base::string16::npos != offset) {
43 std::vector<base::string16> suggestion_tokens;
44 Tokenize(suggestion_string, kTokenSeperatorsUTF16, &suggestion_tokens);
45
46 // Check whether the |search_string| prefixes any of the
47 // |suggestion_string|'s token.
48 if (suggestion_tokens.size() != 0) {
vabr (Chromium) 2015/03/31 09:38:07 You do not really need this if. For size() == 0 th
Pritam Nikam 2015/03/31 14:26:12 Done.
49 for (auto token : suggestion_tokens) {
50 result = StartsWith(token, search_string, case_sensitive);
51 if (result)
52 break;
53 }
54 }
55 }
56
57 return result;
58 }
59
60 base::string16::size_type ComputeRange(const base::string16& field_suggestion,
61 const base::string16& field_contents,
62 size_t* start,
63 size_t* end) {
64 base::string16 user_input = base::i18n::ToLower(field_contents);
65 base::string16 suggestion = base::i18n::ToLower(field_suggestion);
66 base::string16::size_type offset = suggestion.find(user_input);
67 if (base::string16::npos != offset) {
68 *start = offset + user_input.size();
69 *end = suggestion.size();
70 }
71
72 return offset;
73 }
74
75 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698