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

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

Issue 270183002: Move IsStringUTF8/ASCII to base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more minor nit Created 6 years, 7 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/files/file_path.cc ('k') | base/strings/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 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 const std::string& text, 227 const std::string& text,
228 bool trim_sequences_with_line_breaks); 228 bool trim_sequences_with_line_breaks);
229 229
230 // Returns true if |input| is empty or contains only characters found in 230 // Returns true if |input| is empty or contains only characters found in
231 // |characters|. 231 // |characters|.
232 BASE_EXPORT bool ContainsOnlyChars(const StringPiece& input, 232 BASE_EXPORT bool ContainsOnlyChars(const StringPiece& input,
233 const StringPiece& characters); 233 const StringPiece& characters);
234 BASE_EXPORT bool ContainsOnlyChars(const StringPiece16& input, 234 BASE_EXPORT bool ContainsOnlyChars(const StringPiece16& input,
235 const StringPiece16& characters); 235 const StringPiece16& characters);
236 236
237 } // namespace base
238
239 #if defined(OS_WIN)
240 #include "base/strings/string_util_win.h"
241 #elif defined(OS_POSIX)
242 #include "base/strings/string_util_posix.h"
243 #else
244 #error Define string operations appropriately for your platform
245 #endif
246
247 // Returns true if the specified string matches the criteria. How can a wide 237 // Returns true if the specified string matches the criteria. How can a wide
248 // string be 8-bit or UTF8? It contains only characters that are < 256 (in the 238 // string be 8-bit or UTF8? It contains only characters that are < 256 (in the
249 // first case) or characters that use only 8-bits and whose 8-bit 239 // first case) or characters that use only 8-bits and whose 8-bit
250 // representation looks like a UTF-8 string (the second case). 240 // representation looks like a UTF-8 string (the second case).
251 // 241 //
252 // Note that IsStringUTF8 checks not only if the input is structurally 242 // Note that IsStringUTF8 checks not only if the input is structurally
253 // 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
254 // (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
255 // to have the maximum 'discriminating' power from other encodings. If 245 // to have the maximum 'discriminating' power from other encodings. If
256 // 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
257 // add a new function for that. 247 // add a new function for that.
258 BASE_EXPORT bool IsStringUTF8(const std::string& str); 248 BASE_EXPORT bool IsStringUTF8(const std::string& str);
259 BASE_EXPORT bool IsStringASCII(const base::StringPiece& str); 249 BASE_EXPORT bool IsStringASCII(const StringPiece& str);
260 BASE_EXPORT bool IsStringASCII(const base::string16& str); 250 BASE_EXPORT bool IsStringASCII(const string16& str);
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 261
262 // Converts the elements of the given string. This version uses a pointer to 262 // Converts the elements of the given string. This version uses a pointer to
263 // clearly differentiate it from the non-pointer variant. 263 // clearly differentiate it from the non-pointer variant.
264 template <class str> inline void StringToLowerASCII(str* s) { 264 template <class str> inline void StringToLowerASCII(str* s) {
265 for (typename str::iterator i = s->begin(); i != s->end(); ++i) 265 for (typename str::iterator i = s->begin(); i != s->end(); ++i)
266 *i = base::ToLowerASCII(*i); 266 *i = base::ToLowerASCII(*i);
267 } 267 }
268 268
269 template <class str> inline str StringToLowerASCII(const str& s) { 269 template <class str> inline str StringToLowerASCII(const str& s) {
270 // for std::string and std::wstring 270 // for std::string and std::wstring
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 #elif defined(WCHAR_T_IS_UTF32) 515 #elif defined(WCHAR_T_IS_UTF32)
516 typedef uint32 Unsigned; 516 typedef uint32 Unsigned;
517 #endif 517 #endif
518 }; 518 };
519 template<> 519 template<>
520 struct ToUnsigned<short> { 520 struct ToUnsigned<short> {
521 typedef unsigned short Unsigned; 521 typedef unsigned short Unsigned;
522 }; 522 };
523 523
524 #endif // BASE_STRINGS_STRING_UTIL_H_ 524 #endif // BASE_STRINGS_STRING_UTIL_H_
OLDNEW
« no previous file with comments | « base/files/file_path.cc ('k') | base/strings/string_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698