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

Side by Side Diff: base/string_util.cc

Issue 8502027: Fix AutocompleteMatch DCHECK() triggered by |RenderViewContextMenu::AppendSearchProvider()|. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « base/string_util.h ('k') | base/string_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/string_util.h" 5 #include "base/string_util.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <ctype.h> 9 #include <ctype.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 0x0B, 158 0x0B,
159 0x0C, 159 0x0C,
160 0x0D, 160 0x0D,
161 0x20, // Space 161 0x20, // Space
162 0 162 0
163 }; 163 };
164 164
165 const char kUtf8ByteOrderMark[] = "\xEF\xBB\xBF"; 165 const char kUtf8ByteOrderMark[] = "\xEF\xBB\xBF";
166 166
167 template<typename STR> 167 template<typename STR>
168 bool RemoveCharsT(const STR& input, 168 bool ReplaceCharsT(const STR& input,
169 const typename STR::value_type remove_chars[], 169 const typename STR::value_type replace_chars[],
170 STR* output) { 170 const STR& replace_with,
171 STR* output) {
171 bool removed = false; 172 bool removed = false;
172 size_t found; 173 size_t found;
173 174
174 *output = input; 175 *output = input;
175 176
176 found = output->find_first_of(remove_chars); 177 found = output->find_first_of(replace_chars);
177 while (found != STR::npos) { 178 while (found != STR::npos) {
178 removed = true; 179 removed = true;
179 output->replace(found, 1, STR()); 180 output->replace(found, 1, replace_with);
180 found = output->find_first_of(remove_chars, found); 181 found = output->find_first_of(replace_chars, found);
181 } 182 }
182 183
183 return removed; 184 return removed;
184 } 185 }
185 186
187 bool ReplaceChars(const string16& input,
188 const char16 replace_chars[],
189 const string16& replace_with,
190 string16* output) {
191 return ReplaceCharsT(input, replace_chars, replace_with, output);
192 }
193
194 bool ReplaceChars(const std::string& input,
195 const char replace_chars[],
196 const std::string& replace_with,
197 std::string* output) {
198 return ReplaceCharsT(input, replace_chars, replace_with, output);
199 }
200
186 bool RemoveChars(const string16& input, 201 bool RemoveChars(const string16& input,
187 const char16 remove_chars[], 202 const char16 remove_chars[],
188 string16* output) { 203 string16* output) {
189 return RemoveCharsT(input, remove_chars, output); 204 return ReplaceChars(input, remove_chars, string16(), output);
190 } 205 }
191 206
192 bool RemoveChars(const std::string& input, 207 bool RemoveChars(const std::string& input,
193 const char remove_chars[], 208 const char remove_chars[],
194 std::string* output) { 209 std::string* output) {
195 return RemoveCharsT(input, remove_chars, output); 210 return ReplaceChars(input, remove_chars, std::string(), output);
196 } 211 }
197 212
198 template<typename STR> 213 template<typename STR>
199 TrimPositions TrimStringT(const STR& input, 214 TrimPositions TrimStringT(const STR& input,
200 const typename STR::value_type trim_chars[], 215 const typename STR::value_type trim_chars[],
201 TrimPositions positions, 216 TrimPositions positions,
202 STR* output) { 217 STR* output) {
203 // Find the edges of leading/trailing whitespace as desired. 218 // Find the edges of leading/trailing whitespace as desired.
204 const typename STR::size_type last_char = input.length() - 1; 219 const typename STR::size_type last_char = input.length() - 1;
205 const typename STR::size_type first_good_char = (positions & TRIM_LEADING) ? 220 const typename STR::size_type first_good_char = (positions & TRIM_LEADING) ?
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 } 1046 }
1032 1047
1033 } // namespace 1048 } // namespace
1034 1049
1035 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { 1050 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) {
1036 return lcpyT<char>(dst, src, dst_size); 1051 return lcpyT<char>(dst, src, dst_size);
1037 } 1052 }
1038 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { 1053 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
1039 return lcpyT<wchar_t>(dst, src, dst_size); 1054 return lcpyT<wchar_t>(dst, src, dst_size);
1040 } 1055 }
OLDNEW
« no previous file with comments | « base/string_util.h ('k') | base/string_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698