| 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 #include "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <math.h> | 9 #include <math.h> |
| 10 #include <stdarg.h> | 10 #include <stdarg.h> |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 bool ContainsOnlyChars(const StringPiece& input, | 317 bool ContainsOnlyChars(const StringPiece& input, |
| 318 const StringPiece& characters) { | 318 const StringPiece& characters) { |
| 319 return input.find_first_not_of(characters) == StringPiece::npos; | 319 return input.find_first_not_of(characters) == StringPiece::npos; |
| 320 } | 320 } |
| 321 | 321 |
| 322 bool ContainsOnlyChars(const StringPiece16& input, | 322 bool ContainsOnlyChars(const StringPiece16& input, |
| 323 const StringPiece16& characters) { | 323 const StringPiece16& characters) { |
| 324 return input.find_first_not_of(characters) == StringPiece16::npos; | 324 return input.find_first_not_of(characters) == StringPiece16::npos; |
| 325 } | 325 } |
| 326 | 326 |
| 327 } // namespace base | |
| 328 | |
| 329 template<class STR> | 327 template<class STR> |
| 330 static bool DoIsStringASCII(const STR& str) { | 328 static bool DoIsStringASCII(const STR& str) { |
| 331 for (size_t i = 0; i < str.length(); i++) { | 329 for (size_t i = 0; i < str.length(); i++) { |
| 332 typename ToUnsigned<typename STR::value_type>::Unsigned c = str[i]; | 330 typename ToUnsigned<typename STR::value_type>::Unsigned c = str[i]; |
| 333 if (c > 0x7F) | 331 if (c > 0x7F) |
| 334 return false; | 332 return false; |
| 335 } | 333 } |
| 336 return true; | 334 return true; |
| 337 } | 335 } |
| 338 | 336 |
| 339 bool IsStringASCII(const base::StringPiece& str) { | 337 bool IsStringASCII(const StringPiece& str) { |
| 340 return DoIsStringASCII(str); | 338 return DoIsStringASCII(str); |
| 341 } | 339 } |
| 342 | 340 |
| 343 bool IsStringASCII(const base::string16& str) { | 341 bool IsStringASCII(const string16& str) { |
| 344 return DoIsStringASCII(str); | 342 return DoIsStringASCII(str); |
| 345 } | 343 } |
| 346 | 344 |
| 347 bool IsStringUTF8(const std::string& str) { | 345 bool IsStringUTF8(const std::string& str) { |
| 348 const char *src = str.data(); | 346 const char *src = str.data(); |
| 349 int32 src_len = static_cast<int32>(str.length()); | 347 int32 src_len = static_cast<int32>(str.length()); |
| 350 int32 char_index = 0; | 348 int32 char_index = 0; |
| 351 | 349 |
| 352 while (char_index < src_len) { | 350 while (char_index < src_len) { |
| 353 int32 code_point; | 351 int32 code_point; |
| 354 CBU8_NEXT(src, char_index, src_len, code_point); | 352 CBU8_NEXT(src, char_index, src_len, code_point); |
| 355 if (!base::IsValidCharacter(code_point)) | 353 if (!IsValidCharacter(code_point)) |
| 356 return false; | 354 return false; |
| 357 } | 355 } |
| 358 return true; | 356 return true; |
| 359 } | 357 } |
| 360 | 358 |
| 359 } // namespace base |
| 360 |
| 361 template<typename Iter> | 361 template<typename Iter> |
| 362 static inline bool DoLowerCaseEqualsASCII(Iter a_begin, | 362 static inline bool DoLowerCaseEqualsASCII(Iter a_begin, |
| 363 Iter a_end, | 363 Iter a_end, |
| 364 const char* b) { | 364 const char* b) { |
| 365 for (Iter it = a_begin; it != a_end; ++it, ++b) { | 365 for (Iter it = a_begin; it != a_end; ++it, ++b) { |
| 366 if (!*b || base::ToLowerASCII(*it) != *b) | 366 if (!*b || base::ToLowerASCII(*it) != *b) |
| 367 return false; | 367 return false; |
| 368 } | 368 } |
| 369 return *b == 0; | 369 return *b == 0; |
| 370 } | 370 } |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 } | 887 } |
| 888 | 888 |
| 889 } // namespace | 889 } // namespace |
| 890 | 890 |
| 891 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { | 891 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { |
| 892 return lcpyT<char>(dst, src, dst_size); | 892 return lcpyT<char>(dst, src, dst_size); |
| 893 } | 893 } |
| 894 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { | 894 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { |
| 895 return lcpyT<wchar_t>(dst, src, dst_size); | 895 return lcpyT<wchar_t>(dst, src, dst_size); |
| 896 } | 896 } |
| OLD | NEW |