V8 Project
char-predicates.h
Go to the documentation of this file.
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/unicode.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 // Unicode character predicates as defined by ECMA-262, 3rd,
14 // used for lexical analysis.
15 
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);
24 
26  static inline bool Is(uc32 c) {
27  switch (c) {
28  case '$': case '_': case '\\': return true;
29  default: return unibrow::Letter::Is(c);
30  }
31  }
32 };
33 
34 
36  static inline bool Is(uc32 c) {
37  return IdentifierStart::Is(c)
39  || c == 0x200C // U+200C is Zero-Width Non-Joiner.
40  || c == 0x200D // U+200D is Zero-Width Joiner.
43  }
44 };
45 
46 
47 // WhiteSpace according to ECMA-262 5.1, 7.2.
48 struct WhiteSpace {
49  static inline bool Is(uc32 c) {
50  return c == 0x0009 || // <TAB>
51  c == 0x000B || // <VT>
52  c == 0x000C || // <FF>
53  c == 0xFEFF || // <BOM>
54  // \u0020 and \u00A0 are included in unibrow::WhiteSpace.
56  }
57 };
58 
59 
60 // WhiteSpace and LineTerminator according to ECMA-262 5.1, 7.2 and 7.3.
62  static inline bool Is(uc32 c) {
64  }
65 };
66 
67 } } // namespace v8::internal
68 
69 #endif // V8_CHAR_PREDICATES_H_
bool IsDecimalDigit(uc32 c)
bool IsCarriageReturn(uc32 c)
bool IsLineFeed(uc32 c)
bool IsOctalDigit(uc32 c)
bool IsHexDigit(uc32 c)
bool IsRegExpNewline(uc16 c)
bool IsRegExpWord(uc16 c)
bool IsBinaryDigit(uc32 c)
int32_t uc32
Definition: globals.h:185
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
static bool Is(uchar c)
Definition: unicode.cc:821
static bool Is(uchar c)
Definition: unicode.cc:852
static bool Is(uchar c)
Definition: unicode.cc:658
static bool Is(uchar c)
Definition: unicode.cc:755
static bool Is(uchar c)
Definition: unicode.cc:708
static bool Is(uchar c)
Definition: unicode.cc:733
static bool Is(uc32 c)
Definitions and convenience functions for working with unicode.