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

Side by Side Diff: base/strings/string_util.h

Issue 448853002: Move StringToLowerASCII to base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « base/i18n/rtl.cc ('k') | chrome/app/chrome_main_delegate.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 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 // This file defines utility functions for working with strings. 5 // This file defines utility functions for working with strings.
6 6
7 #ifndef BASE_STRINGS_STRING_UTIL_H_ 7 #ifndef BASE_STRINGS_STRING_UTIL_H_
8 #define BASE_STRINGS_STRING_UTIL_H_ 8 #define BASE_STRINGS_STRING_UTIL_H_
9 9
10 #include <ctype.h> 10 #include <ctype.h>
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // Note that IsStringUTF8 checks not only if the input is structurally 242 // Note that IsStringUTF8 checks not only if the input is structurally
243 // valid but also if it doesn't contain any non-character codepoint 243 // valid but also if it doesn't contain any non-character codepoint
244 // (e.g. U+FFFE). It's done on purpose because all the existing callers want 244 // (e.g. U+FFFE). It's done on purpose because all the existing callers want
245 // to have the maximum 'discriminating' power from other encodings. If 245 // to have the maximum 'discriminating' power from other encodings. If
246 // there's a use case for just checking the structural validity, we have to 246 // there's a use case for just checking the structural validity, we have to
247 // add a new function for that. 247 // add a new function for that.
248 BASE_EXPORT bool IsStringUTF8(const std::string& str); 248 BASE_EXPORT bool IsStringUTF8(const std::string& str);
249 BASE_EXPORT bool IsStringASCII(const StringPiece& str); 249 BASE_EXPORT bool IsStringASCII(const StringPiece& str);
250 BASE_EXPORT bool IsStringASCII(const string16& str); 250 BASE_EXPORT bool IsStringASCII(const string16& str);
251 251
252 } // namespace base
253
254 #if defined(OS_WIN)
255 #include "base/strings/string_util_win.h"
256 #elif defined(OS_POSIX)
257 #include "base/strings/string_util_posix.h"
258 #else
259 #error Define string operations appropriately for your platform
260 #endif
261
262 // Converts the elements of the given string. This version uses a pointer to 252 // Converts the elements of the given string. This version uses a pointer to
263 // clearly differentiate it from the non-pointer variant. 253 // clearly differentiate it from the non-pointer variant.
264 template <class str> inline void StringToLowerASCII(str* s) { 254 template <class str> inline void StringToLowerASCII(str* s) {
265 for (typename str::iterator i = s->begin(); i != s->end(); ++i) 255 for (typename str::iterator i = s->begin(); i != s->end(); ++i)
266 *i = base::ToLowerASCII(*i); 256 *i = ToLowerASCII(*i);
267 } 257 }
268 258
269 template <class str> inline str StringToLowerASCII(const str& s) { 259 template <class str> inline str StringToLowerASCII(const str& s) {
270 // for std::string and std::wstring 260 // for std::string and std::wstring
271 str output(s); 261 str output(s);
272 StringToLowerASCII(&output); 262 StringToLowerASCII(&output);
273 return output; 263 return output;
274 } 264 }
275 265
266 } // namespace base
267
268 #if defined(OS_WIN)
269 #include "base/strings/string_util_win.h"
270 #elif defined(OS_POSIX)
271 #include "base/strings/string_util_posix.h"
272 #else
273 #error Define string operations appropriately for your platform
274 #endif
275
276 // Converts the elements of the given string. This version uses a pointer to 276 // Converts the elements of the given string. This version uses a pointer to
277 // clearly differentiate it from the non-pointer variant. 277 // clearly differentiate it from the non-pointer variant.
278 template <class str> inline void StringToUpperASCII(str* s) { 278 template <class str> inline void StringToUpperASCII(str* s) {
279 for (typename str::iterator i = s->begin(); i != s->end(); ++i) 279 for (typename str::iterator i = s->begin(); i != s->end(); ++i)
280 *i = base::ToUpperASCII(*i); 280 *i = base::ToUpperASCII(*i);
281 } 281 }
282 282
283 template <class str> inline str StringToUpperASCII(const str& s) { 283 template <class str> inline str StringToUpperASCII(const str& s) {
284 // for std::string and std::wstring 284 // for std::string and std::wstring
285 str output(s); 285 str output(s);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 #elif defined(WCHAR_T_IS_UTF32) 514 #elif defined(WCHAR_T_IS_UTF32)
515 typedef uint32 Unsigned; 515 typedef uint32 Unsigned;
516 #endif 516 #endif
517 }; 517 };
518 template<> 518 template<>
519 struct ToUnsigned<short> { 519 struct ToUnsigned<short> {
520 typedef unsigned short Unsigned; 520 typedef unsigned short Unsigned;
521 }; 521 };
522 522
523 #endif // BASE_STRINGS_STRING_UTIL_H_ 523 #endif // BASE_STRINGS_STRING_UTIL_H_
OLDNEW
« no previous file with comments | « base/i18n/rtl.cc ('k') | chrome/app/chrome_main_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698