Add lit_char_is_octal_digit, lit_char_is_decimal_digit, lit_char_is_hex_digit helpers.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
@@ -253,36 +253,51 @@ lit_char_is_unicode_connector_punctuation (ecma_char_t c) /**< code unit */
|
|||||||
} /* lit_char_is_unicode_connector_punctuation */
|
} /* lit_char_is_unicode_connector_punctuation */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if specified character is a word character (part of IsWordChar abstract operation)
|
* Check if specified character is one of OctalDigit characters (ECMA-262 v5, B.1.2)
|
||||||
*
|
*
|
||||||
* See also: ECMA-262 v5, 15.10.2.6 (IsWordChar)
|
* @return true / false
|
||||||
*
|
|
||||||
* @return true - if the character is a word character
|
|
||||||
* false - otherwise.
|
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
lit_char_is_word_char (ecma_char_t c) /**< code unit */
|
lit_char_is_octal_digit (ecma_char_t c) /**< code unit */
|
||||||
{
|
{
|
||||||
if ((c >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_BEGIN && c <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_END)
|
return (c >= LIT_CHAR_ASCII_OCTAL_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_OCTAL_DIGITS_END);
|
||||||
|| (c >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_BEGIN && c <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_END)
|
} /* lit_char_is_octal_digit */
|
||||||
|| (c >= LIT_CHAR_ASCII_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_DIGITS_END)
|
|
||||||
|| c == LIT_CHAR_UNDERSCORE)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
} /* lit_char_is_word_char */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a hex character to an unsigned integer
|
* Check if specified character is one of DecimalDigit characters (ECMA-262 v5, 7.8.3)
|
||||||
|
*
|
||||||
|
* @return true / false
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
lit_char_is_decimal_digit (ecma_char_t c) /**< code unit */
|
||||||
|
{
|
||||||
|
return (c >= LIT_CHAR_ASCII_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_DIGITS_END);
|
||||||
|
} /* lit_char_is_decimal_digit */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if specified character is one of HexDigit characters (ECMA-262 v5, 7.8.3)
|
||||||
|
*
|
||||||
|
* @return true / false
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
lit_char_is_hex_digit (ecma_char_t c) /**< code unit */
|
||||||
|
{
|
||||||
|
return ((c >= LIT_CHAR_ASCII_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_DIGITS_END)
|
||||||
|
|| (c >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_HEX_BEGIN && c <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_HEX_END)
|
||||||
|
|| (c >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_HEX_BEGIN && c <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_HEX_END));
|
||||||
|
} /* lit_char_is_hex_digit */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a HexDigit character to its numeric value, as defined in ECMA-262 v5, 7.8.3
|
||||||
*
|
*
|
||||||
* @return digit value, corresponding to the hex char
|
* @return digit value, corresponding to the hex char
|
||||||
*/
|
*/
|
||||||
uint32_t
|
uint32_t
|
||||||
lit_char_hex_to_int (ecma_char_t c) /**< code unit, corresponding to
|
lit_char_hex_to_int (ecma_char_t c) /**< code unit, corresponding to
|
||||||
* one of [0-9A-Fa-f] characters */
|
* one of HexDigit characters */
|
||||||
{
|
{
|
||||||
|
JERRY_ASSERT (lit_char_is_hex_digit (c));
|
||||||
|
|
||||||
if (c >= LIT_CHAR_ASCII_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_DIGITS_END)
|
if (c >= LIT_CHAR_ASCII_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_DIGITS_END)
|
||||||
{
|
{
|
||||||
return (uint32_t) (c - LIT_CHAR_ASCII_DIGITS_BEGIN);
|
return (uint32_t) (c - LIT_CHAR_ASCII_DIGITS_BEGIN);
|
||||||
@@ -293,8 +308,23 @@ lit_char_hex_to_int (ecma_char_t c) /**< code unit, corresponding to
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (c >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_HEX_BEGIN && c <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_HEX_END);
|
|
||||||
|
|
||||||
return (uint32_t) (c - LIT_CHAR_ASCII_UPPERCASE_LETTERS_HEX_BEGIN + 10);
|
return (uint32_t) (c - LIT_CHAR_ASCII_UPPERCASE_LETTERS_HEX_BEGIN + 10);
|
||||||
}
|
}
|
||||||
} /* lit_char_hex_to_int */
|
} /* lit_char_hex_to_int */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if specified character is a word character (part of IsWordChar abstract operation)
|
||||||
|
*
|
||||||
|
* See also: ECMA-262 v5, 15.10.2.6 (IsWordChar)
|
||||||
|
*
|
||||||
|
* @return true - if the character is a word character
|
||||||
|
* false - otherwise.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
lit_char_is_word_char (ecma_char_t c) /**< code unit */
|
||||||
|
{
|
||||||
|
return ((c >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_BEGIN && c <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_END)
|
||||||
|
|| (c >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_BEGIN && c <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_END)
|
||||||
|
|| (c >= LIT_CHAR_ASCII_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_DIGITS_END)
|
||||||
|
|| c == LIT_CHAR_UNDERSCORE);
|
||||||
|
} /* lit_char_is_word_char */
|
||||||
|
|||||||
@@ -199,9 +199,17 @@ extern bool lit_char_is_unicode_connector_punctuation (ecma_char_t);
|
|||||||
* hexadecimal digits range */
|
* hexadecimal digits range */
|
||||||
#define LIT_CHAR_ASCII_LOWERCASE_LETTERS_HEX_END LIT_CHAR_LOWERCASE_F
|
#define LIT_CHAR_ASCII_LOWERCASE_LETTERS_HEX_END LIT_CHAR_LOWERCASE_F
|
||||||
|
|
||||||
|
#define LIT_CHAR_ASCII_OCTAL_DIGITS_BEGIN LIT_CHAR_0 /* octal digits range */
|
||||||
|
#define LIT_CHAR_ASCII_OCTAL_DIGITS_END LIT_CHAR_7
|
||||||
|
|
||||||
#define LIT_CHAR_ASCII_DIGITS_BEGIN LIT_CHAR_0 /* decimal digits range */
|
#define LIT_CHAR_ASCII_DIGITS_BEGIN LIT_CHAR_0 /* decimal digits range */
|
||||||
#define LIT_CHAR_ASCII_DIGITS_END LIT_CHAR_9
|
#define LIT_CHAR_ASCII_DIGITS_END LIT_CHAR_9
|
||||||
|
|
||||||
|
extern bool lit_char_is_octal_digit (ecma_char_t);
|
||||||
|
extern bool lit_char_is_decimal_digit (ecma_char_t);
|
||||||
|
extern bool lit_char_is_hex_digit (ecma_char_t);
|
||||||
|
extern uint32_t lit_char_hex_to_int (ecma_char_t);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Null character
|
* Null character
|
||||||
*/
|
*/
|
||||||
@@ -212,6 +220,4 @@ extern bool lit_char_is_unicode_connector_punctuation (ecma_char_t);
|
|||||||
*/
|
*/
|
||||||
extern bool lit_char_is_word_char (ecma_char_t);
|
extern bool lit_char_is_word_char (ecma_char_t);
|
||||||
|
|
||||||
extern uint32_t lit_char_hex_to_int (ecma_char_t);
|
|
||||||
|
|
||||||
#endif /* LIT_CHAR_HELPERS_H */
|
#endif /* LIT_CHAR_HELPERS_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user