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

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 review comments. 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 bool IsFeatureSubstringMatchEnabled() {
19 return base::CommandLine::ForCurrentProcess()->HasSwitch(
20 switches::kEnableSuggestionsWithSubstringMatch);
21 }
22
23 bool IsContentsPrefixOfSuggestionToken(const base::string16& field_suggestion,
24 const base::string16& field_contents,
25 bool case_sensitive) {
26 if (!IsFeatureSubstringMatchEnabled()) {
27 return false;
28 }
29
30 bool result = false;
31 std::vector<base::string16> suggestion_tokens;
32 Tokenize(field_suggestion, base::ASCIIToUTF16(" .,-_@"), &suggestion_tokens);
33
34 // Check whether the |field_contents| prefixes any of the |field_suggestion|'s
35 // token.
36 for (auto token : suggestion_tokens) {
37 result = StartsWith(token, field_contents, case_sensitive);
Evan Stade 2015/03/31 21:41:52 this doesn't work if you type user@exa and the sug
Pritam Nikam 2015/04/01 09:10:37 Done. Modified ComputeRange() so that it will tak
38 if (result)
39 break;
40 }
41
42 return result;
43 }
44
45 base::string16::size_type ComputeRange(const base::string16& field_suggestion,
46 const base::string16& field_contents,
47 size_t* start,
48 size_t* end) {
49 base::string16::size_type offset =
50 StartsAt(field_suggestion, field_contents, false);
51 if (base::string16::npos != offset) {
52 *start = offset + field_contents.size();
53 *end = field_suggestion.size();
54 }
55
56 return offset;
57 }
58
59 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698