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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 // Note that IsStringUTF8 checks not only if the input is structurally | 252 // Note that IsStringUTF8 checks not only if the input is structurally |
253 // valid but also if it doesn't contain any non-character codepoint | 253 // 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 | 254 // (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 | 255 // 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 | 256 // there's a use case for just checking the structural validity, we have to |
257 // add a new function for that. | 257 // add a new function for that. |
258 BASE_EXPORT bool IsStringUTF8(const std::string& str); | 258 BASE_EXPORT bool IsStringUTF8(const std::string& str); |
259 BASE_EXPORT bool IsStringASCII(const base::StringPiece& str); | 259 BASE_EXPORT bool IsStringASCII(const base::StringPiece& str); |
260 BASE_EXPORT bool IsStringASCII(const base::string16& str); | 260 BASE_EXPORT bool IsStringASCII(const base::string16& str); |
261 | 261 |
| 262 BASE_EXPORT bool IsUpperCaseHexNumber(const std::string& number); |
| 263 |
262 // Converts the elements of the given string. This version uses a pointer to | 264 // Converts the elements of the given string. This version uses a pointer to |
263 // clearly differentiate it from the non-pointer variant. | 265 // clearly differentiate it from the non-pointer variant. |
264 template <class str> inline void StringToLowerASCII(str* s) { | 266 template <class str> inline void StringToLowerASCII(str* s) { |
265 for (typename str::iterator i = s->begin(); i != s->end(); ++i) | 267 for (typename str::iterator i = s->begin(); i != s->end(); ++i) |
266 *i = base::ToLowerASCII(*i); | 268 *i = base::ToLowerASCII(*i); |
267 } | 269 } |
268 | 270 |
269 template <class str> inline str StringToLowerASCII(const str& s) { | 271 template <class str> inline str StringToLowerASCII(const str& s) { |
270 // for std::string and std::wstring | 272 // for std::string and std::wstring |
271 str output(s); | 273 str output(s); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 347 } |
346 | 348 |
347 template <typename Char> | 349 template <typename Char> |
348 inline bool IsHexDigit(Char c) { | 350 inline bool IsHexDigit(Char c) { |
349 return (c >= '0' && c <= '9') || | 351 return (c >= '0' && c <= '9') || |
350 (c >= 'A' && c <= 'F') || | 352 (c >= 'A' && c <= 'F') || |
351 (c >= 'a' && c <= 'f'); | 353 (c >= 'a' && c <= 'f'); |
352 } | 354 } |
353 | 355 |
354 template <typename Char> | 356 template <typename Char> |
| 357 inline bool IsUpperCaseHexDigit(Char c) { |
| 358 return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F'); |
| 359 } |
| 360 |
| 361 template <typename Char> |
355 inline Char HexDigitToInt(Char c) { | 362 inline Char HexDigitToInt(Char c) { |
356 DCHECK(IsHexDigit(c)); | 363 DCHECK(IsHexDigit(c)); |
357 if (c >= '0' && c <= '9') | 364 if (c >= '0' && c <= '9') |
358 return c - '0'; | 365 return c - '0'; |
359 if (c >= 'A' && c <= 'F') | 366 if (c >= 'A' && c <= 'F') |
360 return c - 'A' + 10; | 367 return c - 'A' + 10; |
361 if (c >= 'a' && c <= 'f') | 368 if (c >= 'a' && c <= 'f') |
362 return c - 'a' + 10; | 369 return c - 'a' + 10; |
363 return 0; | 370 return 0; |
364 } | 371 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 #elif defined(WCHAR_T_IS_UTF32) | 522 #elif defined(WCHAR_T_IS_UTF32) |
516 typedef uint32 Unsigned; | 523 typedef uint32 Unsigned; |
517 #endif | 524 #endif |
518 }; | 525 }; |
519 template<> | 526 template<> |
520 struct ToUnsigned<short> { | 527 struct ToUnsigned<short> { |
521 typedef unsigned short Unsigned; | 528 typedef unsigned short Unsigned; |
522 }; | 529 }; |
523 | 530 |
524 #endif // BASE_STRINGS_STRING_UTIL_H_ | 531 #endif // BASE_STRINGS_STRING_UTIL_H_ |
OLD | NEW |