blob: fadbc9afbea671c95eda7d4b088a07e31d6d7d7d [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_CHAR_PREDICATES_INL_H_
29#define V8_CHAR_PREDICATES_INL_H_
30
31#include "char-predicates.h"
32
33namespace v8 {
34namespace internal {
35
36
37inline bool IsCarriageReturn(uc32 c) {
38 return c == 0x000D;
39}
40
41
42inline bool IsLineFeed(uc32 c) {
43 return c == 0x000A;
44}
45
46
47static inline bool IsInRange(int value, int lower_limit, int higher_limit) {
48 ASSERT(lower_limit <= higher_limit);
49 return static_cast<unsigned int>(value - lower_limit) <=
50 static_cast<unsigned int>(higher_limit - lower_limit);
51}
52
53
54inline bool IsDecimalDigit(uc32 c) {
55 // ECMA-262, 3rd, 7.8.3 (p 16)
56 return IsInRange(c, '0', '9');
57}
58
59
60inline bool IsHexDigit(uc32 c) {
61 // ECMA-262, 3rd, 7.6 (p 15)
62 return IsDecimalDigit(c) || IsInRange(c | 0x20, 'a', 'f');
63}
64
65
66inline bool IsRegExpWord(uc16 c) {
67 return IsInRange(c | 0x20, 'a', 'z')
68 || IsDecimalDigit(c)
69 || (c == '_');
70}
71
72
73inline bool IsRegExpNewline(uc16 c) {
74 switch (c) {
75 // CR LF LS PS
76 case 0x000A: case 0x000D: case 0x2028: case 0x2029:
77 return false;
78 default:
79 return true;
80 }
81}
82
83
84} } // namespace v8::internal
85
86#endif // V8_CHAR_PREDICATES_INL_H_