Changeset 4630 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp
- Timestamp:
- Jul 12, 2003, 9:01:36 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ustring.cpp
r4206 r4630 659 659 } 660 660 661 uint32_t UString::toStrictUInt32(bool *ok) const 662 { 663 if (ok) 664 *ok = false; 665 666 // Empty string is not OK. 667 int len = rep->len; 668 if (len == 0) 669 return 0; 670 const UChar *p = rep->dat; 671 unsigned short c = p->unicode(); 672 673 // If the first digit is 0, only 0 itself is OK. 674 if (c == '0') { 675 if (len == 1 && ok) 676 *ok = true; 677 return 0; 678 } 679 680 // Convert to UInt32, checking for overflow. 681 uint32_t i = 0; 682 while (1) { 683 // Process character, turning it into a digit. 684 if (c < '0' || c > '9') 685 return 0; 686 const unsigned d = c - '0'; 687 688 // Check for overflow. 689 const unsigned maxProduct = 0xFFFFFFFFU - d; 690 if (i > maxProduct / 10) 691 return 0; 692 693 // Add in another digit. 694 i *= 10; 695 i += d; 696 697 // Handle end of string. 698 if (--len == 0) { 699 if (ok) 700 *ok = true; 701 return i; 702 } 703 704 // Get next character. 705 c = (++p)->unicode(); 706 } 707 } 708 661 709 int UString::find(const UString &f, int pos) const 662 710 {
Note:
See TracChangeset
for help on using the changeset viewer.