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> |
11 #include <cmath> | 11 #include <cmath> |
12 | 12 |
13 #include "include/v8.h" | 13 #include "include/v8.h" |
14 #include "src/allocation.h" | 14 #include "src/allocation.h" |
15 #include "src/base/bits.h" | 15 #include "src/base/bits.h" |
16 #include "src/base/logging.h" | 16 #include "src/base/logging.h" |
17 #include "src/base/macros.h" | 17 #include "src/base/macros.h" |
18 #include "src/base/platform/platform.h" | 18 #include "src/base/platform/platform.h" |
19 #include "src/globals.h" | 19 #include "src/globals.h" |
20 #include "src/list.h" | 20 #include "src/list.h" |
21 #include "src/vector.h" | 21 #include "src/vector.h" |
22 | 22 |
23 namespace v8 { | 23 namespace v8 { |
24 namespace internal { | 24 namespace internal { |
25 | 25 |
26 // ---------------------------------------------------------------------------- | 26 // ---------------------------------------------------------------------------- |
27 // General helper functions | 27 // General helper functions |
28 | 28 |
| 29 // Returns the value (0 .. 15) of a hexadecimal character c. |
| 30 // If c is not a legal hexadecimal character, returns a value < 0. |
| 31 inline int HexValue(uc32 c) { |
| 32 c -= '0'; |
| 33 if (static_cast<unsigned>(c) <= 9) return c; |
| 34 c = (c | 0x20) - ('a' - '0'); // detect 0x11..0x16 and 0x31..0x36. |
| 35 if (static_cast<unsigned>(c) <= 5) return c + 10; |
| 36 return -1; |
| 37 } |
| 38 |
29 | 39 |
30 inline int BoolToInt(bool b) { return b ? 1 : 0; } | 40 inline int BoolToInt(bool b) { return b ? 1 : 0; } |
31 | 41 |
32 | 42 |
33 // Same as strcmp, but can handle NULL arguments. | 43 // Same as strcmp, but can handle NULL arguments. |
34 inline bool CStringEquals(const char* s1, const char* s2) { | 44 inline bool CStringEquals(const char* s1, const char* s2) { |
35 return (s1 == s2) || (s1 != NULL && s2 != NULL && strcmp(s1, s2) == 0); | 45 return (s1 == s2) || (s1 != NULL && s2 != NULL && strcmp(s1, s2) == 0); |
36 } | 46 } |
37 | 47 |
38 | 48 |
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1773 uint8_t* ptr = reinterpret_cast<uint8_t*>(p); | 1783 uint8_t* ptr = reinterpret_cast<uint8_t*>(p); |
1774 *ptr = c.b[0]; | 1784 *ptr = c.b[0]; |
1775 *(ptr + 1) = c.b[1]; | 1785 *(ptr + 1) = c.b[1]; |
1776 #endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 | 1786 #endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 |
1777 } | 1787 } |
1778 | 1788 |
1779 } // namespace internal | 1789 } // namespace internal |
1780 } // namespace v8 | 1790 } // namespace v8 |
1781 | 1791 |
1782 #endif // V8_UTILS_H_ | 1792 #endif // V8_UTILS_H_ |
OLD | NEW |