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 19 matching lines...) Expand all Loading... |
30 // Returns the value (0 .. 15) of a hexadecimal character c. | 30 // Returns the value (0 .. 15) of a hexadecimal character c. |
31 // If c is not a legal hexadecimal character, returns a value < 0. | 31 // If c is not a legal hexadecimal character, returns a value < 0. |
32 inline int HexValue(uc32 c) { | 32 inline int HexValue(uc32 c) { |
33 c -= '0'; | 33 c -= '0'; |
34 if (static_cast<unsigned>(c) <= 9) return c; | 34 if (static_cast<unsigned>(c) <= 9) return c; |
35 c = (c | 0x20) - ('a' - '0'); // detect 0x11..0x16 and 0x31..0x36. | 35 c = (c | 0x20) - ('a' - '0'); // detect 0x11..0x16 and 0x31..0x36. |
36 if (static_cast<unsigned>(c) <= 5) return c + 10; | 36 if (static_cast<unsigned>(c) <= 5) return c + 10; |
37 return -1; | 37 return -1; |
38 } | 38 } |
39 | 39 |
| 40 inline char HexCharOfValue(int value) { |
| 41 DCHECK(0 <= value && value <= 16); |
| 42 if (value < 10) return value + '0'; |
| 43 return value - 10 + 'A'; |
| 44 } |
40 | 45 |
41 inline int BoolToInt(bool b) { return b ? 1 : 0; } | 46 inline int BoolToInt(bool b) { return b ? 1 : 0; } |
42 | 47 |
43 | 48 |
44 // Same as strcmp, but can handle NULL arguments. | 49 // Same as strcmp, but can handle NULL arguments. |
45 inline bool CStringEquals(const char* s1, const char* s2) { | 50 inline bool CStringEquals(const char* s1, const char* s2) { |
46 return (s1 == s2) || (s1 != NULL && s2 != NULL && strcmp(s1, s2) == 0); | 51 return (s1 == s2) || (s1 != NULL && s2 != NULL && strcmp(s1, s2) == 0); |
47 } | 52 } |
48 | 53 |
49 | 54 |
(...skipping 1490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1540 } | 1545 } |
1541 | 1546 |
1542 static inline void WriteUnalignedUInt32(void* p, uint32_t value) { | 1547 static inline void WriteUnalignedUInt32(void* p, uint32_t value) { |
1543 WriteUnalignedValue(p, value); | 1548 WriteUnalignedValue(p, value); |
1544 } | 1549 } |
1545 | 1550 |
1546 } // namespace internal | 1551 } // namespace internal |
1547 } // namespace v8 | 1552 } // namespace v8 |
1548 | 1553 |
1549 #endif // V8_UTILS_H_ | 1554 #endif // V8_UTILS_H_ |
OLD | NEW |