OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project 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 #ifndef V8_UTILS_H_ | 5 #ifndef V8_UTILS_H_ |
6 #define V8_UTILS_H_ | 6 #define V8_UTILS_H_ |
7 | 7 |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1575 // Add formatted contents to the builder just like printf(). | 1575 // Add formatted contents to the builder just like printf(). |
1576 void AddFormatted(const char* format, ...); | 1576 void AddFormatted(const char* format, ...); |
1577 | 1577 |
1578 // Add formatted contents like printf based on a va_list. | 1578 // Add formatted contents like printf based on a va_list. |
1579 void AddFormattedList(const char* format, va_list list); | 1579 void AddFormattedList(const char* format, va_list list); |
1580 private: | 1580 private: |
1581 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 1581 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
1582 }; | 1582 }; |
1583 | 1583 |
1584 | 1584 |
| 1585 bool DoubleToBoolean(double d); |
| 1586 |
| 1587 template <typename Stream> |
| 1588 bool StringToArrayIndex(Stream* stream, uint32_t* index) { |
| 1589 uint16_t ch = stream->GetNext(); |
| 1590 |
| 1591 // If the string begins with a '0' character, it must only consist |
| 1592 // of it to be a legal array index. |
| 1593 if (ch == '0') { |
| 1594 *index = 0; |
| 1595 return !stream->HasMore(); |
| 1596 } |
| 1597 |
| 1598 // Convert string to uint32 array index; character by character. |
| 1599 int d = ch - '0'; |
| 1600 if (d < 0 || d > 9) return false; |
| 1601 uint32_t result = d; |
| 1602 while (stream->HasMore()) { |
| 1603 d = stream->GetNext() - '0'; |
| 1604 if (d < 0 || d > 9) return false; |
| 1605 // Check that the new result is below the 32 bit limit. |
| 1606 if (result > 429496729U - ((d > 5) ? 1 : 0)) return false; |
| 1607 result = (result * 10) + d; |
| 1608 } |
| 1609 |
| 1610 *index = result; |
| 1611 return true; |
| 1612 } |
| 1613 |
| 1614 |
1585 } } // namespace v8::internal | 1615 } } // namespace v8::internal |
1586 | 1616 |
1587 #endif // V8_UTILS_H_ | 1617 #endif // V8_UTILS_H_ |
OLD | NEW |