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.
5 #ifndef V8_CHAR_PREDICATES_H_
6 #define V8_CHAR_PREDICATES_H_
8 #include "src/unicode.h"
13 // Unicode character predicates as defined by ECMA-262, 3rd,
14 // used for lexical analysis.
16 inline bool IsCarriageReturn(uc32 c);
17 inline bool IsLineFeed(uc32 c);
18 inline bool IsDecimalDigit(uc32 c);
19 inline bool IsHexDigit(uc32 c);
20 inline bool IsOctalDigit(uc32 c);
21 inline bool IsBinaryDigit(uc32 c);
22 inline bool IsRegExpWord(uc32 c);
23 inline bool IsRegExpNewline(uc32 c);
26 struct SupplementaryPlanes {
27 static bool IsIDStart(uc32 c);
28 static bool IsIDPart(uc32 c);
32 // ES6 draft section 11.6
33 // This includes '_', '$' and '\', and ID_Start according to
34 // http://www.unicode.org/reports/tr31/, which consists of categories
35 // 'Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', but excluding properties
36 // 'Pattern_Syntax' or 'Pattern_White_Space'.
37 // For code points in the SMPs, we can resort to ICU (if available).
38 struct IdentifierStart {
39 static inline bool Is(uc32 c) {
40 if (c > 0xFFFF) return SupplementaryPlanes::IsIDStart(c);
41 return unibrow::ID_Start::Is(c);
46 // ES6 draft section 11.6
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 // For code points in the SMPs, we can resort to ICU (if available).
52 struct IdentifierPart {
53 static inline bool Is(uc32 c) {
54 if (c > 0xFFFF) return SupplementaryPlanes::IsIDPart(c);
55 return unibrow::ID_Start::Is(c) || unibrow::ID_Continue::Is(c);
60 // ES6 draft section 11.2
61 // This includes all code points of Unicode category 'Zs'.
62 // \u180e stops being one as of Unicode 6.3.0, but ES6 adheres to Unicode 5.1,
63 // so it is also included.
64 // Further included are \u0009, \u000b, \u0020, \u00a0, \u000c, and \ufeff.
65 // There are no category 'Zs' code points in the SMPs.
67 static inline bool Is(uc32 c) { return unibrow::WhiteSpace::Is(c); }
71 // WhiteSpace and LineTerminator according to ES6 draft section 11.2 and 11.3
72 // This consists of \000a, \000d, \u2028, and \u2029.
73 struct WhiteSpaceOrLineTerminator {
74 static inline bool Is(uc32 c) {
75 return WhiteSpace::Is(c) || unibrow::LineTerminator::Is(c);
79 } } // namespace v8::internal
81 #endif // V8_CHAR_PREDICATES_H_