Index: components/autofill/core/common/autofill_util.cc |
diff --git a/components/autofill/core/common/autofill_util.cc b/components/autofill/core/common/autofill_util.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8c263ae2942c1d4dabd18991766d6d2c8cbac5e8 |
--- /dev/null |
+++ b/components/autofill/core/common/autofill_util.cc |
@@ -0,0 +1,59 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/autofill/core/common/autofill_util.h" |
+ |
+#include <vector> |
+ |
+#include "base/command_line.h" |
+#include "base/i18n/case_conversion.h" |
+#include "base/strings/string_piece.h" |
+#include "base/strings/string_util.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "components/autofill/core/common/autofill_switches.h" |
+ |
+namespace autofill { |
+ |
+bool IsFeatureSubstringMatchEnabled() { |
+ return base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableSuggestionsWithSubstringMatch); |
+} |
+ |
+bool IsContentsPrefixOfSuggestionToken(const base::string16& field_suggestion, |
+ const base::string16& field_contents, |
+ bool case_sensitive) { |
+ if (!IsFeatureSubstringMatchEnabled()) { |
+ return false; |
+ } |
+ |
+ bool result = false; |
+ std::vector<base::string16> suggestion_tokens; |
+ Tokenize(field_suggestion, base::ASCIIToUTF16(" .,-_@"), &suggestion_tokens); |
+ |
+ // Check whether the |field_contents| prefixes any of the |field_suggestion|'s |
+ // token. |
+ for (auto token : suggestion_tokens) { |
+ 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
|
+ if (result) |
+ break; |
+ } |
+ |
+ return result; |
+} |
+ |
+base::string16::size_type ComputeRange(const base::string16& field_suggestion, |
+ const base::string16& field_contents, |
+ size_t* start, |
+ size_t* end) { |
+ base::string16::size_type offset = |
+ StartsAt(field_suggestion, field_contents, false); |
+ if (base::string16::npos != offset) { |
+ *start = offset + field_contents.size(); |
+ *end = field_suggestion.size(); |
+ } |
+ |
+ return offset; |
+} |
+ |
+} // namespace autofill |