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

Unified Diff: base/strings/string_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: Incorporated Vaclav's review comments. Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: base/strings/string_util.cc
diff --git a/base/strings/string_util.cc b/base/strings/string_util.cc
index e084cb5597da6cbdcb50d0c3ce958bbc8dbc220e..77609e787d4d0575cc9ae3ffdd5c52ec1cf1471f 100644
--- a/base/strings/string_util.cc
+++ b/base/strings/string_util.cc
@@ -1006,6 +1006,27 @@ bool MatchPattern(const string16& eval, const string16& pattern) {
0, NextCharUTF16());
}
+template <typename STR>
+string16::size_type StartsAtT(const STR& str,
+ const STR& search,
+ bool case_sensitive) {
+ typename STR::const_iterator it;
+ if (case_sensitive) {
+ it = std::search(str.begin(), str.end(), search.begin(), search.end());
+ } else {
+ it = std::search(str.begin(), str.end(), search.begin(), search.end(),
+ base::CaseInsensitiveCompare<typename STR::value_type>());
+ }
+
+ return (it != str.end()) ? std::distance(str.begin(), it) : string16::npos;
danakj 2015/04/02 18:31:42 does (it - str.begin()) not work instead of std::d
Pritam Nikam 2015/04/06 06:13:10 Done.
+}
+
+string16::size_type StartsAt(const string16& str,
+ const string16& search,
+ bool case_sensitive) {
+ return StartsAtT(str, search, case_sensitive);
+}
+
// The following code is compatible with the OpenBSD lcpy interface. See:
// http://www.gratisoft.us/todd/papers/strlcpy.html
// ftp://ftp.openbsd.org/pub/OpenBSD/src/lib/libc/string/{wcs,str}lcpy.c

Powered by Google App Engine
This is Rietveld 408576698