Add ecma_char_is_word_char helper (part of IsWordChar abstract operation, ECMA-262 v5, 15.10.2.6); move hex_to_int from lexer to jerry-core/ecma/base/ecma-helpers-char.cpp, renaming it to ecma_char_hex_to_int.
JerryScript-DCO-1.0-Signed-off-by: Szilard Ledan szledan.u-szeged@partner.samsung.com JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
@@ -62,6 +62,64 @@ ecma_char_is_line_terminator (ecma_char_t c) /**< character value */
|
|||||||
|| ecma_char_is_new_line (c));
|
|| ecma_char_is_new_line (c));
|
||||||
} /* ecma_char_is_line_terminator */
|
} /* ecma_char_is_line_terminator */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
ecma_char_is_word_char (ecma_char_t c) /**< character value */
|
||||||
|
{
|
||||||
|
if ((c >= 'a' && c <= 'z')
|
||||||
|
|| (c >= 'A' && c <= 'Z')
|
||||||
|
|| (c >= '0' && c <= '9')
|
||||||
|
|| c == '_')
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} /* ecma_char_is_word_char */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a hex character to an unsigned integer
|
||||||
|
*
|
||||||
|
* @return digit value, corresponding to the hex char
|
||||||
|
*/
|
||||||
|
uint32_t
|
||||||
|
ecma_char_hex_to_int (ecma_char_t hex) /**< [0-9A-Fa-f] character value */
|
||||||
|
{
|
||||||
|
switch (hex)
|
||||||
|
{
|
||||||
|
case '0': return 0x0;
|
||||||
|
case '1': return 0x1;
|
||||||
|
case '2': return 0x2;
|
||||||
|
case '3': return 0x3;
|
||||||
|
case '4': return 0x4;
|
||||||
|
case '5': return 0x5;
|
||||||
|
case '6': return 0x6;
|
||||||
|
case '7': return 0x7;
|
||||||
|
case '8': return 0x8;
|
||||||
|
case '9': return 0x9;
|
||||||
|
case 'a':
|
||||||
|
case 'A': return 0xA;
|
||||||
|
case 'b':
|
||||||
|
case 'B': return 0xB;
|
||||||
|
case 'c':
|
||||||
|
case 'C': return 0xC;
|
||||||
|
case 'd':
|
||||||
|
case 'D': return 0xD;
|
||||||
|
case 'e':
|
||||||
|
case 'E': return 0xE;
|
||||||
|
case 'f':
|
||||||
|
case 'F': return 0xF;
|
||||||
|
default: JERRY_UNREACHABLE ();
|
||||||
|
}
|
||||||
|
} /* ecma_char_hex_to_int */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -334,6 +334,8 @@ extern ecma_length_t ecma_number_to_zt_string (ecma_number_t num, ecma_char_t *b
|
|||||||
extern bool ecma_char_is_new_line (ecma_char_t c);
|
extern bool ecma_char_is_new_line (ecma_char_t c);
|
||||||
extern bool ecma_char_is_carriage_return (ecma_char_t c);
|
extern bool ecma_char_is_carriage_return (ecma_char_t c);
|
||||||
extern bool ecma_char_is_line_terminator (ecma_char_t c);
|
extern bool ecma_char_is_line_terminator (ecma_char_t c);
|
||||||
|
extern bool ecma_char_is_word_char (ecma_char_t c);
|
||||||
|
extern uint32_t ecma_char_hex_to_int (ecma_char_t hex);
|
||||||
|
|
||||||
#endif /* !JERRY_ECMA_HELPERS_H */
|
#endif /* !JERRY_ECMA_HELPERS_H */
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
|
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
|
||||||
|
* Copyright 2015 University of Szeged.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -341,37 +342,6 @@ consume_char (void)
|
|||||||
} \
|
} \
|
||||||
while (0)
|
while (0)
|
||||||
|
|
||||||
static uint32_t
|
|
||||||
hex_to_int (char hex)
|
|
||||||
{
|
|
||||||
switch (hex)
|
|
||||||
{
|
|
||||||
case '0': return 0x0;
|
|
||||||
case '1': return 0x1;
|
|
||||||
case '2': return 0x2;
|
|
||||||
case '3': return 0x3;
|
|
||||||
case '4': return 0x4;
|
|
||||||
case '5': return 0x5;
|
|
||||||
case '6': return 0x6;
|
|
||||||
case '7': return 0x7;
|
|
||||||
case '8': return 0x8;
|
|
||||||
case '9': return 0x9;
|
|
||||||
case 'a':
|
|
||||||
case 'A': return 0xA;
|
|
||||||
case 'b':
|
|
||||||
case 'B': return 0xB;
|
|
||||||
case 'c':
|
|
||||||
case 'C': return 0xC;
|
|
||||||
case 'd':
|
|
||||||
case 'D': return 0xD;
|
|
||||||
case 'e':
|
|
||||||
case 'E': return 0xE;
|
|
||||||
case 'f':
|
|
||||||
case 'F': return 0xF;
|
|
||||||
default: JERRY_UNREACHABLE ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to decode specified character as SingleEscapeCharacter (ECMA-262, v5, 7.8.4)
|
* Try to decode specified character as SingleEscapeCharacter (ECMA-262, v5, 7.8.4)
|
||||||
*
|
*
|
||||||
@@ -545,7 +515,7 @@ convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of
|
|||||||
JERRY_ASSERT ((char_code & 0xF000u) == 0);
|
JERRY_ASSERT ((char_code & 0xF000u) == 0);
|
||||||
|
|
||||||
char_code = (uint16_t) (char_code << 4u);
|
char_code = (uint16_t) (char_code << 4u);
|
||||||
char_code = (uint16_t) (char_code + hex_to_int (nc));
|
char_code = (uint16_t) (char_code + ecma_char_hex_to_int ((ecma_char_t) nc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -761,11 +731,11 @@ parse_number (void)
|
|||||||
{
|
{
|
||||||
if (!is_overflow)
|
if (!is_overflow)
|
||||||
{
|
{
|
||||||
res = (res << 4) + hex_to_int (token_start[i]);
|
res = (res << 4) + ecma_char_hex_to_int ((ecma_char_t) token_start[i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fp_res = fp_res * 16 + (ecma_number_t) hex_to_int (token_start[i]);
|
fp_res = fp_res * 16 + (ecma_number_t) ecma_char_hex_to_int ((ecma_char_t) token_start[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res > 255)
|
if (res > 255)
|
||||||
@@ -879,11 +849,11 @@ parse_number (void)
|
|||||||
{
|
{
|
||||||
if (!is_overflow)
|
if (!is_overflow)
|
||||||
{
|
{
|
||||||
res = res * 8 + hex_to_int (token_start[i]);
|
res = res * 8 + ecma_char_hex_to_int ((ecma_char_t) token_start[i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fp_res = fp_res * 8 + (ecma_number_t) hex_to_int (token_start[i]);
|
fp_res = fp_res * 8 + (ecma_number_t) ecma_char_hex_to_int ((ecma_char_t) token_start[i]);
|
||||||
}
|
}
|
||||||
if (res > 255)
|
if (res > 255)
|
||||||
{
|
{
|
||||||
@@ -899,11 +869,11 @@ parse_number (void)
|
|||||||
{
|
{
|
||||||
if (!is_overflow)
|
if (!is_overflow)
|
||||||
{
|
{
|
||||||
res = res * 10 + hex_to_int (token_start[i]);
|
res = res * 10 + ecma_char_hex_to_int ((ecma_char_t) token_start[i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fp_res = fp_res * 10 + (ecma_number_t) hex_to_int (token_start[i]);
|
fp_res = fp_res * 10 + (ecma_number_t) ecma_char_hex_to_int ((ecma_char_t) token_start[i]);
|
||||||
}
|
}
|
||||||
if (res > 255)
|
if (res > 255)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user