5 #ifndef V8_CHAR_PREDICATES_INL_H_ 6 #define V8_CHAR_PREDICATES_INL_H_ 8 #include "src/char-predicates.h" 17 inline constexpr
int AsciiAlphaToLower(uc32 c) {
return c | 0x20; }
19 inline constexpr
bool IsCarriageReturn(uc32 c) {
return c == 0x000D; }
21 inline constexpr
bool IsLineFeed(uc32 c) {
return c == 0x000A; }
23 inline constexpr
bool IsAsciiIdentifier(uc32 c) {
24 return IsAlphaNumeric(c) || c ==
'$' || c ==
'_';
27 inline constexpr
bool IsAlphaNumeric(uc32 c) {
28 return IsInRange(AsciiAlphaToLower(c),
'a',
'z') || IsDecimalDigit(c);
31 inline constexpr
bool IsDecimalDigit(uc32 c) {
33 return IsInRange(c,
'0',
'9');
36 inline constexpr
bool IsHexDigit(uc32 c) {
38 return IsDecimalDigit(c) || IsInRange(AsciiAlphaToLower(c),
'a',
'f');
41 inline constexpr
bool IsOctalDigit(uc32 c) {
43 return IsInRange(c,
'0',
'7');
46 inline constexpr
bool IsNonOctalDecimalDigit(uc32 c) {
47 return IsInRange(c,
'8',
'9');
50 inline constexpr
bool IsBinaryDigit(uc32 c) {
52 return c ==
'0' || c ==
'1';
55 inline constexpr
bool IsRegExpWord(uc16 c) {
56 return IsInRange(AsciiAlphaToLower(c),
'a',
'z')
61 inline constexpr
bool IsRegExpNewline(uc16 c) {
63 return c != 0x000A && c != 0x000D && c != 0x2028 && c != 0x2029;
68 kIsIdentifierStart = 1 << 0,
69 kIsIdentifierPart = 1 << 1,
70 kIsWhiteSpace = 1 << 2,
71 kIsWhiteSpaceOrLineTerminator = 1 << 3
73 constexpr uint8_t BuildAsciiCharFlags(uc32 c) {
76 (IsAsciiIdentifier(c) || c ==
'\\') ? (
77 kIsIdentifierPart | (!IsDecimalDigit(c) ? kIsIdentifierStart : 0)) : 0 |
78 (c ==
' ' || c ==
'\t' || c ==
'\v' || c ==
'\f') ?
79 kIsWhiteSpace | kIsWhiteSpaceOrLineTerminator : 0 |
80 (c ==
'\r' || c ==
'\n') ? kIsWhiteSpaceOrLineTerminator : 0;
83 const constexpr uint8_t kAsciiCharFlags[128] = {
84 #define BUILD_CHAR_FLAGS(N) BuildAsciiCharFlags(N), 85 INT_0_TO_127_LIST(BUILD_CHAR_FLAGS)
86 #undef BUILD_CHAR_FLAGS 89 bool IsIdentifierStart(uc32 c) {
90 if (!IsInRange(c, 0, 127))
return IsIdentifierStartSlow(c);
91 DCHECK_EQ(IsIdentifierStartSlow(c),
92 static_cast<bool>(kAsciiCharFlags[c] & kIsIdentifierStart));
93 return kAsciiCharFlags[c] & kIsIdentifierStart;
96 bool IsIdentifierPart(uc32 c) {
97 if (!IsInRange(c, 0, 127))
return IsIdentifierPartSlow(c);
98 DCHECK_EQ(IsIdentifierPartSlow(c),
99 static_cast<bool>(kAsciiCharFlags[c] & kIsIdentifierPart));
100 return kAsciiCharFlags[c] & kIsIdentifierPart;
103 bool IsWhiteSpace(uc32 c) {
104 if (!IsInRange(c, 0, 127))
return IsWhiteSpaceSlow(c);
105 DCHECK_EQ(IsWhiteSpaceSlow(c),
106 static_cast<bool>(kAsciiCharFlags[c] & kIsWhiteSpace));
107 return kAsciiCharFlags[c] & kIsWhiteSpace;
110 bool IsWhiteSpaceOrLineTerminator(uc32 c) {
111 if (!IsInRange(c, 0, 127))
return IsWhiteSpaceOrLineTerminatorSlow(c);
113 IsWhiteSpaceOrLineTerminatorSlow(c),
114 static_cast<bool>(kAsciiCharFlags[c] & kIsWhiteSpaceOrLineTerminator));
115 return kAsciiCharFlags[c] & kIsWhiteSpaceOrLineTerminator;
118 bool IsLineTerminatorSequence(uc32 c, uc32 next) {
119 if (!unibrow::IsLineTerminator(c))
return false;
120 if (c == 0x000d && next == 0x000a)
return false;
127 #endif // V8_CHAR_PREDICATES_INL_H_