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..ca75732ee4732a741cfbf2b80953529711e27aaa |
--- /dev/null |
+++ b/components/autofill/core/common/autofill_util.cc |
@@ -0,0 +1,72 @@ |
+// 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 { |
+ |
+namespace { |
+ |
+base::string16 kTokenSeperatorsUTF16 = base::ASCIIToUTF16(" .,-_@"); |
+ |
+} // namespace |
+ |
+bool IsFeatureSubstringMatchEnabled() { |
+ return base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableSuggestionsWithSubstringMatch); |
+} |
+ |
+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
|
+ const base::string16& field_contents, |
+ bool case_sensitive) { |
+ if (field_suggestion.empty() || field_contents.empty()) { |
+ return false; |
+ } |
+ |
+ bool result = false; |
+ base::string16 search_string = |
+ case_sensitive ? field_contents : base::i18n::ToLower(field_contents); |
+ base::string16 suggestion_string = |
+ case_sensitive ? field_suggestion : base::i18n::ToLower(field_suggestion); |
+ base::string16::size_type offset = suggestion_string.find(search_string); |
+ if (base::string16::npos != offset) { |
+ // Check whether the |field_contents| begins with the |suggestion_string| or |
+ // character right before |offset| is one of |kTokenSeperatorsUTF16| |
+ // splitting characters. |
+ if (0 == offset || |
+ base::ContainsOnlyChars( |
+ base::internal::substr(suggestion_string, offset - 1, 1), |
+ kTokenSeperatorsUTF16)) { |
+ result = true; |
+ } |
+ } |
+ |
+ 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 user_input = base::i18n::ToLower(field_contents); |
+ base::string16 suggestion = base::i18n::ToLower(field_suggestion); |
+ base::string16::size_type offset = suggestion.find(user_input); |
+ if (base::string16::npos != offset) { |
+ *start = offset + user_input.size(); |
+ *end = suggestion.size(); |
+ } |
+ |
+ return offset; |
+} |
+ |
+} // namespace autofill |