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

Side by Side Diff: base/string_number_conversions.cc

Issue 7238018: Upstream android string implementation etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update the comments in string_number_conversions.cc Created 9 years, 6 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/string_number_conversions.h" 5 #include "base/string_number_conversions.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <wctype.h> 9 #include <wctype.h>
10 10
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 } 396 }
397 397
398 bool StringToInt(std::string::const_iterator begin, 398 bool StringToInt(std::string::const_iterator begin,
399 std::string::const_iterator end, 399 std::string::const_iterator end,
400 int* output) { 400 int* output) {
401 return IteratorRangeToNumber<IteratorRangeToIntTraits>::Invoke(begin, 401 return IteratorRangeToNumber<IteratorRangeToIntTraits>::Invoke(begin,
402 end, 402 end,
403 output); 403 output);
404 } 404 }
405 405
406 #if !defined(OS_ANDROID)
darin (slow to review) 2011/06/24 16:46:05 i think it would be better to declare a #define li
michaelbai 2011/06/24 18:51:30 Thanks, Done.
407 // In Android platform, the compiler thinks std::string::const_iterator and
408 // "const char*" are equivalent types.
406 bool StringToInt(const char* begin, const char* end, int* output) { 409 bool StringToInt(const char* begin, const char* end, int* output) {
407 return IteratorRangeToNumber<CharBufferToIntTraits>::Invoke(begin, 410 return IteratorRangeToNumber<CharBufferToIntTraits>::Invoke(begin,
408 end, 411 end,
409 output); 412 output);
410 } 413 }
414 #endif
411 415
412 bool StringToInt(const string16& input, int* output) { 416 bool StringToInt(const string16& input, int* output) {
413 return IteratorRangeToNumber<WideIteratorRangeToIntTraits>::Invoke( 417 return IteratorRangeToNumber<WideIteratorRangeToIntTraits>::Invoke(
414 input.begin(), input.end(), output); 418 input.begin(), input.end(), output);
415 } 419 }
416 420
417 bool StringToInt(string16::const_iterator begin, 421 bool StringToInt(string16::const_iterator begin,
418 string16::const_iterator end, 422 string16::const_iterator end,
419 int* output) { 423 int* output) {
420 return IteratorRangeToNumber<WideIteratorRangeToIntTraits>::Invoke(begin, 424 return IteratorRangeToNumber<WideIteratorRangeToIntTraits>::Invoke(begin,
421 end, 425 end,
422 output); 426 output);
423 } 427 }
424 428
429 #if !defined(OS_ANDROID)
430 // In Android platform, the compiler thinks base::string16::const_iterator and
431 // "char16*" are equivalent types.
425 bool StringToInt(const char16* begin, const char16* end, int* output) { 432 bool StringToInt(const char16* begin, const char16* end, int* output) {
426 return IteratorRangeToNumber<WideCharBufferToIntTraits>::Invoke(begin, 433 return IteratorRangeToNumber<WideCharBufferToIntTraits>::Invoke(begin,
427 end, 434 end,
428 output); 435 output);
429 } 436 }
437 #endif
430 438
431 bool StringToInt64(const std::string& input, int64* output) { 439 bool StringToInt64(const std::string& input, int64* output) {
432 return IteratorRangeToNumber<IteratorRangeToInt64Traits>::Invoke( 440 return IteratorRangeToNumber<IteratorRangeToInt64Traits>::Invoke(
433 input.begin(), input.end(), output); 441 input.begin(), input.end(), output);
434 } 442 }
435 443
436 bool StringToInt64(std::string::const_iterator begin, 444 bool StringToInt64(std::string::const_iterator begin,
437 std::string::const_iterator end, 445 std::string::const_iterator end,
438 int64* output) { 446 int64* output) {
439 return IteratorRangeToNumber<IteratorRangeToInt64Traits>::Invoke(begin, 447 return IteratorRangeToNumber<IteratorRangeToInt64Traits>::Invoke(begin,
440 end, 448 end,
441 output); 449 output);
442 } 450 }
443 451
452 #if !defined(OS_ANDROID)
453 // In Android platform, the compiler thinks std::string::const_iterator and
454 // "char*" are equivalent types.
444 bool StringToInt64(const char* begin, const char* end, int64* output) { 455 bool StringToInt64(const char* begin, const char* end, int64* output) {
445 return IteratorRangeToNumber<CharBufferToInt64Traits>::Invoke(begin, 456 return IteratorRangeToNumber<CharBufferToInt64Traits>::Invoke(begin,
446 end, 457 end,
447 output); 458 output);
448 } 459 }
460 #endif
449 461
450 bool StringToInt64(const string16& input, int64* output) { 462 bool StringToInt64(const string16& input, int64* output) {
451 return IteratorRangeToNumber<WideIteratorRangeToInt64Traits>::Invoke( 463 return IteratorRangeToNumber<WideIteratorRangeToInt64Traits>::Invoke(
452 input.begin(), input.end(), output); 464 input.begin(), input.end(), output);
453 } 465 }
454 466
455 bool StringToInt64(string16::const_iterator begin, 467 bool StringToInt64(string16::const_iterator begin,
456 string16::const_iterator end, 468 string16::const_iterator end,
457 int64* output) { 469 int64* output) {
458 return IteratorRangeToNumber<WideIteratorRangeToInt64Traits>::Invoke(begin, 470 return IteratorRangeToNumber<WideIteratorRangeToInt64Traits>::Invoke(begin,
459 end, 471 end,
460 output); 472 output);
461 } 473 }
462 474
475 #if !defined(OS_ANDROID)
476 // In Android platform, the compiler thinks base::string16::const_iterator and
477 // "char16*" are equivalent types.
463 bool StringToInt64(const char16* begin, const char16* end, int64* output) { 478 bool StringToInt64(const char16* begin, const char16* end, int64* output) {
464 return IteratorRangeToNumber<WideCharBufferToInt64Traits>::Invoke(begin, 479 return IteratorRangeToNumber<WideCharBufferToInt64Traits>::Invoke(begin,
465 end, 480 end,
466 output); 481 output);
467 } 482 }
483 #endif
468 484
469 bool StringToDouble(const std::string& input, double* output) { 485 bool StringToDouble(const std::string& input, double* output) {
470 errno = 0; // Thread-safe? It is on at least Mac, Linux, and Windows. 486 errno = 0; // Thread-safe? It is on at least Mac, Linux, and Windows.
471 char* endptr = NULL; 487 char* endptr = NULL;
472 *output = dmg_fp::strtod(input.c_str(), &endptr); 488 *output = dmg_fp::strtod(input.c_str(), &endptr);
473 489
474 // Cases to return false: 490 // Cases to return false:
475 // - If errno is ERANGE, there was an overflow or underflow. 491 // - If errno is ERANGE, there was an overflow or underflow.
476 // - If the input string is empty, there was nothing to parse. 492 // - If the input string is empty, there was nothing to parse.
477 // - If endptr does not point to the end of the string, there are either 493 // - If endptr does not point to the end of the string, there are either
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 530 }
515 531
516 bool HexStringToInt(std::string::const_iterator begin, 532 bool HexStringToInt(std::string::const_iterator begin,
517 std::string::const_iterator end, 533 std::string::const_iterator end,
518 int* output) { 534 int* output) {
519 return IteratorRangeToNumber<HexIteratorRangeToIntTraits>::Invoke(begin, 535 return IteratorRangeToNumber<HexIteratorRangeToIntTraits>::Invoke(begin,
520 end, 536 end,
521 output); 537 output);
522 } 538 }
523 539
540 #if !defined(OS_ANDROID)
541 // In Android platform, the compiler thinks std::string::const_iterator and
542 // "char*" are equivalent types.
524 bool HexStringToInt(const char* begin, const char* end, int* output) { 543 bool HexStringToInt(const char* begin, const char* end, int* output) {
525 return IteratorRangeToNumber<HexCharBufferToIntTraits>::Invoke(begin, 544 return IteratorRangeToNumber<HexCharBufferToIntTraits>::Invoke(begin,
526 end, 545 end,
527 output); 546 output);
528 } 547 }
548 #endif
529 549
530 bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { 550 bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) {
531 return HexStringToBytesT(input, output); 551 return HexStringToBytesT(input, output);
532 } 552 }
533 553
534 } // namespace base 554 } // namespace base
OLDNEW
« base/hash_tables.h ('K') | « base/hash_tables.h ('k') | base/string_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698