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

Side by Side 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, 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <math.h> 9 #include <math.h>
10 #include <stdarg.h> 10 #include <stdarg.h>
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 pattern.data(), pattern.data() + pattern.size(), 999 pattern.data(), pattern.data() + pattern.size(),
1000 0, NextCharUTF8()); 1000 0, NextCharUTF8());
1001 } 1001 }
1002 1002
1003 bool MatchPattern(const string16& eval, const string16& pattern) { 1003 bool MatchPattern(const string16& eval, const string16& pattern) {
1004 return MatchPatternT(eval.c_str(), eval.c_str() + eval.size(), 1004 return MatchPatternT(eval.c_str(), eval.c_str() + eval.size(),
1005 pattern.c_str(), pattern.c_str() + pattern.size(), 1005 pattern.c_str(), pattern.c_str() + pattern.size(),
1006 0, NextCharUTF16()); 1006 0, NextCharUTF16());
1007 } 1007 }
1008 1008
1009 template <typename STR>
1010 string16::size_type StartsAtT(const STR& str,
1011 const STR& search,
1012 bool case_sensitive) {
1013 typename STR::const_iterator it;
1014 if (case_sensitive) {
1015 it = std::search(str.begin(), str.end(), search.begin(), search.end());
1016 } else {
1017 it = std::search(str.begin(), str.end(), search.begin(), search.end(),
1018 base::CaseInsensitiveCompare<typename STR::value_type>());
1019 }
1020
1021 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.
1022 }
1023
1024 string16::size_type StartsAt(const string16& str,
1025 const string16& search,
1026 bool case_sensitive) {
1027 return StartsAtT(str, search, case_sensitive);
1028 }
1029
1009 // The following code is compatible with the OpenBSD lcpy interface. See: 1030 // The following code is compatible with the OpenBSD lcpy interface. See:
1010 // http://www.gratisoft.us/todd/papers/strlcpy.html 1031 // http://www.gratisoft.us/todd/papers/strlcpy.html
1011 // ftp://ftp.openbsd.org/pub/OpenBSD/src/lib/libc/string/{wcs,str}lcpy.c 1032 // ftp://ftp.openbsd.org/pub/OpenBSD/src/lib/libc/string/{wcs,str}lcpy.c
1012 1033
1013 namespace { 1034 namespace {
1014 1035
1015 template <typename CHAR> 1036 template <typename CHAR>
1016 size_t lcpyT(CHAR* dst, const CHAR* src, size_t dst_size) { 1037 size_t lcpyT(CHAR* dst, const CHAR* src, size_t dst_size) {
1017 for (size_t i = 0; i < dst_size; ++i) { 1038 for (size_t i = 0; i < dst_size; ++i) {
1018 if ((dst[i] = src[i]) == 0) // We hit and copied the terminating NULL. 1039 if ((dst[i] = src[i]) == 0) // We hit and copied the terminating NULL.
(...skipping 10 matching lines...) Expand all
1029 } 1050 }
1030 1051
1031 } // namespace 1052 } // namespace
1032 1053
1033 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { 1054 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) {
1034 return lcpyT<char>(dst, src, dst_size); 1055 return lcpyT<char>(dst, src, dst_size);
1035 } 1056 }
1036 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { 1057 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
1037 return lcpyT<wchar_t>(dst, src, dst_size); 1058 return lcpyT<wchar_t>(dst, src, dst_size);
1038 } 1059 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698