From afe58e90ae3261c477baa05687d76d0b186d31de Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Wed, 8 Jul 2015 15:17:41 +0300 Subject: [PATCH] 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 --- jerry-core/lit/lit-char-helpers.cpp | 70 ++++++++++++++++++++--------- jerry-core/lit/lit-char-helpers.h | 10 ++++- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/jerry-core/lit/lit-char-helpers.cpp b/jerry-core/lit/lit-char-helpers.cpp index 428d692c0..6e0ed9b31 100644 --- a/jerry-core/lit/lit-char-helpers.cpp +++ b/jerry-core/lit/lit-char-helpers.cpp @@ -253,36 +253,51 @@ lit_char_is_unicode_connector_punctuation (ecma_char_t c) /**< code unit */ } /* 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 - if the character is a word character - * false - otherwise. + * @return true / false */ 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) - || (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) - { - return true; - } - - return false; -} /* lit_char_is_word_char */ + return (c >= LIT_CHAR_ASCII_OCTAL_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_OCTAL_DIGITS_END); +} /* lit_char_is_octal_digit */ /** - * 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 */ uint32_t 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) { 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 { - 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); } } /* 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 */ diff --git a/jerry-core/lit/lit-char-helpers.h b/jerry-core/lit/lit-char-helpers.h index 794f74272..e83240641 100644 --- a/jerry-core/lit/lit-char-helpers.h +++ b/jerry-core/lit/lit-char-helpers.h @@ -199,9 +199,17 @@ extern bool lit_char_is_unicode_connector_punctuation (ecma_char_t); * hexadecimal digits range */ #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_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 */ @@ -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 uint32_t lit_char_hex_to_int (ecma_char_t); - #endif /* LIT_CHAR_HELPERS_H */