Home | History | Annotate | Download | only in src
      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 
     25 struct IdentifierStart {
     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 
     35 struct IdentifierPart {
     36   static inline bool Is(uc32 c) {
     37     return IdentifierStart::Is(c)
     38         || unibrow::Number::Is(c)
     39         || c == 0x200C  // U+200C is Zero-Width Non-Joiner.
     40         || c == 0x200D  // U+200D is Zero-Width Joiner.
     41         || unibrow::CombiningMark::Is(c)
     42         || unibrow::ConnectorPunctuation::Is(c);
     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.
     55            unibrow::WhiteSpace::Is(c);
     56   }
     57 };
     58 
     59 
     60 // WhiteSpace and LineTerminator according to ECMA-262 5.1, 7.2 and 7.3.
     61 struct WhiteSpaceOrLineTerminator {
     62   static inline bool Is(uc32 c) {
     63     return WhiteSpace::Is(c) || unibrow::LineTerminator::Is(c);
     64   }
     65 };
     66 
     67 } }  // namespace v8::internal
     68 
     69 #endif  // V8_CHAR_PREDICATES_H_
     70