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

Side by Side Diff: base/string_util.h

Issue 4371001: Fix clang build by moving ToLowerASCII into base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 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 | « no previous file | base/string_util.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_STRING_UTIL_H_ 7 #ifndef BASE_STRING_UTIL_H_
8 #define BASE_STRING_UTIL_H_ 8 #define BASE_STRING_UTIL_H_
9 #pragma once 9 #pragma once
10 10
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // - 'F', which is not identified by Windows wprintf documentation. 109 // - 'F', which is not identified by Windows wprintf documentation.
110 // - 'D', 'O', and 'U', which are deprecated and not available on all systems. 110 // - 'D', 'O', and 'U', which are deprecated and not available on all systems.
111 // Use %ld, %lo, and %lu instead. 111 // Use %ld, %lo, and %lu instead.
112 // 112 //
113 // Note that there is no portable conversion specifier for char data when 113 // Note that there is no portable conversion specifier for char data when
114 // working with wprintf. 114 // working with wprintf.
115 // 115 //
116 // This function is intended to be called from base::vswprintf. 116 // This function is intended to be called from base::vswprintf.
117 bool IsWprintfFormatPortable(const wchar_t* format); 117 bool IsWprintfFormatPortable(const wchar_t* format);
118 118
119 // ASCII-specific tolower. The standard library's tolower is locale sensitive,
120 // so we don't want to use it here.
121 template <class Char> inline Char ToLowerASCII(Char c) {
122 return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c;
123 }
124
119 // Function objects to aid in comparing/searching strings. 125 // Function objects to aid in comparing/searching strings.
120 126
121 template<typename Char> struct CaseInsensitiveCompare { 127 template<typename Char> struct CaseInsensitiveCompare {
122 public: 128 public:
123 bool operator()(Char x, Char y) const { 129 bool operator()(Char x, Char y) const {
124 // TODO(darin): Do we really want to do locale sensitive comparisons here? 130 // TODO(darin): Do we really want to do locale sensitive comparisons here?
125 // See http://crbug.com/24917 131 // See http://crbug.com/24917
126 return tolower(x) == tolower(y); 132 return tolower(x) == tolower(y);
127 } 133 }
128 }; 134 };
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 // valid but also if it doesn't contain any non-character codepoint 274 // valid but also if it doesn't contain any non-character codepoint
269 // (e.g. U+FFFE). It's done on purpose because all the existing callers want 275 // (e.g. U+FFFE). It's done on purpose because all the existing callers want
270 // to have the maximum 'discriminating' power from other encodings. If 276 // to have the maximum 'discriminating' power from other encodings. If
271 // there's a use case for just checking the structural validity, we have to 277 // there's a use case for just checking the structural validity, we have to
272 // add a new function for that. 278 // add a new function for that.
273 bool IsStringUTF8(const std::string& str); 279 bool IsStringUTF8(const std::string& str);
274 bool IsStringASCII(const std::wstring& str); 280 bool IsStringASCII(const std::wstring& str);
275 bool IsStringASCII(const base::StringPiece& str); 281 bool IsStringASCII(const base::StringPiece& str);
276 bool IsStringASCII(const string16& str); 282 bool IsStringASCII(const string16& str);
277 283
278 // ASCII-specific tolower. The standard library's tolower is locale sensitive,
279 // so we don't want to use it here.
280 template <class Char> inline Char ToLowerASCII(Char c) {
281 return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c;
282 }
283
284 // Converts the elements of the given string. This version uses a pointer to 284 // Converts the elements of the given string. This version uses a pointer to
285 // clearly differentiate it from the non-pointer variant. 285 // clearly differentiate it from the non-pointer variant.
286 template <class str> inline void StringToLowerASCII(str* s) { 286 template <class str> inline void StringToLowerASCII(str* s) {
287 for (typename str::iterator i = s->begin(); i != s->end(); ++i) 287 for (typename str::iterator i = s->begin(); i != s->end(); ++i)
288 *i = ToLowerASCII(*i); 288 *i = base::ToLowerASCII(*i);
289 } 289 }
290 290
291 template <class str> inline str StringToLowerASCII(const str& s) { 291 template <class str> inline str StringToLowerASCII(const str& s) {
292 // for std::string and std::wstring 292 // for std::string and std::wstring
293 str output(s); 293 str output(s);
294 StringToLowerASCII(&output); 294 StringToLowerASCII(&output);
295 return output; 295 return output;
296 } 296 }
297 297
298 // ASCII-specific toupper. The standard library's toupper is locale sensitive, 298 // ASCII-specific toupper. The standard library's toupper is locale sensitive,
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 #elif defined(WCHAR_T_IS_UTF32) 579 #elif defined(WCHAR_T_IS_UTF32)
580 typedef uint32 Unsigned; 580 typedef uint32 Unsigned;
581 #endif 581 #endif
582 }; 582 };
583 template<> 583 template<>
584 struct ToUnsigned<short> { 584 struct ToUnsigned<short> {
585 typedef unsigned short Unsigned; 585 typedef unsigned short Unsigned;
586 }; 586 };
587 587
588 #endif // BASE_STRING_UTIL_H_ 588 #endif // BASE_STRING_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/string_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698