1 // Copyright 2011 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_CHAR_PREDICATES_H_ 6 #define V8_CHAR_PREDICATES_H_ 7 8 #include "src/globals.h" 9 #include "src/unicode.h" 10 11 namespace v8 { 12 namespace internal { 13 14 // Unicode character predicates as defined by ECMA-262, 3rd, 15 // used for lexical analysis. 16 17 inline int AsciiAlphaToLower(uc32 c); 18 inline bool IsCarriageReturn(uc32 c); 19 inline bool IsLineFeed(uc32 c); 20 inline bool IsAsciiIdentifier(uc32 c); 21 inline bool IsAlphaNumeric(uc32 c); 22 inline bool IsDecimalDigit(uc32 c); 23 inline bool IsHexDigit(uc32 c); 24 inline bool IsOctalDigit(uc32 c); 25 inline bool IsBinaryDigit(uc32 c); 26 inline bool IsRegExpWord(uc32 c); 27 inline bool IsRegExpNewline(uc32 c); 28 29 // ES#sec-names-and-keywords 30 // This includes '_', '$' and '\', and ID_Start according to 31 // http://www.unicode.org/reports/tr31/, which consists of categories 32 // 'Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', but excluding properties 33 // 'Pattern_Syntax' or 'Pattern_White_Space'. 34 #ifdef V8_INTL_SUPPORT 35 struct V8_EXPORT_PRIVATE IdentifierStart { 36 static bool Is(uc32 c); 37 #else 38 struct IdentifierStart { 39 // Non-BMP characters are not supported without I18N. 40 static inline bool Is(uc32 c) { 41 return (c <= 0xFFFF) ? unibrow::ID_Start::Is(c) : false; 42 } 43 #endif 44 }; 45 46 // ES#sec-names-and-keywords 47 // This includes \u200c and \u200d, and ID_Continue according to 48 // http://www.unicode.org/reports/tr31/, which consists of ID_Start, 49 // the categories 'Mn', 'Mc', 'Nd', 'Pc', but excluding properties 50 // 'Pattern_Syntax' or 'Pattern_White_Space'. 51 #ifdef V8_INTL_SUPPORT 52 struct V8_EXPORT_PRIVATE IdentifierPart { 53 static bool Is(uc32 c); 54 #else 55 struct IdentifierPart { 56 static inline bool Is(uc32 c) { 57 // Non-BMP charaacters are not supported without I18N. 58 if (c <= 0xFFFF) { 59 return unibrow::ID_Start::Is(c) || unibrow::ID_Continue::Is(c); 60 } 61 return false; 62 } 63 #endif 64 }; 65 66 // ES6 draft section 11.2 67 // This includes all code points of Unicode category 'Zs'. 68 // Further included are \u0009, \u000b, \u000c, and \ufeff. 69 #ifdef V8_INTL_SUPPORT 70 struct V8_EXPORT_PRIVATE WhiteSpace { 71 static bool Is(uc32 c); 72 #else 73 struct WhiteSpace { 74 static inline bool Is(uc32 c) { return unibrow::WhiteSpace::Is(c); } 75 #endif 76 }; 77 78 // WhiteSpace and LineTerminator according to ES6 draft section 11.2 and 11.3 79 // This includes all the characters with Unicode category 'Z' (= Zs+Zl+Zp) 80 // as well as \u0009 - \u000d and \ufeff. 81 struct WhiteSpaceOrLineTerminator { IsWhiteSpaceOrLineTerminator82 static inline bool Is(uc32 c) { 83 return WhiteSpace::Is(c) || unibrow::IsLineTerminator(c); 84 } 85 }; 86 87 } // namespace internal 88 } // namespace v8 89 90 #endif // V8_CHAR_PREDICATES_H_ 91