OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 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 | 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_INTL_SUPPORT |
| 6 #error Internationalization is expected to be enabled. |
| 7 #endif // V8_INTL_SUPPORT |
| 8 |
5 #include "src/char-predicates.h" | 9 #include "src/char-predicates.h" |
6 | 10 |
7 #ifdef V8_INTL_SUPPORT | |
8 #include "unicode/uchar.h" | 11 #include "unicode/uchar.h" |
9 #include "unicode/urename.h" | 12 #include "unicode/urename.h" |
10 #endif // V8_INTL_SUPPORT | |
11 | 13 |
12 namespace v8 { | 14 namespace v8 { |
13 namespace internal { | 15 namespace internal { |
14 | 16 |
15 bool SupplementaryPlanes::IsIDStart(uc32 c) { | 17 // ES#sec-names-and-keywords Names and Keywords |
16 DCHECK(c > 0xFFFF); | 18 // UnicodeIDStart, '$', '_' and '\' |
17 #ifdef V8_INTL_SUPPORT | 19 bool IdentifierStart::Is(uc32 c) { |
18 // This only works for code points in the SMPs, since ICU does not exclude | 20 // cannot use u_isIDStart because it does not work for |
19 // code points with properties 'Pattern_Syntax' or 'Pattern_White_Space'. | 21 // Other_ID_Start characters. |
20 // Code points in the SMP do not have those properties. | 22 return u_hasBinaryProperty(c, UCHAR_ID_START) || |
21 return u_isIDStart(c); | 23 (c < 0x60 && (c == '$' || c == '\\' || c == '_')); |
22 #else | |
23 // This is incorrect, but if we don't have ICU, use this as fallback. | |
24 return false; | |
25 #endif // V8_INTL_SUPPORT | |
26 } | 24 } |
27 | 25 |
| 26 // ES#sec-names-and-keywords Names and Keywords |
| 27 // UnicodeIDContinue, '$', '_', '\', ZWJ, and ZWNJ |
| 28 bool IdentifierPart::Is(uc32 c) { |
| 29 // Can't use u_isIDPart because it does not work for |
| 30 // Other_ID_Continue characters. |
| 31 return u_hasBinaryProperty(c, UCHAR_ID_CONTINUE) || |
| 32 (c < 0x60 && (c == '$' || c == '\\' || c == '_')) || c == 0x200C || |
| 33 c == 0x200D; |
| 34 } |
28 | 35 |
29 bool SupplementaryPlanes::IsIDPart(uc32 c) { | 36 // ES#sec-white-space White Space |
30 DCHECK(c > 0xFFFF); | 37 // gC=Zs, U+0009, U+000B, U+000C, U+FEFF |
31 #ifdef V8_INTL_SUPPORT | 38 bool WhiteSpace::Is(uc32 c) { |
32 // This only works for code points in the SMPs, since ICU does not exclude | 39 return (u_charType(c) == U_SPACE_SEPARATOR) || |
33 // code points with properties 'Pattern_Syntax' or 'Pattern_White_Space'. | 40 (c < 0x0D && (c == 0x09 || c == 0x0B || c == 0x0C)) || c == 0xFEFF; |
34 // Code points in the SMP do not have those properties. | |
35 return u_isIDPart(c); | |
36 #else | |
37 // This is incorrect, but if we don't have ICU, use this as fallback. | |
38 return false; | |
39 #endif // V8_INTL_SUPPORT | |
40 } | 41 } |
| 42 |
41 } // namespace internal | 43 } // namespace internal |
42 } // namespace v8 | 44 } // namespace v8 |
OLD | NEW |