OLD | NEW |
---|---|
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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 // 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 |
239 // 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 |
240 // representation looks like a UTF-8 string (the second case). | 240 // representation looks like a UTF-8 string (the second case). |
241 // | 241 // |
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 // | |
249 // IsStringASCII assumes the input is likely all ASCII, and does not leave early | |
250 // if it is not the case. | |
248 BASE_EXPORT bool IsStringUTF8(const std::string& str); | 251 BASE_EXPORT bool IsStringUTF8(const std::string& str); |
249 BASE_EXPORT bool IsStringASCII(const StringPiece& str); | 252 BASE_EXPORT bool IsStringASCII(const StringPiece& str); |
250 BASE_EXPORT bool IsStringASCII(const string16& str); | 253 BASE_EXPORT bool IsStringASCII(const string16& str); |
254 BASE_EXPORT bool IsStringASCII(const char* src, size_t src_len); | |
brettw
2014/09/16 17:14:28
The string piece version should cover this case. A
mnaganov (inactive)
2014/09/17 15:15:01
You are right, I didn't think about this, thanks!
| |
255 BASE_EXPORT bool IsStringASCII(const char16* src, size_t src_len); | |
251 | 256 |
252 // Converts the elements of the given string. This version uses a pointer to | 257 // Converts the elements of the given string. This version uses a pointer to |
253 // clearly differentiate it from the non-pointer variant. | 258 // clearly differentiate it from the non-pointer variant. |
254 template <class str> inline void StringToLowerASCII(str* s) { | 259 template <class str> inline void StringToLowerASCII(str* s) { |
255 for (typename str::iterator i = s->begin(); i != s->end(); ++i) | 260 for (typename str::iterator i = s->begin(); i != s->end(); ++i) |
256 *i = ToLowerASCII(*i); | 261 *i = ToLowerASCII(*i); |
257 } | 262 } |
258 | 263 |
259 template <class str> inline str StringToLowerASCII(const str& s) { | 264 template <class str> inline str StringToLowerASCII(const str& s) { |
260 // for std::string and std::wstring | 265 // for std::string and std::wstring |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 #elif defined(WCHAR_T_IS_UTF32) | 519 #elif defined(WCHAR_T_IS_UTF32) |
515 typedef uint32 Unsigned; | 520 typedef uint32 Unsigned; |
516 #endif | 521 #endif |
517 }; | 522 }; |
518 template<> | 523 template<> |
519 struct ToUnsigned<short> { | 524 struct ToUnsigned<short> { |
520 typedef unsigned short Unsigned; | 525 typedef unsigned short Unsigned; |
521 }; | 526 }; |
522 | 527 |
523 #endif // BASE_STRINGS_STRING_UTIL_H_ | 528 #endif // BASE_STRINGS_STRING_UTIL_H_ |
OLD | NEW |