2011-11-29 10:56:11 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#ifndef V8_CHAR_PREDICATES_INL_H_
|
|
|
|
#define V8_CHAR_PREDICATES_INL_H_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/char-predicates.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2010-09-03 12:59:52 +00:00
|
|
|
// If c is in 'A'-'Z' or 'a'-'z', return its lower-case.
|
|
|
|
// Else, return something outside of 'A'-'Z' and 'a'-'z'.
|
|
|
|
// Note: it ignores LOCALE.
|
|
|
|
inline int AsciiAlphaToLower(uc32 c) {
|
|
|
|
return c | 0x20;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
inline bool IsCarriageReturn(uc32 c) {
|
|
|
|
return c == 0x000D;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsLineFeed(uc32 c) {
|
|
|
|
return c == 0x000A;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-29 10:56:11 +00:00
|
|
|
inline bool IsInRange(int value, int lower_limit, int higher_limit) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(lower_limit <= higher_limit);
|
2009-03-17 13:27:21 +00:00
|
|
|
return static_cast<unsigned int>(value - lower_limit) <=
|
|
|
|
static_cast<unsigned int>(higher_limit - lower_limit);
|
|
|
|
}
|
|
|
|
|
2015-03-03 15:27:46 +00:00
|
|
|
inline bool IsAsciiIdentifier(uc32 c) {
|
|
|
|
return IsAlphaNumeric(c) || c == '$' || c == '_';
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsAlphaNumeric(uc32 c) {
|
|
|
|
return IsInRange(AsciiAlphaToLower(c), 'a', 'z') || IsDecimalDigit(c);
|
|
|
|
}
|
2009-03-17 13:27:21 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
inline bool IsDecimalDigit(uc32 c) {
|
|
|
|
// ECMA-262, 3rd, 7.8.3 (p 16)
|
2009-03-17 13:27:21 +00:00
|
|
|
return IsInRange(c, '0', '9');
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsHexDigit(uc32 c) {
|
|
|
|
// ECMA-262, 3rd, 7.6 (p 15)
|
2010-09-03 12:59:52 +00:00
|
|
|
return IsDecimalDigit(c) || IsInRange(AsciiAlphaToLower(c), 'a', 'f');
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-19 09:57:35 +00:00
|
|
|
inline bool IsOctalDigit(uc32 c) {
|
|
|
|
// ECMA-262, 6th, 7.8.3
|
|
|
|
return IsInRange(c, '0', '7');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsBinaryDigit(uc32 c) {
|
|
|
|
// ECMA-262, 6th, 7.8.3
|
|
|
|
return c == '0' || c == '1';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-01 15:42:35 +00:00
|
|
|
inline bool IsRegExpWord(uc16 c) {
|
2010-09-03 12:59:52 +00:00
|
|
|
return IsInRange(AsciiAlphaToLower(c), 'a', 'z')
|
2009-03-17 13:27:21 +00:00
|
|
|
|| IsDecimalDigit(c)
|
2008-12-01 15:42:35 +00:00
|
|
|
|| (c == '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsRegExpNewline(uc16 c) {
|
|
|
|
switch (c) {
|
|
|
|
// CR LF LS PS
|
|
|
|
case 0x000A: case 0x000D: case 0x2028: case 0x2029:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#endif // V8_CHAR_PREDICATES_INL_H_
|