mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Refactor builtins to handle CESU-8 encoded strings.
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai.u-szeged@partner.samsung.com
This commit is contained in:
parent
dcd610b305
commit
579b1edaa5
@ -354,15 +354,16 @@ ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
||||
return ECMA_NUMBER_ZERO;
|
||||
}
|
||||
|
||||
lit_utf8_iterator_t iter = lit_utf8_iterator_create (str_p, str_size);
|
||||
lit_utf8_byte_t *str_curr_p = (lit_utf8_byte_t *) str_p;
|
||||
const lit_utf8_byte_t *str_end_p = str_p + str_size;
|
||||
ecma_char_t code_unit;
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&iter))
|
||||
while (str_curr_p < str_end_p)
|
||||
{
|
||||
code_unit = lit_utf8_iterator_peek_next (&iter);
|
||||
code_unit = lit_utf8_peek_next (str_curr_p);
|
||||
if (lit_char_is_white_space (code_unit) || lit_char_is_line_terminator (code_unit))
|
||||
{
|
||||
lit_utf8_iterator_incr (&iter);
|
||||
lit_utf8_incr (&str_curr_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -370,17 +371,15 @@ ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_ASSERT (!iter.buf_pos.is_non_bmp_middle);
|
||||
const lit_utf8_byte_t *begin_p = iter.buf_p + iter.buf_pos.offset;
|
||||
const lit_utf8_byte_t *begin_p = str_curr_p;
|
||||
str_curr_p = (lit_utf8_byte_t *) str_end_p;
|
||||
|
||||
iter = lit_utf8_iterator_create (iter.buf_p + iter.buf_pos.offset, str_size - iter.buf_pos.offset);
|
||||
lit_utf8_iterator_seek_eos (&iter);
|
||||
while (!lit_utf8_iterator_is_bos (&iter))
|
||||
while (str_curr_p > str_p)
|
||||
{
|
||||
code_unit = lit_utf8_iterator_peek_prev (&iter);
|
||||
code_unit = lit_utf8_peek_prev (str_curr_p);
|
||||
if (lit_char_is_white_space (code_unit) || lit_char_is_line_terminator (code_unit))
|
||||
{
|
||||
lit_utf8_iterator_decr (&iter);
|
||||
lit_utf8_decr (&str_curr_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -388,8 +387,7 @@ ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_ASSERT (!iter.buf_pos.is_non_bmp_middle);
|
||||
const lit_utf8_byte_t *end_p = iter.buf_p + iter.buf_pos.offset - 1;
|
||||
const lit_utf8_byte_t *end_p = str_curr_p - 1;
|
||||
|
||||
if (begin_p > end_p)
|
||||
{
|
||||
|
||||
@ -48,27 +48,22 @@
|
||||
* @return NaN if cannot read from string, ToNumber() otherwise
|
||||
*/
|
||||
static ecma_number_t
|
||||
ecma_date_parse_date_chars (lit_utf8_iterator_t *iter, /**< iterator of the utf8 string */
|
||||
ecma_date_parse_date_chars (lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */
|
||||
const lit_utf8_byte_t *str_end_p, /**< pointer to the end of the string */
|
||||
uint32_t num_of_chars) /**< number of characters to read and convert */
|
||||
{
|
||||
JERRY_ASSERT (num_of_chars > 0);
|
||||
|
||||
lit_utf8_size_t copy_size = 0;
|
||||
const lit_utf8_byte_t *str_start_p = iter->buf_p + iter->buf_pos.offset;
|
||||
const lit_utf8_byte_t *str_start_p = *str_p;
|
||||
|
||||
while (num_of_chars--)
|
||||
{
|
||||
if (lit_utf8_iterator_is_eos (iter)
|
||||
|| !lit_char_is_decimal_digit (lit_utf8_iterator_peek_next (iter)))
|
||||
if (*str_p >= str_end_p || !lit_char_is_decimal_digit (lit_utf8_read_next (str_p)))
|
||||
{
|
||||
return ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
copy_size += lit_get_unicode_char_size_by_utf8_first_byte (*(iter->buf_p + iter->buf_pos.offset));
|
||||
lit_utf8_iterator_incr (iter);
|
||||
}
|
||||
|
||||
return ecma_utf8_string_to_number (str_start_p, copy_size);
|
||||
return ecma_utf8_string_to_number (str_start_p, (lit_utf8_size_t) (*str_p - str_start_p));
|
||||
} /* ecma_date_parse_date_chars */
|
||||
|
||||
/**
|
||||
@ -211,10 +206,11 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
|
||||
ssize_t sz = ecma_string_to_utf8_string (date_str_p, date_start_p, (ssize_t) date_str_size);
|
||||
JERRY_ASSERT (sz >= 0);
|
||||
|
||||
lit_utf8_iterator_t iter = lit_utf8_iterator_create (date_start_p, date_str_size);
|
||||
lit_utf8_byte_t *date_str_curr_p = date_start_p;
|
||||
const lit_utf8_byte_t *date_str_end_p = date_start_p + date_str_size;
|
||||
|
||||
/* 1. read year */
|
||||
ecma_number_t year = ecma_date_parse_date_chars (&iter, 4);
|
||||
ecma_number_t year = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 4);
|
||||
|
||||
if (!ecma_number_is_nan (year)
|
||||
&& year >= 0)
|
||||
@ -224,12 +220,12 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
|
||||
ecma_number_t time = ECMA_NUMBER_ZERO;
|
||||
|
||||
/* 2. read month if any */
|
||||
if (!lit_utf8_iterator_is_eos (&iter)
|
||||
&& lit_utf8_iterator_peek_next (&iter) == '-')
|
||||
if (date_str_curr_p < date_str_end_p
|
||||
&& *date_str_curr_p == '-')
|
||||
{
|
||||
/* eat up '-' */
|
||||
lit_utf8_iterator_incr (&iter);
|
||||
month = ecma_date_parse_date_chars (&iter, 2);
|
||||
date_str_curr_p++;
|
||||
month = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (month > 12 || month < 1)
|
||||
{
|
||||
@ -238,12 +234,12 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
|
||||
}
|
||||
|
||||
/* 3. read day if any */
|
||||
if (!lit_utf8_iterator_is_eos (&iter)
|
||||
&& lit_utf8_iterator_peek_next (&iter) == '-')
|
||||
if (date_str_curr_p < date_str_end_p
|
||||
&& *date_str_curr_p == '-')
|
||||
{
|
||||
/* eat up '-' */
|
||||
lit_utf8_iterator_incr (&iter);
|
||||
day = ecma_date_parse_date_chars (&iter, 2);
|
||||
date_str_curr_p++;
|
||||
day = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (day < 1 || day > 31)
|
||||
{
|
||||
@ -252,24 +248,24 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
|
||||
}
|
||||
|
||||
/* 4. read time if any */
|
||||
if (!lit_utf8_iterator_is_eos (&iter)
|
||||
&& lit_utf8_iterator_peek_next (&iter) == 'T')
|
||||
if (date_str_curr_p < date_str_end_p
|
||||
&& *date_str_curr_p == 'T')
|
||||
{
|
||||
/* eat up 'T' */
|
||||
date_str_curr_p++;
|
||||
|
||||
ecma_number_t hours = ECMA_NUMBER_ZERO;
|
||||
ecma_number_t minutes = ECMA_NUMBER_ZERO;
|
||||
ecma_number_t seconds = ECMA_NUMBER_ZERO;
|
||||
ecma_number_t milliseconds = ECMA_NUMBER_ZERO;
|
||||
|
||||
ecma_length_t num_of_visited_chars = lit_utf8_iterator_get_index (&iter);
|
||||
ecma_length_t date_str_len = lit_utf8_string_length (iter.buf_p, iter.buf_size) - 1;
|
||||
ecma_length_t remaining_length = lit_utf8_string_length (date_str_curr_p,
|
||||
(lit_utf8_size_t) (date_str_end_p - date_str_curr_p));
|
||||
|
||||
if ((date_str_len - num_of_visited_chars) >= 5)
|
||||
if (remaining_length >= 5)
|
||||
{
|
||||
/* eat up 'T' */
|
||||
lit_utf8_iterator_incr (&iter);
|
||||
|
||||
/* 4.1 read hours and minutes */
|
||||
hours = ecma_date_parse_date_chars (&iter, 2);
|
||||
hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (hours < 0 || hours > 24)
|
||||
{
|
||||
@ -281,9 +277,9 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
|
||||
}
|
||||
|
||||
/* eat up ':' */
|
||||
lit_utf8_iterator_incr (&iter);
|
||||
date_str_curr_p++;
|
||||
|
||||
minutes = ecma_date_parse_date_chars (&iter, 2);
|
||||
minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (minutes < 0 || minutes > 59)
|
||||
{
|
||||
@ -291,11 +287,12 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
|
||||
}
|
||||
|
||||
/* 4.2 read seconds if any */
|
||||
if (!lit_utf8_iterator_is_eos (&iter) && lit_utf8_iterator_peek_next (&iter) == ':')
|
||||
if (date_str_curr_p < date_str_end_p
|
||||
&& *date_str_curr_p == ':')
|
||||
{
|
||||
/* eat up ':' */
|
||||
lit_utf8_iterator_incr (&iter);
|
||||
seconds = ecma_date_parse_date_chars (&iter, 2);
|
||||
date_str_curr_p++;
|
||||
seconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (seconds < 0 || seconds > 59)
|
||||
{
|
||||
@ -303,11 +300,12 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
|
||||
}
|
||||
|
||||
/* 4.3 read milliseconds if any */
|
||||
if (!lit_utf8_iterator_is_eos (&iter) && lit_utf8_iterator_peek_next (&iter) == '.')
|
||||
if (date_str_curr_p < date_str_end_p
|
||||
&& *date_str_curr_p == '.')
|
||||
{
|
||||
/* eat up '.' */
|
||||
lit_utf8_iterator_incr (&iter);
|
||||
milliseconds = ecma_date_parse_date_chars (&iter, 3);
|
||||
date_str_curr_p++;
|
||||
milliseconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 3);
|
||||
|
||||
if (milliseconds < 0)
|
||||
{
|
||||
@ -324,34 +322,34 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
|
||||
}
|
||||
|
||||
/* 4.4 read timezone if any */
|
||||
if (!lit_utf8_iterator_is_eos (&iter)
|
||||
&& lit_utf8_iterator_peek_next (&iter) == 'Z'
|
||||
if (date_str_curr_p < date_str_end_p
|
||||
&& *date_str_curr_p == 'Z'
|
||||
&& !ecma_number_is_nan (time))
|
||||
{
|
||||
lit_utf8_iterator_incr (&iter);
|
||||
date_str_curr_p++;
|
||||
time = ecma_date_make_time (hours, minutes, seconds, milliseconds);
|
||||
}
|
||||
else if (!lit_utf8_iterator_is_eos (&iter)
|
||||
&& (lit_utf8_iterator_peek_next (&iter) == '+'
|
||||
|| lit_utf8_iterator_peek_next (&iter) == '-'))
|
||||
else if (date_str_curr_p < date_str_end_p
|
||||
&& (*date_str_curr_p == '+' || *date_str_curr_p == '-'))
|
||||
{
|
||||
ecma_length_t num_of_visited_chars = lit_utf8_iterator_get_index (&iter);
|
||||
ecma_length_t date_str_len = lit_utf8_string_length (iter.buf_p, iter.buf_size) - 1;
|
||||
ecma_length_t remaining_length;
|
||||
remaining_length = lit_utf8_string_length (date_str_curr_p,
|
||||
(lit_utf8_size_t) (date_str_end_p - date_str_curr_p)) - 1;
|
||||
|
||||
if ((date_str_len - num_of_visited_chars) == 5)
|
||||
if (remaining_length == 5)
|
||||
{
|
||||
bool is_negative = false;
|
||||
|
||||
if (lit_utf8_iterator_peek_next (&iter) == '-')
|
||||
if (*date_str_curr_p == '-')
|
||||
{
|
||||
is_negative = true;
|
||||
}
|
||||
|
||||
/* eat up '+/-' */
|
||||
lit_utf8_iterator_incr (&iter);
|
||||
date_str_curr_p++;
|
||||
|
||||
/* read hours and minutes */
|
||||
hours = ecma_date_parse_date_chars (&iter, 2);
|
||||
hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (hours < 0 || hours > 24)
|
||||
{
|
||||
@ -363,9 +361,9 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
|
||||
}
|
||||
|
||||
/* eat up ':' */
|
||||
lit_utf8_iterator_incr (&iter);
|
||||
date_str_curr_p++;
|
||||
|
||||
minutes = ecma_date_parse_date_chars (&iter, 2);
|
||||
minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (minutes < 0 || minutes > 59)
|
||||
{
|
||||
@ -384,7 +382,7 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
|
||||
}
|
||||
}
|
||||
|
||||
if (lit_utf8_iterator_is_eos (&iter))
|
||||
if (date_str_curr_p >= date_str_end_p)
|
||||
{
|
||||
ecma_number_t date = ecma_date_make_day (year, month - 1, day);
|
||||
*date_num_p = ecma_date_make_date (date, time);
|
||||
|
||||
@ -90,11 +90,12 @@ ecma_builtin_global_object_print (ecma_value_t this_arg __attr_unused___, /**< t
|
||||
ssize_t actual_sz = ecma_string_to_utf8_string (str_p, utf8_str_p, (ssize_t) utf8_str_size);
|
||||
JERRY_ASSERT (actual_sz == (ssize_t) utf8_str_size);
|
||||
|
||||
lit_utf8_iterator_t str_iter = lit_utf8_iterator_create (utf8_str_p, utf8_str_size);
|
||||
lit_utf8_byte_t *utf8_str_curr_p = utf8_str_p;
|
||||
const lit_utf8_byte_t *utf8_str_end_p = utf8_str_p + utf8_str_size;
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&str_iter))
|
||||
while (utf8_str_curr_p < utf8_str_end_p)
|
||||
{
|
||||
ecma_char_t code_point = lit_utf8_iterator_read_next (&str_iter);
|
||||
ecma_char_t code_point = lit_utf8_read_next (&utf8_str_curr_p);
|
||||
|
||||
if (code_point == LIT_CHAR_NULL)
|
||||
{
|
||||
@ -207,42 +208,40 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
|
||||
|
||||
if (str_size > 0)
|
||||
{
|
||||
MEM_DEFINE_LOCAL_ARRAY (utf8_string_buff, str_size, lit_utf8_byte_t);
|
||||
MEM_DEFINE_LOCAL_ARRAY (string_buff, str_size, lit_utf8_byte_t);
|
||||
|
||||
ssize_t bytes_copied = ecma_string_to_utf8_string (number_str_p,
|
||||
utf8_string_buff,
|
||||
string_buff,
|
||||
(ssize_t) str_size);
|
||||
JERRY_ASSERT (bytes_copied >= 0);
|
||||
lit_utf8_iterator_t iter = lit_utf8_iterator_create (utf8_string_buff, str_size);
|
||||
lit_utf8_byte_t *string_curr_p = string_buff;
|
||||
lit_utf8_byte_t *string_end_p = string_buff + str_size;
|
||||
|
||||
/* 2. Remove leading whitespace. */
|
||||
lit_utf8_iterator_seek_eos (&iter);
|
||||
|
||||
lit_utf8_iterator_pos_t start = lit_utf8_iterator_get_pos (&iter);
|
||||
lit_utf8_iterator_pos_t end = lit_utf8_iterator_get_pos (&iter);
|
||||
lit_utf8_byte_t *start_p = string_end_p;
|
||||
lit_utf8_byte_t *end_p = string_end_p;
|
||||
|
||||
lit_utf8_iterator_seek_bos (&iter);
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&iter))
|
||||
while (string_curr_p < string_end_p)
|
||||
{
|
||||
ecma_char_t current_char = lit_utf8_iterator_read_next (&iter);
|
||||
ecma_char_t current_char = lit_utf8_read_next (&string_curr_p);
|
||||
|
||||
if (!lit_char_is_white_space (current_char)
|
||||
&& !lit_char_is_line_terminator (current_char))
|
||||
{
|
||||
lit_utf8_iterator_read_prev (&iter);
|
||||
start = lit_utf8_iterator_get_pos (&iter);
|
||||
lit_utf8_decr (&string_curr_p);
|
||||
start_p = string_curr_p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!lit_utf8_iterator_is_eos (&iter))
|
||||
if (string_curr_p < string_end_p)
|
||||
{
|
||||
/* 3. */
|
||||
int sign = 1;
|
||||
|
||||
/* 4. */
|
||||
ecma_char_t current = lit_utf8_iterator_read_next (&iter);
|
||||
ecma_char_t current = lit_utf8_read_next (&string_curr_p);
|
||||
if (current == LIT_CHAR_MINUS)
|
||||
{
|
||||
sign = -1;
|
||||
@ -251,10 +250,10 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
|
||||
/* 5. */
|
||||
if (current == LIT_CHAR_MINUS || current == LIT_CHAR_PLUS)
|
||||
{
|
||||
start = lit_utf8_iterator_get_pos (&iter);
|
||||
if (!lit_utf8_iterator_is_eos (&iter))
|
||||
start_p = string_curr_p;
|
||||
if (string_curr_p < string_end_p)
|
||||
{
|
||||
current = lit_utf8_iterator_read_next (&iter);
|
||||
current = lit_utf8_read_next (&string_curr_p);
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,25 +291,23 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
|
||||
/* 10. */
|
||||
if (strip_prefix)
|
||||
{
|
||||
if (end.offset - start.offset >= 2 && current == LIT_CHAR_0)
|
||||
if (end_p - start_p >= 2 && current == LIT_CHAR_0)
|
||||
{
|
||||
ecma_char_t next = lit_utf8_iterator_peek_next (&iter);
|
||||
ecma_char_t next = *string_curr_p;
|
||||
if (next == LIT_CHAR_LOWERCASE_X || next == LIT_CHAR_UPPERCASE_X)
|
||||
{
|
||||
/* Skip the 'x' or 'X' characters. */
|
||||
lit_utf8_iterator_incr (&iter);
|
||||
start = lit_utf8_iterator_get_pos (&iter);
|
||||
|
||||
start_p = ++string_curr_p;
|
||||
rad = 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 11. Check if characters are in [0, Radix - 1]. We also convert them to number values in the process. */
|
||||
lit_utf8_iterator_seek (&iter, start);
|
||||
while (!lit_utf8_iterator_is_eos (&iter))
|
||||
string_curr_p = start_p;
|
||||
while (string_curr_p < string_end_p)
|
||||
{
|
||||
ecma_char_t current_char = lit_utf8_iterator_read_next (&iter);
|
||||
ecma_char_t current_char = *string_curr_p++;
|
||||
int32_t current_number;
|
||||
|
||||
if ((current_char >= LIT_CHAR_LOWERCASE_A && current_char <= LIT_CHAR_LOWERCASE_Z))
|
||||
@ -333,14 +330,13 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
|
||||
|
||||
if (!(current_number < rad))
|
||||
{
|
||||
lit_utf8_iterator_decr (&iter);
|
||||
end = lit_utf8_iterator_get_pos (&iter);
|
||||
end_p = --string_curr_p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* 12. */
|
||||
if (end.offset - start.offset == 0)
|
||||
if (end_p == start_p)
|
||||
{
|
||||
ecma_number_t *ret_num_p = ecma_alloc_number ();
|
||||
*ret_num_p = ecma_number_make_nan ();
|
||||
@ -355,17 +351,11 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
|
||||
ecma_number_t multiplier = 1.0f;
|
||||
|
||||
/* 13. and 14. */
|
||||
if (end.offset < str_size)
|
||||
string_curr_p = end_p;
|
||||
|
||||
while (string_curr_p > start_p)
|
||||
{
|
||||
lit_utf8_iterator_seek (&iter, end);
|
||||
}
|
||||
else
|
||||
{
|
||||
lit_utf8_iterator_seek_eos (&iter);
|
||||
}
|
||||
while (lit_utf8_iterator_get_pos (&iter).offset > start.offset)
|
||||
{
|
||||
ecma_char_t current_char = lit_utf8_iterator_read_prev (&iter);
|
||||
ecma_char_t current_char = *(--string_curr_p);
|
||||
ecma_number_t current_number;
|
||||
|
||||
if ((current_char >= LIT_CHAR_LOWERCASE_A && current_char <= LIT_CHAR_LOWERCASE_Z))
|
||||
@ -407,7 +397,7 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
|
||||
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (ret_num_p));
|
||||
}
|
||||
|
||||
MEM_FINALIZE_LOCAL_ARRAY (utf8_string_buff);
|
||||
MEM_FINALIZE_LOCAL_ARRAY (string_buff);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -443,32 +433,29 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
|
||||
|
||||
if (str_size > 0)
|
||||
{
|
||||
MEM_DEFINE_LOCAL_ARRAY (utf8_string_buff, str_size, lit_utf8_byte_t);
|
||||
MEM_DEFINE_LOCAL_ARRAY (string_buff, str_size, lit_utf8_byte_t);
|
||||
|
||||
ssize_t bytes_copied = ecma_string_to_utf8_string (number_str_p,
|
||||
utf8_string_buff,
|
||||
string_buff,
|
||||
(ssize_t) str_size);
|
||||
JERRY_ASSERT (bytes_copied >= 0);
|
||||
lit_utf8_iterator_t iter = lit_utf8_iterator_create (utf8_string_buff, str_size);
|
||||
|
||||
lit_utf8_iterator_seek_eos (&iter);
|
||||
|
||||
lit_utf8_iterator_pos_t start = lit_utf8_iterator_get_pos (&iter);
|
||||
lit_utf8_iterator_pos_t end = lit_utf8_iterator_get_pos (&iter);
|
||||
|
||||
lit_utf8_iterator_seek_bos (&iter);
|
||||
lit_utf8_byte_t *str_curr_p = string_buff;
|
||||
lit_utf8_byte_t *str_end_p = string_buff + str_size;
|
||||
|
||||
lit_utf8_byte_t *start_p = str_end_p;
|
||||
lit_utf8_byte_t *end_p = str_end_p;
|
||||
|
||||
/* 2. Find first non whitespace char and set starting position. */
|
||||
while (!lit_utf8_iterator_is_eos (&iter))
|
||||
while (str_curr_p < str_end_p)
|
||||
{
|
||||
ecma_char_t current_char = lit_utf8_iterator_read_next (&iter);
|
||||
ecma_char_t current_char = lit_utf8_read_next (&str_curr_p);
|
||||
|
||||
if (!lit_char_is_white_space (current_char)
|
||||
&& !lit_char_is_line_terminator (current_char))
|
||||
{
|
||||
lit_utf8_iterator_decr (&iter);
|
||||
start = lit_utf8_iterator_get_pos (&iter);
|
||||
lit_utf8_decr (&str_curr_p);
|
||||
start_p = str_curr_p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -476,10 +463,10 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
|
||||
bool sign = false;
|
||||
ecma_char_t current;
|
||||
|
||||
if (!lit_utf8_iterator_is_eos (&iter))
|
||||
if (str_curr_p < str_end_p)
|
||||
{
|
||||
/* Check if sign is present. */
|
||||
current = lit_utf8_iterator_read_next (&iter);
|
||||
current = *str_curr_p;
|
||||
if (current == LIT_CHAR_MINUS)
|
||||
{
|
||||
sign = true;
|
||||
@ -488,27 +475,21 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
|
||||
if (current == LIT_CHAR_MINUS || current == LIT_CHAR_PLUS)
|
||||
{
|
||||
/* Set starting position to be after the sign character. */
|
||||
start = lit_utf8_iterator_get_pos (&iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
lit_utf8_iterator_decr (&iter);
|
||||
start_p = ++str_curr_p;
|
||||
}
|
||||
}
|
||||
|
||||
ecma_number_t *ret_num_p = ecma_alloc_number ();
|
||||
|
||||
const lit_utf8_byte_t *infinity_utf8_str_p = lit_get_magic_string_utf8 (LIT_MAGIC_STRING_INFINITY_UL);
|
||||
lit_utf8_iterator_t infinity_iter = lit_utf8_iterator_create (infinity_utf8_str_p,
|
||||
sizeof (*infinity_utf8_str_p));
|
||||
|
||||
JERRY_ASSERT (!lit_utf8_iterator_is_eos (&infinity_iter));
|
||||
const lit_utf8_byte_t *infinity_str_p = lit_get_magic_string_utf8 (LIT_MAGIC_STRING_INFINITY_UL);
|
||||
lit_utf8_byte_t *infinity_str_curr_p = (lit_utf8_byte_t *) infinity_str_p;
|
||||
lit_utf8_byte_t *infinity_str_end_p = infinity_str_curr_p + sizeof (*infinity_str_p);
|
||||
|
||||
/* Check if string is equal to "Infinity". */
|
||||
while (!lit_utf8_iterator_is_eos (&iter)
|
||||
&& (lit_utf8_iterator_read_next (&iter) == lit_utf8_iterator_read_next (&infinity_iter)))
|
||||
while (str_curr_p < str_end_p
|
||||
&& *str_curr_p++ == *infinity_str_curr_p++)
|
||||
{
|
||||
if (lit_utf8_iterator_is_eos (&infinity_iter))
|
||||
if (infinity_str_curr_p == infinity_str_end_p)
|
||||
{
|
||||
/* String matched Infinity. */
|
||||
*ret_num_p = ecma_number_make_infinity (sign);
|
||||
@ -518,11 +499,11 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
|
||||
}
|
||||
|
||||
/* Reset to starting position. */
|
||||
lit_utf8_iterator_seek (&iter, start);
|
||||
str_curr_p = start_p;
|
||||
|
||||
if (ecma_is_completion_value_empty (ret_value) && !lit_utf8_iterator_is_eos (&iter))
|
||||
if (ecma_is_completion_value_empty (ret_value) && str_curr_p < str_end_p)
|
||||
{
|
||||
current = lit_utf8_iterator_read_next (&iter);
|
||||
current = *str_curr_p;
|
||||
|
||||
bool has_whole_part = false;
|
||||
bool has_fraction_part = false;
|
||||
@ -531,105 +512,93 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
|
||||
if (lit_char_is_decimal_digit (current))
|
||||
{
|
||||
has_whole_part = true;
|
||||
str_curr_p++;
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&iter))
|
||||
while (str_curr_p < str_end_p)
|
||||
{
|
||||
current = lit_utf8_iterator_read_next (&iter);
|
||||
current = *str_curr_p++;
|
||||
if (!lit_char_is_decimal_digit (current))
|
||||
{
|
||||
lit_utf8_iterator_decr (&iter);
|
||||
str_curr_p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lit_utf8_iterator_decr (&iter);
|
||||
}
|
||||
|
||||
|
||||
/* Set end position to the end of whole part. */
|
||||
end = lit_utf8_iterator_get_pos (&iter);
|
||||
if (!lit_utf8_iterator_is_eos (&iter))
|
||||
end_p = str_curr_p;
|
||||
if (str_curr_p < str_end_p)
|
||||
{
|
||||
current = lit_utf8_iterator_read_next (&iter);
|
||||
current = *str_curr_p;
|
||||
}
|
||||
|
||||
/* Check decimal point. */
|
||||
if (current == LIT_CHAR_DOT && !lit_utf8_iterator_is_eos (&iter))
|
||||
if (current == LIT_CHAR_DOT && str_curr_p < str_end_p)
|
||||
{
|
||||
current = lit_utf8_iterator_read_next (&iter);
|
||||
current = *(++str_curr_p);
|
||||
|
||||
if (lit_char_is_decimal_digit (current))
|
||||
{
|
||||
has_fraction_part = true;
|
||||
str_curr_p++;
|
||||
|
||||
/* Check digits of fractional part. */
|
||||
while (!lit_utf8_iterator_is_eos (&iter))
|
||||
while (str_curr_p < str_end_p)
|
||||
{
|
||||
current = lit_utf8_iterator_read_next (&iter);
|
||||
current = *str_curr_p++;
|
||||
if (!lit_char_is_decimal_digit (current))
|
||||
{
|
||||
lit_utf8_iterator_decr (&iter);
|
||||
str_curr_p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set end position to end of fraction part. */
|
||||
end = lit_utf8_iterator_get_pos (&iter);
|
||||
end_p = str_curr_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
lit_utf8_iterator_decr (&iter);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lit_utf8_iterator_decr (&iter);
|
||||
}
|
||||
|
||||
if (!lit_utf8_iterator_is_eos (&iter))
|
||||
|
||||
if (str_curr_p < str_end_p)
|
||||
{
|
||||
current = lit_utf8_iterator_read_next (&iter);
|
||||
current = *str_curr_p++;
|
||||
}
|
||||
|
||||
/* Check exponent. */
|
||||
if ((current == LIT_CHAR_LOWERCASE_E || current == LIT_CHAR_UPPERCASE_E)
|
||||
&& (has_whole_part || has_fraction_part)
|
||||
&& !lit_utf8_iterator_is_eos (&iter))
|
||||
&& str_curr_p < str_end_p)
|
||||
{
|
||||
current = lit_utf8_iterator_read_next (&iter);
|
||||
current = *str_curr_p++;
|
||||
|
||||
/* Check sign of exponent. */
|
||||
if ((current == LIT_CHAR_PLUS || current == LIT_CHAR_MINUS)
|
||||
&& !lit_utf8_iterator_is_eos (&iter))
|
||||
&& str_curr_p < str_end_p)
|
||||
{
|
||||
current = lit_utf8_iterator_read_next (&iter);
|
||||
current = *str_curr_p++;
|
||||
}
|
||||
|
||||
if (lit_char_is_decimal_digit (current))
|
||||
{
|
||||
/* Check digits of exponent part. */
|
||||
while (!lit_utf8_iterator_is_eos (&iter))
|
||||
while (str_curr_p < str_end_p)
|
||||
{
|
||||
current = lit_utf8_iterator_read_next (&iter);
|
||||
current = *str_curr_p++;
|
||||
if (!lit_char_is_decimal_digit (current))
|
||||
{
|
||||
lit_utf8_iterator_decr (&iter);
|
||||
str_curr_p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set end position to end of exponent part. */
|
||||
end = lit_utf8_iterator_get_pos (&iter);
|
||||
end_p = str_curr_p;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lit_utf8_iterator_decr (&iter);
|
||||
}
|
||||
|
||||
/* String did not contain a valid number. */
|
||||
if (start.offset == end.offset)
|
||||
if (start_p == end_p)
|
||||
{
|
||||
*ret_num_p = ecma_number_make_nan ();
|
||||
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (ret_num_p));
|
||||
@ -637,8 +606,8 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
|
||||
else
|
||||
{
|
||||
/* 5. */
|
||||
*ret_num_p = ecma_utf8_string_to_number (utf8_string_buff + start.offset,
|
||||
(lit_utf8_size_t) (end.offset - start.offset));
|
||||
*ret_num_p = ecma_utf8_string_to_number (start_p,
|
||||
(lit_utf8_size_t) (end_p - start_p));
|
||||
|
||||
if (sign)
|
||||
{
|
||||
@ -654,7 +623,7 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
|
||||
*ret_num_p = ecma_number_make_nan ();
|
||||
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (ret_num_p));
|
||||
}
|
||||
MEM_FINALIZE_LOCAL_ARRAY (utf8_string_buff);
|
||||
MEM_FINALIZE_LOCAL_ARRAY (string_buff);
|
||||
}
|
||||
/* String length is zero. */
|
||||
else
|
||||
@ -1301,12 +1270,13 @@ ecma_builtin_global_object_escape (ecma_value_t this_arg __attr_unused___, /**<
|
||||
* The escape routine has two major phases: first we compute
|
||||
* the length of the output, then we encode the input.
|
||||
*/
|
||||
lit_utf8_iterator_t iterator = lit_utf8_iterator_create (input_start_p, input_size);
|
||||
lit_utf8_byte_t *input_curr_p = input_start_p;
|
||||
lit_utf8_byte_t *input_end_p = input_start_p + input_size;
|
||||
lit_utf8_size_t output_length = 0;
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&iterator))
|
||||
while (input_curr_p < input_end_p)
|
||||
{
|
||||
ecma_char_t chr = lit_utf8_iterator_read_next (&iterator);
|
||||
ecma_char_t chr = lit_utf8_read_next (&input_curr_p);
|
||||
|
||||
if (chr <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
|
||||
{
|
||||
@ -1335,11 +1305,11 @@ ecma_builtin_global_object_escape (ecma_value_t this_arg __attr_unused___, /**<
|
||||
|
||||
lit_utf8_byte_t *output_char_p = output_start_p;
|
||||
|
||||
lit_utf8_iterator_seek_bos (&iterator);
|
||||
input_curr_p = input_start_p;
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&iterator))
|
||||
while (input_curr_p < input_end_p)
|
||||
{
|
||||
ecma_char_t chr = lit_utf8_iterator_read_next (&iterator);
|
||||
ecma_char_t chr = lit_utf8_read_next (&input_curr_p);
|
||||
|
||||
if (chr <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
|
||||
{
|
||||
|
||||
@ -598,10 +598,9 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**
|
||||
(ssize_t) (original_size));
|
||||
JERRY_ASSERT (sz >= 0);
|
||||
|
||||
lit_utf8_iterator_t original_it = lit_utf8_iterator_create (original_str_utf8_p, original_size);
|
||||
|
||||
ecma_length_t index = start;
|
||||
lit_utf8_iterator_advance (&original_it, index);
|
||||
|
||||
lit_utf8_byte_t *original_str_curr_p = original_str_utf8_p + index;
|
||||
|
||||
/* create utf8 string from search string */
|
||||
MEM_DEFINE_LOCAL_ARRAY (search_str_utf8_p,
|
||||
@ -613,7 +612,7 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**
|
||||
(ssize_t) (search_size));
|
||||
JERRY_ASSERT (sz >= 0);
|
||||
|
||||
lit_utf8_iterator_t search_it = lit_utf8_iterator_create (search_str_utf8_p, search_size);
|
||||
lit_utf8_byte_t *search_str_curr_p = search_str_utf8_p;
|
||||
|
||||
/* iterate original string and try to match at each position */
|
||||
bool searching = true;
|
||||
@ -622,11 +621,11 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**
|
||||
{
|
||||
/* match as long as possible */
|
||||
ecma_length_t match_len = 0;
|
||||
lit_utf8_iterator_t stored_original_it = original_it;
|
||||
lit_utf8_byte_t *stored_original_str_curr_p = original_str_curr_p;
|
||||
|
||||
while (match_len < search_len &&
|
||||
index + match_len < original_len &&
|
||||
lit_utf8_iterator_read_next (&original_it) == lit_utf8_iterator_read_next (&search_it))
|
||||
lit_utf8_read_next (&original_str_curr_p) == lit_utf8_read_next (&search_str_curr_p))
|
||||
{
|
||||
match_len++;
|
||||
}
|
||||
@ -640,14 +639,14 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**
|
||||
else
|
||||
{
|
||||
/* inc/dec index and update iterators and search condition */
|
||||
lit_utf8_iterator_seek_bos (&search_it);
|
||||
original_it = stored_original_it;
|
||||
search_str_curr_p = search_str_utf8_p;
|
||||
original_str_curr_p = stored_original_str_curr_p;
|
||||
|
||||
if (firstIndex)
|
||||
{
|
||||
if ((searching = (index <= original_len - search_len)))
|
||||
{
|
||||
lit_utf8_iterator_incr (&original_it);
|
||||
lit_utf8_incr (&original_str_curr_p);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
@ -655,7 +654,7 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**
|
||||
{
|
||||
if ((searching = (index > 0)))
|
||||
{
|
||||
lit_utf8_iterator_decr (&original_it);
|
||||
lit_utf8_decr (&original_str_curr_p);
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1145,11 +1145,12 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
|
||||
|
||||
JERRY_ASSERT (bytes_copied > 0 || !string_size);
|
||||
|
||||
lit_utf8_iterator_t iter = lit_utf8_iterator_create (string_buff, string_size);
|
||||
lit_utf8_byte_t *str_p = string_buff;
|
||||
const lit_utf8_byte_t *str_end_p = str_p + string_size;
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&iter))
|
||||
while (str_p < str_end_p)
|
||||
{
|
||||
ecma_char_t current_char = lit_utf8_iterator_read_next (&iter);
|
||||
ecma_char_t current_char = lit_utf8_read_next (&str_p);
|
||||
|
||||
/* 2.a */
|
||||
if (current_char == LIT_CHAR_BACKSLASH || current_char == LIT_CHAR_DOUBLE_QUOTE)
|
||||
|
||||
@ -369,10 +369,9 @@ ecma_builtin_string_prototype_object_index_of (ecma_value_t this_arg, /**< this
|
||||
(ssize_t) (original_size));
|
||||
JERRY_ASSERT (sz >= 0);
|
||||
|
||||
lit_utf8_iterator_t original_it = lit_utf8_iterator_create (original_str_utf8_p, original_size);
|
||||
|
||||
ecma_length_t index = start;
|
||||
lit_utf8_iterator_advance (&original_it, index);
|
||||
|
||||
lit_utf8_byte_t *original_str_curr_p = original_str_utf8_p + index;
|
||||
|
||||
/* create utf8 string from search string */
|
||||
MEM_DEFINE_LOCAL_ARRAY (search_str_utf8_p,
|
||||
@ -384,7 +383,7 @@ ecma_builtin_string_prototype_object_index_of (ecma_value_t this_arg, /**< this
|
||||
(ssize_t) (search_size));
|
||||
JERRY_ASSERT (sz >= 0);
|
||||
|
||||
lit_utf8_iterator_t search_it = lit_utf8_iterator_create (search_str_utf8_p, search_size);
|
||||
lit_utf8_byte_t *search_str_curr_p = search_str_utf8_p;
|
||||
|
||||
/* iterate original string and try to match at each position */
|
||||
bool found = false;
|
||||
@ -392,10 +391,10 @@ ecma_builtin_string_prototype_object_index_of (ecma_value_t this_arg, /**< this
|
||||
while (!found && index <= original_len - search_len)
|
||||
{
|
||||
ecma_length_t match_len = 0;
|
||||
lit_utf8_iterator_pos_t stored_original_pos = lit_utf8_iterator_get_pos (&original_it);
|
||||
lit_utf8_byte_t *stored_original_str_curr_p = original_str_curr_p;
|
||||
|
||||
while (match_len < search_len &&
|
||||
lit_utf8_iterator_read_next (&original_it) == lit_utf8_iterator_read_next (&search_it))
|
||||
lit_utf8_read_next (&original_str_curr_p) == lit_utf8_read_next (&search_str_curr_p))
|
||||
{
|
||||
match_len++;
|
||||
}
|
||||
@ -409,9 +408,9 @@ ecma_builtin_string_prototype_object_index_of (ecma_value_t this_arg, /**< this
|
||||
else
|
||||
{
|
||||
/* reset iterators */
|
||||
lit_utf8_iterator_seek_bos (&search_it);
|
||||
lit_utf8_iterator_seek (&original_it, stored_original_pos);
|
||||
lit_utf8_iterator_incr (&original_it);
|
||||
search_str_curr_p = search_str_utf8_p;
|
||||
original_str_curr_p = stored_original_str_curr_p;
|
||||
lit_utf8_incr (&original_str_curr_p);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
@ -765,7 +764,7 @@ typedef struct
|
||||
|
||||
/* Replace value string part. */
|
||||
ecma_string_t *replace_string_p; /**< replace string */
|
||||
lit_utf8_iterator_t replace_iterator; /**< replace string iterator */
|
||||
lit_utf8_byte_t *replace_str_curr_p; /**< replace string iterator */
|
||||
} ecma_builtin_replace_search_ctx_t;
|
||||
|
||||
/**
|
||||
@ -907,42 +906,44 @@ ecma_builtin_string_prototype_object_replace_match (ecma_builtin_replace_search_
|
||||
(ssize_t) (input_size));
|
||||
JERRY_ASSERT (sz >= 0);
|
||||
|
||||
lit_utf8_iterator_t search_iterator = lit_utf8_iterator_create (search_start_p, search_size);
|
||||
lit_utf8_iterator_t input_iterator = lit_utf8_iterator_create (input_start_p, input_size);
|
||||
lit_utf8_byte_t *search_str_curr_p = search_start_p;
|
||||
lit_utf8_byte_t *input_str_curr_p = input_start_p;
|
||||
|
||||
ecma_length_t match_start = 0;
|
||||
ecma_length_t match_end = 0;
|
||||
bool match_found = false;
|
||||
|
||||
if (lit_utf8_iterator_is_eos (&search_iterator))
|
||||
if (!search_size)
|
||||
{
|
||||
/* Empty string, always matches. */
|
||||
match_found = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_char_t first_char = lit_utf8_iterator_read_next (&search_iterator);
|
||||
const lit_utf8_byte_t *input_str_end_p = input_start_p + input_size;
|
||||
const lit_utf8_byte_t *search_str_end_p = search_start_p + search_size;
|
||||
ecma_char_t first_char = lit_utf8_read_next (&search_str_curr_p);
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&input_iterator))
|
||||
while (input_str_curr_p < input_str_end_p)
|
||||
{
|
||||
if (lit_utf8_iterator_read_next (&input_iterator) == first_char)
|
||||
if (lit_utf8_read_next (&input_str_curr_p) == first_char)
|
||||
{
|
||||
/* Local copy to preserve the original value of the iterators. */
|
||||
lit_utf8_iterator_t nested_search_iterator = search_iterator;
|
||||
lit_utf8_iterator_t nested_input_iterator = input_iterator;
|
||||
/* Local copy to preserve the original value. */
|
||||
lit_utf8_byte_t *nested_search_str_curr_p = search_str_curr_p;
|
||||
lit_utf8_byte_t *nested_input_str_curr_p = input_str_curr_p;
|
||||
match_end = match_start + 1;
|
||||
|
||||
match_found = true;
|
||||
while (!lit_utf8_iterator_is_eos (&nested_search_iterator))
|
||||
while (nested_search_str_curr_p < search_str_end_p)
|
||||
{
|
||||
if (lit_utf8_iterator_is_eos (&nested_input_iterator))
|
||||
if (nested_input_str_curr_p >= input_str_end_p)
|
||||
{
|
||||
match_found = false;
|
||||
break;
|
||||
}
|
||||
|
||||
ecma_char_t search_character = lit_utf8_iterator_read_next (&nested_search_iterator);
|
||||
ecma_char_t input_character = lit_utf8_iterator_read_next (&nested_input_iterator);
|
||||
ecma_char_t search_character = lit_utf8_read_next (&nested_search_str_curr_p);
|
||||
ecma_char_t input_character = lit_utf8_read_next (&nested_input_str_curr_p);
|
||||
|
||||
if (search_character != input_character)
|
||||
{
|
||||
@ -1095,19 +1096,18 @@ ecma_builtin_string_prototype_object_replace_get_string (ecma_builtin_replace_se
|
||||
ecma_length_t previous_start = 0;
|
||||
ecma_length_t current_position = 0;
|
||||
|
||||
lit_utf8_iterator_t replace_iterator = context_p->replace_iterator;
|
||||
lit_utf8_byte_t *replace_str_curr_p = context_p->replace_str_curr_p;
|
||||
lit_utf8_byte_t *replace_str_end_p = replace_str_curr_p + ecma_string_get_size (context_p->replace_string_p);
|
||||
|
||||
JERRY_ASSERT (lit_utf8_iterator_is_bos (&replace_iterator));
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&replace_iterator))
|
||||
while (replace_str_curr_p < replace_str_end_p)
|
||||
{
|
||||
ecma_char_t action = LIT_CHAR_NULL;
|
||||
|
||||
if (lit_utf8_iterator_read_next (&replace_iterator) == LIT_CHAR_DOLLAR_SIGN)
|
||||
if (*replace_str_curr_p++ == LIT_CHAR_DOLLAR_SIGN)
|
||||
{
|
||||
if (!lit_utf8_iterator_is_eos (&replace_iterator))
|
||||
if (replace_str_curr_p < replace_str_end_p)
|
||||
{
|
||||
action = lit_utf8_iterator_peek_next (&replace_iterator);
|
||||
action = *replace_str_curr_p;
|
||||
|
||||
if (action == LIT_CHAR_DOLLAR_SIGN)
|
||||
{
|
||||
@ -1125,9 +1125,9 @@ ecma_builtin_string_prototype_object_replace_get_string (ecma_builtin_replace_se
|
||||
}
|
||||
else if (index == 0 || match_length > 10)
|
||||
{
|
||||
lit_utf8_iterator_incr (&replace_iterator);
|
||||
replace_str_curr_p++;
|
||||
|
||||
ecma_char_t next_character = lit_utf8_iterator_peek_next (&replace_iterator);
|
||||
ecma_char_t next_character = *replace_str_curr_p;
|
||||
|
||||
if (next_character >= LIT_CHAR_0 && next_character <= LIT_CHAR_9)
|
||||
{
|
||||
@ -1138,7 +1138,7 @@ ecma_builtin_string_prototype_object_replace_get_string (ecma_builtin_replace_se
|
||||
}
|
||||
}
|
||||
|
||||
lit_utf8_iterator_decr (&replace_iterator);
|
||||
replace_str_curr_p--;
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
@ -1162,7 +1162,7 @@ ecma_builtin_string_prototype_object_replace_get_string (ecma_builtin_replace_se
|
||||
previous_start,
|
||||
current_position,
|
||||
true);
|
||||
lit_utf8_iterator_incr (&replace_iterator);
|
||||
replace_str_curr_p++;
|
||||
|
||||
if (action == LIT_CHAR_DOLLAR_SIGN)
|
||||
{
|
||||
@ -1198,16 +1198,16 @@ ecma_builtin_string_prototype_object_replace_get_string (ecma_builtin_replace_se
|
||||
index = (uint32_t) (action - LIT_CHAR_0);
|
||||
|
||||
if ((match_length > 10 || index == 0)
|
||||
&& !lit_utf8_iterator_is_eos (&replace_iterator))
|
||||
&& replace_str_curr_p < replace_str_end_p)
|
||||
{
|
||||
action = lit_utf8_iterator_peek_next (&replace_iterator);
|
||||
action = *replace_str_curr_p;
|
||||
if (action >= LIT_CHAR_0 && action <= LIT_CHAR_9)
|
||||
{
|
||||
uint32_t full_index = index * 10 + (uint32_t) (action - LIT_CHAR_0);
|
||||
if (full_index < match_length)
|
||||
{
|
||||
index = full_index;
|
||||
lit_utf8_iterator_incr (&replace_iterator);
|
||||
replace_str_curr_p++;
|
||||
current_position++;
|
||||
}
|
||||
}
|
||||
@ -1419,7 +1419,7 @@ ecma_builtin_string_prototype_object_replace_main (ecma_builtin_replace_search_c
|
||||
JERRY_ASSERT (sz >= 0);
|
||||
|
||||
context_p->replace_string_p = replace_string_p;
|
||||
context_p->replace_iterator = lit_utf8_iterator_create (replace_start_p, replace_size);
|
||||
context_p->replace_str_curr_p = replace_start_p;
|
||||
|
||||
ret_value = ecma_builtin_string_prototype_object_replace_loop (context_p);
|
||||
|
||||
@ -2300,11 +2300,12 @@ ecma_builtin_string_prototype_object_conversion_helper (ecma_value_t this_arg, /
|
||||
*/
|
||||
|
||||
lit_utf8_size_t output_length = 0;
|
||||
lit_utf8_iterator_t input_iterator = lit_utf8_iterator_create (input_start_p, input_size);
|
||||
lit_utf8_byte_t *input_str_curr_p = input_start_p;
|
||||
const lit_utf8_byte_t *input_str_end_p = input_start_p + input_size;
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&input_iterator))
|
||||
while (input_str_curr_p < input_str_end_p)
|
||||
{
|
||||
ecma_char_t character = lit_utf8_iterator_read_next (&input_iterator);
|
||||
ecma_char_t character = lit_utf8_read_next (&input_str_curr_p);
|
||||
ecma_char_t character_buffer[LIT_MAXIMUM_OTHER_CASE_LENGTH];
|
||||
lit_utf8_byte_t utf8_byte_buffer[LIT_CESU8_MAX_BYTES_IN_CODE_POINT];
|
||||
lit_utf8_size_t character_length;
|
||||
@ -2339,11 +2340,11 @@ ecma_builtin_string_prototype_object_conversion_helper (ecma_value_t this_arg, /
|
||||
lit_utf8_byte_t *output_char_p = output_start_p;
|
||||
|
||||
/* Encoding the output. */
|
||||
lit_utf8_iterator_seek_bos (&input_iterator);
|
||||
input_str_curr_p = input_start_p;
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&input_iterator))
|
||||
while (input_str_curr_p < input_str_end_p)
|
||||
{
|
||||
ecma_char_t character = lit_utf8_iterator_read_next (&input_iterator);
|
||||
ecma_char_t character = lit_utf8_read_next (&input_str_curr_p);
|
||||
ecma_char_t character_buffer[LIT_MAXIMUM_OTHER_CASE_LENGTH];
|
||||
lit_utf8_size_t character_length;
|
||||
|
||||
|
||||
@ -74,12 +74,13 @@ re_parse_regexp_flags (ecma_string_t *flags_str_p, /**< Input string with flags
|
||||
ssize_t sz = ecma_string_to_utf8_string (flags_str_p, flags_start_p, (ssize_t) flags_str_size);
|
||||
JERRY_ASSERT (sz >= 0);
|
||||
|
||||
lit_utf8_iterator_t iter = lit_utf8_iterator_create (flags_start_p, flags_str_size);
|
||||
lit_utf8_byte_t *flags_str_curr_p = flags_start_p;
|
||||
const lit_utf8_byte_t *flags_str_end_p = flags_start_p + flags_str_size;
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&iter)
|
||||
while (flags_str_curr_p < flags_str_end_p
|
||||
&& ecma_is_completion_value_empty (ret_value))
|
||||
{
|
||||
switch (lit_utf8_iterator_read_next (&iter))
|
||||
switch (*flags_str_curr_p++)
|
||||
{
|
||||
case 'g':
|
||||
{
|
||||
@ -335,12 +336,14 @@ re_canonicalize (ecma_char_t ch, /**< character */
|
||||
static ecma_completion_value_t
|
||||
re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
re_bytecode_t *bc_p, /**< pointer to the current RegExp bytecode */
|
||||
lit_utf8_iterator_t iter, /**< input string iterator */
|
||||
lit_utf8_iterator_t *out_iter_p) /**< Output: matching substring iterator */
|
||||
lit_utf8_byte_t *str_p, /**< input string pointer */
|
||||
lit_utf8_byte_t **out_str_p) /**< Output: matching substring iterator */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
re_opcode_t op;
|
||||
|
||||
lit_utf8_byte_t *str_curr_p = str_p;
|
||||
|
||||
while ((op = re_get_opcode (&bc_p)))
|
||||
{
|
||||
switch (op)
|
||||
@ -348,20 +351,20 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
case RE_OP_MATCH:
|
||||
{
|
||||
JERRY_DDLOG ("Execute RE_OP_MATCH: match\n");
|
||||
*out_iter_p = iter;
|
||||
*out_str_p = str_curr_p;
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
return ret_value; /* match */
|
||||
}
|
||||
case RE_OP_CHAR:
|
||||
{
|
||||
if (lit_utf8_iterator_is_eos (&iter))
|
||||
if (str_curr_p >= re_ctx_p->input_end_p)
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); /* fail */
|
||||
}
|
||||
|
||||
bool is_ignorecase = re_ctx_p->flags & RE_FLAG_IGNORE_CASE;
|
||||
ecma_char_t ch1 = (ecma_char_t) re_get_value (&bc_p); /* Already canonicalized. */
|
||||
ecma_char_t ch2 = re_canonicalize (lit_utf8_iterator_read_next (&iter), is_ignorecase);
|
||||
ecma_char_t ch2 = re_canonicalize (lit_utf8_read_next (&str_curr_p), is_ignorecase);
|
||||
JERRY_DDLOG ("Character matching %d to %d: ", ch1, ch2);
|
||||
|
||||
if (ch1 != ch2)
|
||||
@ -376,12 +379,12 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
}
|
||||
case RE_OP_PERIOD:
|
||||
{
|
||||
if (lit_utf8_iterator_is_eos (&iter))
|
||||
if (str_curr_p >= re_ctx_p->input_end_p)
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); /* fail */
|
||||
}
|
||||
|
||||
ecma_char_t ch = lit_utf8_iterator_read_next (&iter);
|
||||
ecma_char_t ch = lit_utf8_read_next (&str_curr_p);
|
||||
JERRY_DDLOG ("Period matching '.' to %d: ", (uint32_t) ch);
|
||||
|
||||
if (lit_char_is_line_terminator (ch))
|
||||
@ -397,7 +400,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
{
|
||||
JERRY_DDLOG ("Execute RE_OP_ASSERT_START: ");
|
||||
|
||||
if ((iter.buf_p + iter.buf_pos.offset) <= re_ctx_p->input_start_p)
|
||||
if (str_curr_p <= re_ctx_p->input_start_p)
|
||||
{
|
||||
JERRY_DDLOG ("match\n");
|
||||
break;
|
||||
@ -409,7 +412,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); /* fail */
|
||||
}
|
||||
|
||||
if (lit_char_is_line_terminator (lit_utf8_iterator_peek_prev (&iter)))
|
||||
if (lit_char_is_line_terminator (lit_utf8_peek_prev (str_curr_p)))
|
||||
{
|
||||
JERRY_DDLOG ("match\n");
|
||||
break;
|
||||
@ -422,7 +425,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
{
|
||||
JERRY_DDLOG ("Execute RE_OP_ASSERT_END: ");
|
||||
|
||||
if ((iter.buf_p + iter.buf_pos.offset) >= re_ctx_p->input_end_p)
|
||||
if (str_curr_p >= re_ctx_p->input_end_p)
|
||||
{
|
||||
JERRY_DDLOG ("match\n");
|
||||
break; /* tail merge */
|
||||
@ -434,7 +437,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); /* fail */
|
||||
}
|
||||
|
||||
if (lit_char_is_line_terminator (lit_utf8_iterator_peek_next (&iter)))
|
||||
if (lit_char_is_line_terminator (lit_utf8_peek_next (str_curr_p)))
|
||||
{
|
||||
JERRY_DDLOG ("match\n");
|
||||
break; /* tail merge */
|
||||
@ -448,22 +451,22 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
{
|
||||
bool is_wordchar_left, is_wordchar_right;
|
||||
|
||||
if ((iter.buf_p + iter.buf_pos.offset) <= re_ctx_p->input_start_p)
|
||||
if (str_curr_p <= re_ctx_p->input_start_p)
|
||||
{
|
||||
is_wordchar_left = false; /* not a wordchar */
|
||||
}
|
||||
else
|
||||
{
|
||||
is_wordchar_left = lit_char_is_word_char (lit_utf8_iterator_peek_prev (&iter));
|
||||
is_wordchar_left = lit_char_is_word_char (lit_utf8_peek_prev (str_curr_p));
|
||||
}
|
||||
|
||||
if ((iter.buf_p + iter.buf_pos.offset) >= re_ctx_p->input_end_p)
|
||||
if (str_curr_p >= re_ctx_p->input_end_p)
|
||||
{
|
||||
is_wordchar_right = false; /* not a wordchar */
|
||||
}
|
||||
else
|
||||
{
|
||||
is_wordchar_right = lit_char_is_word_char (lit_utf8_iterator_peek_next (&iter));
|
||||
is_wordchar_right = lit_char_is_word_char (lit_utf8_peek_next (str_curr_p));
|
||||
}
|
||||
|
||||
if (op == RE_OP_ASSERT_WORD_BOUNDARY)
|
||||
@ -494,21 +497,21 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
case RE_OP_LOOKAHEAD_NEG:
|
||||
{
|
||||
ecma_completion_value_t match_value = ecma_make_empty_completion_value ();
|
||||
lit_utf8_iterator_t sub_iter = lit_utf8_iterator_create (NULL, 0);
|
||||
lit_utf8_byte_t *sub_str_p = NULL;
|
||||
|
||||
uint32_t array_size = re_ctx_p->num_of_captures + re_ctx_p->num_of_non_captures;
|
||||
MEM_DEFINE_LOCAL_ARRAY (saved_bck_p, array_size, lit_utf8_iterator_t);
|
||||
MEM_DEFINE_LOCAL_ARRAY (saved_bck_p, array_size, lit_utf8_byte_t *);
|
||||
|
||||
size_t size = (size_t) (array_size) * sizeof (lit_utf8_iterator_t);
|
||||
size_t size = (size_t) (array_size) * sizeof (lit_utf8_byte_t *);
|
||||
memcpy (saved_bck_p, re_ctx_p->saved_p, size);
|
||||
|
||||
do
|
||||
{
|
||||
uint32_t offset = re_get_value (&bc_p);
|
||||
|
||||
if (!sub_iter.buf_p)
|
||||
if (!sub_str_p)
|
||||
{
|
||||
match_value = re_match_regexp (re_ctx_p, bc_p, iter, &sub_iter);
|
||||
match_value = re_match_regexp (re_ctx_p, bc_p, str_curr_p, &sub_str_p);
|
||||
if (ecma_is_completion_value_throw (match_value))
|
||||
{
|
||||
break;
|
||||
@ -522,11 +525,11 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
{
|
||||
JERRY_DDLOG ("Execute RE_OP_LOOKAHEAD_POS/NEG: ");
|
||||
ecma_free_completion_value (match_value);
|
||||
if ((op == RE_OP_LOOKAHEAD_POS && sub_iter.buf_p)
|
||||
|| (op == RE_OP_LOOKAHEAD_NEG && !sub_iter.buf_p))
|
||||
if ((op == RE_OP_LOOKAHEAD_POS && sub_str_p)
|
||||
|| (op == RE_OP_LOOKAHEAD_NEG && !sub_str_p))
|
||||
{
|
||||
JERRY_DDLOG ("match\n");
|
||||
match_value = re_match_regexp (re_ctx_p, bc_p, iter, &sub_iter);
|
||||
match_value = re_match_regexp (re_ctx_p, bc_p, str_curr_p, &sub_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -539,7 +542,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
{
|
||||
if (ecma_is_value_true (match_value))
|
||||
{
|
||||
*out_iter_p = sub_iter;
|
||||
*out_str_p = sub_str_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -559,14 +562,14 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
bool is_match;
|
||||
|
||||
JERRY_DDLOG ("Execute RE_OP_CHAR_CLASS/RE_OP_INV_CHAR_CLASS, ");
|
||||
if (lit_utf8_iterator_is_eos (&iter))
|
||||
if (str_curr_p >= re_ctx_p->input_end_p)
|
||||
{
|
||||
JERRY_DDLOG ("fail\n");
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); /* fail */
|
||||
}
|
||||
|
||||
bool is_ignorecase = re_ctx_p->flags & RE_FLAG_IGNORE_CASE;
|
||||
ecma_char_t curr_ch = re_canonicalize (lit_utf8_iterator_read_next (&iter), is_ignorecase);
|
||||
ecma_char_t curr_ch = re_canonicalize (lit_utf8_read_next (&str_curr_p), is_ignorecase);
|
||||
|
||||
num_of_ranges = re_get_value (&bc_p);
|
||||
is_match = false;
|
||||
@ -615,26 +618,26 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
backref_idx *= 2; /* backref n -> saved indices [n*2, n*2+1] */
|
||||
JERRY_ASSERT (backref_idx >= 2 && backref_idx + 1 < re_ctx_p->num_of_captures);
|
||||
|
||||
if (!re_ctx_p->saved_p[backref_idx].buf_p || !re_ctx_p->saved_p[backref_idx + 1].buf_p)
|
||||
if (!re_ctx_p->saved_p[backref_idx] || !re_ctx_p->saved_p[backref_idx + 1])
|
||||
{
|
||||
JERRY_DDLOG ("match\n");
|
||||
break; /* capture is 'undefined', always matches! */
|
||||
}
|
||||
|
||||
lit_utf8_iterator_t sub_iter = re_ctx_p->saved_p[backref_idx];
|
||||
lit_utf8_byte_t *sub_str_p = re_ctx_p->saved_p[backref_idx];
|
||||
|
||||
while (sub_iter.buf_pos.offset < re_ctx_p->saved_p[backref_idx + 1].buf_pos.offset)
|
||||
while (sub_str_p < re_ctx_p->saved_p[backref_idx + 1])
|
||||
{
|
||||
ecma_char_t ch1, ch2;
|
||||
|
||||
if ((iter.buf_p + iter.buf_pos.offset) >= re_ctx_p->input_end_p)
|
||||
if (str_curr_p >= re_ctx_p->input_end_p)
|
||||
{
|
||||
JERRY_DDLOG ("fail\n");
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); /* fail */
|
||||
}
|
||||
|
||||
ch1 = lit_utf8_iterator_read_next (&sub_iter);
|
||||
ch2 = lit_utf8_iterator_read_next (&iter);
|
||||
ch1 = lit_utf8_read_next (&sub_str_p);
|
||||
ch2 = lit_utf8_read_next (&str_curr_p);
|
||||
|
||||
if (ch1 != ch2)
|
||||
{
|
||||
@ -650,17 +653,17 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
re_bytecode_t *old_bc_p;
|
||||
|
||||
JERRY_DDLOG ("Execute RE_OP_SAVE_AT_START\n");
|
||||
lit_utf8_iterator_t old_start_p = re_ctx_p->saved_p[RE_GLOBAL_START_IDX];
|
||||
re_ctx_p->saved_p[RE_GLOBAL_START_IDX] = iter;
|
||||
lit_utf8_byte_t *old_start_p = re_ctx_p->saved_p[RE_GLOBAL_START_IDX];
|
||||
re_ctx_p->saved_p[RE_GLOBAL_START_IDX] = str_curr_p;
|
||||
|
||||
do
|
||||
{
|
||||
uint32_t offset = re_get_value (&bc_p);
|
||||
lit_utf8_iterator_t sub_iter = lit_utf8_iterator_create (NULL, 0);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, iter, &sub_iter);
|
||||
lit_utf8_byte_t *sub_str_p = NULL;
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, str_curr_p, &sub_str_p);
|
||||
if (ecma_is_value_true (match_value))
|
||||
{
|
||||
*out_iter_p = sub_iter;
|
||||
*out_str_p = sub_str_p;
|
||||
return match_value; /* match */
|
||||
}
|
||||
else if (ecma_is_completion_value_throw (match_value))
|
||||
@ -679,8 +682,8 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
case RE_OP_SAVE_AND_MATCH:
|
||||
{
|
||||
JERRY_DDLOG ("End of pattern is reached: match\n");
|
||||
re_ctx_p->saved_p[RE_GLOBAL_END_IDX] = iter;
|
||||
*out_iter_p = iter;
|
||||
re_ctx_p->saved_p[RE_GLOBAL_END_IDX] = str_curr_p;
|
||||
*out_str_p = str_curr_p;
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); /* match */
|
||||
}
|
||||
case RE_OP_ALTERNATIVE:
|
||||
@ -711,8 +714,8 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
* after the group first, if zero iteration is allowed.
|
||||
*/
|
||||
uint32_t start_idx, iter_idx, offset;
|
||||
lit_utf8_iterator_t old_start = lit_utf8_iterator_create (NULL, 0);
|
||||
lit_utf8_iterator_t sub_iter = lit_utf8_iterator_create (NULL, 0);
|
||||
lit_utf8_byte_t *old_start_p = NULL;
|
||||
lit_utf8_byte_t *sub_str_p = NULL;
|
||||
re_bytecode_t *old_bc_p;
|
||||
|
||||
old_bc_p = bc_p; /* save the bytecode start position of the group start */
|
||||
@ -725,8 +728,8 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
iter_idx = start_idx - 1;
|
||||
start_idx *= 2;
|
||||
|
||||
old_start = re_ctx_p->saved_p[start_idx];
|
||||
re_ctx_p->saved_p[start_idx] = iter;
|
||||
old_start_p = re_ctx_p->saved_p[start_idx];
|
||||
re_ctx_p->saved_p[start_idx] = str_curr_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -740,11 +743,11 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
bc_p += offset;
|
||||
|
||||
/* Try to match after the close paren if zero is allowed */
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, iter, &sub_iter);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, str_curr_p, &sub_str_p);
|
||||
|
||||
if (ecma_is_value_true (match_value))
|
||||
{
|
||||
*out_iter_p = sub_iter;
|
||||
*out_str_p = sub_str_p;
|
||||
return match_value; /* match */
|
||||
}
|
||||
else if (ecma_is_completion_value_throw (match_value))
|
||||
@ -753,7 +756,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
}
|
||||
if (RE_IS_CAPTURE_GROUP (op))
|
||||
{
|
||||
re_ctx_p->saved_p[start_idx] = old_start;
|
||||
re_ctx_p->saved_p[start_idx] = old_start_p;
|
||||
}
|
||||
|
||||
bc_p = old_bc_p;
|
||||
@ -765,7 +768,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
case RE_OP_NON_CAPTURE_GREEDY_ZERO_GROUP_START:
|
||||
{
|
||||
uint32_t start_idx, iter_idx, old_iteration_cnt, offset;
|
||||
lit_utf8_iterator_t sub_iter = lit_utf8_iterator_create (NULL, 0);
|
||||
lit_utf8_byte_t *sub_str_p = NULL;
|
||||
re_bytecode_t *old_bc_p;
|
||||
re_bytecode_t *end_bc_p = NULL;
|
||||
start_idx = re_get_value (&bc_p);
|
||||
@ -790,18 +793,18 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
start_idx += re_ctx_p->num_of_captures;
|
||||
}
|
||||
|
||||
lit_utf8_iterator_t old_start = re_ctx_p->saved_p[start_idx];
|
||||
lit_utf8_byte_t *old_start_p = re_ctx_p->saved_p[start_idx];
|
||||
old_iteration_cnt = re_ctx_p->num_of_iterations_p[iter_idx];
|
||||
re_ctx_p->saved_p[start_idx] = iter;
|
||||
re_ctx_p->saved_p[start_idx] = str_curr_p;
|
||||
re_ctx_p->num_of_iterations_p[iter_idx] = 0;
|
||||
|
||||
do
|
||||
{
|
||||
offset = re_get_value (&bc_p);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, iter, &sub_iter);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, str_curr_p, &sub_str_p);
|
||||
if (ecma_is_value_true (match_value))
|
||||
{
|
||||
*out_iter_p = sub_iter;
|
||||
*out_str_p = sub_str_p;
|
||||
return match_value; /* match */
|
||||
}
|
||||
else if (ecma_is_completion_value_throw (match_value))
|
||||
@ -820,11 +823,11 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
|| op == RE_OP_NON_CAPTURE_GREEDY_ZERO_GROUP_START)
|
||||
{
|
||||
JERRY_ASSERT (end_bc_p);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, end_bc_p, iter, &sub_iter);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, end_bc_p, str_curr_p, &sub_str_p);
|
||||
|
||||
if (ecma_is_value_true (match_value))
|
||||
{
|
||||
*out_iter_p = sub_iter;
|
||||
*out_str_p = sub_str_p;
|
||||
return match_value; /* match */
|
||||
}
|
||||
else if (ecma_is_completion_value_throw (match_value))
|
||||
@ -833,7 +836,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
}
|
||||
}
|
||||
|
||||
re_ctx_p->saved_p[start_idx] = old_start;
|
||||
re_ctx_p->saved_p[start_idx] = old_start_p;
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); /* fail */
|
||||
}
|
||||
case RE_OP_CAPTURE_NON_GREEDY_GROUP_END:
|
||||
@ -870,14 +873,14 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
if (re_ctx_p->num_of_iterations_p[iter_idx] >= min
|
||||
&& re_ctx_p->num_of_iterations_p[iter_idx] <= max)
|
||||
{
|
||||
lit_utf8_iterator_t old_end = re_ctx_p->saved_p[end_idx];
|
||||
re_ctx_p->saved_p[end_idx] = iter;
|
||||
lit_utf8_byte_t *old_end_p = re_ctx_p->saved_p[end_idx];
|
||||
re_ctx_p->saved_p[end_idx] = str_curr_p;
|
||||
|
||||
lit_utf8_iterator_t sub_iter = lit_utf8_iterator_create (NULL, 0);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, iter, &sub_iter);
|
||||
lit_utf8_byte_t *sub_str_p = NULL;
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, str_curr_p, &sub_str_p);
|
||||
if (ecma_is_value_true (match_value))
|
||||
{
|
||||
*out_iter_p = sub_iter;
|
||||
*out_str_p = sub_str_p;
|
||||
return match_value; /* match */
|
||||
}
|
||||
else if (ecma_is_completion_value_throw (match_value))
|
||||
@ -885,7 +888,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
return match_value;
|
||||
}
|
||||
|
||||
re_ctx_p->saved_p[end_idx] = old_end;
|
||||
re_ctx_p->saved_p[end_idx] = old_end_p;
|
||||
}
|
||||
re_ctx_p->num_of_iterations_p[iter_idx]--;
|
||||
bc_p = old_bc_p;
|
||||
@ -897,9 +900,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
case RE_OP_NON_CAPTURE_GREEDY_GROUP_END:
|
||||
{
|
||||
uint32_t start_idx, end_idx, iter_idx, min, max, offset;
|
||||
lit_utf8_iterator_t old_start = lit_utf8_iterator_create (NULL, 0);
|
||||
lit_utf8_iterator_t old_end = lit_utf8_iterator_create (NULL, 0);
|
||||
lit_utf8_iterator_t sub_iter = lit_utf8_iterator_create (NULL, 0);
|
||||
lit_utf8_byte_t *old_start_p = NULL;
|
||||
lit_utf8_byte_t *old_end_p = NULL;
|
||||
lit_utf8_byte_t *sub_str_p = NULL;
|
||||
re_bytecode_t *old_bc_p;
|
||||
|
||||
end_idx = re_get_value (&bc_p);
|
||||
@ -924,8 +927,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
|
||||
/* Check the empty iteration if the minimum number of iterations is reached. */
|
||||
if (re_ctx_p->num_of_iterations_p[iter_idx] >= min
|
||||
&& iter.buf_p == re_ctx_p->saved_p[start_idx].buf_p
|
||||
&& iter.buf_pos.offset == re_ctx_p->saved_p[start_idx].buf_pos.offset)
|
||||
&& str_curr_p== re_ctx_p->saved_p[start_idx])
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); /* fail */
|
||||
}
|
||||
@ -933,21 +935,21 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
re_ctx_p->num_of_iterations_p[iter_idx]++;
|
||||
|
||||
old_bc_p = bc_p; /* Save the bytecode end position of the END opcodes for matching after it. */
|
||||
old_end = re_ctx_p->saved_p[end_idx];
|
||||
re_ctx_p->saved_p[end_idx] = iter;
|
||||
old_end_p = re_ctx_p->saved_p[end_idx];
|
||||
re_ctx_p->saved_p[end_idx] = str_curr_p;
|
||||
|
||||
if (re_ctx_p->num_of_iterations_p[iter_idx] < max)
|
||||
{
|
||||
bc_p -= offset;
|
||||
offset = re_get_value (&bc_p);
|
||||
|
||||
old_start = re_ctx_p->saved_p[start_idx];
|
||||
re_ctx_p->saved_p[start_idx] = iter;
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, iter, &sub_iter);
|
||||
old_start_p = re_ctx_p->saved_p[start_idx];
|
||||
re_ctx_p->saved_p[start_idx] = str_curr_p;
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, str_curr_p, &sub_str_p);
|
||||
|
||||
if (ecma_is_value_true (match_value))
|
||||
{
|
||||
*out_iter_p = sub_iter;
|
||||
*out_str_p = sub_str_p;
|
||||
return match_value; /* match */
|
||||
}
|
||||
else if (ecma_is_completion_value_throw (match_value))
|
||||
@ -955,7 +957,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
return match_value;
|
||||
}
|
||||
|
||||
re_ctx_p->saved_p[start_idx] = old_start;
|
||||
re_ctx_p->saved_p[start_idx] = old_start_p;
|
||||
|
||||
/* Try to match alternatives if any. */
|
||||
bc_p += offset;
|
||||
@ -964,14 +966,14 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
bc_p++; /* RE_OP_ALTERNATIVE */
|
||||
offset = re_get_value (&bc_p);
|
||||
|
||||
old_start = re_ctx_p->saved_p[start_idx];
|
||||
re_ctx_p->saved_p[start_idx] = iter;
|
||||
old_start_p = re_ctx_p->saved_p[start_idx];
|
||||
re_ctx_p->saved_p[start_idx] = str_curr_p;
|
||||
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, iter, &sub_iter);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, str_curr_p, &sub_str_p);
|
||||
|
||||
if (ecma_is_value_true (match_value))
|
||||
{
|
||||
*out_iter_p = sub_iter;
|
||||
*out_str_p = sub_str_p;
|
||||
return match_value; /* match */
|
||||
}
|
||||
else if (ecma_is_completion_value_throw (match_value))
|
||||
@ -979,7 +981,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
return match_value;
|
||||
}
|
||||
|
||||
re_ctx_p->saved_p[start_idx] = old_start;
|
||||
re_ctx_p->saved_p[start_idx] = old_start_p;
|
||||
bc_p += offset;
|
||||
}
|
||||
}
|
||||
@ -988,11 +990,11 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
&& re_ctx_p->num_of_iterations_p[iter_idx] <= max)
|
||||
{
|
||||
/* Try to match the rest of the bytecode. */
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, old_bc_p, iter, &sub_iter);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, old_bc_p, str_curr_p, &sub_str_p);
|
||||
|
||||
if (ecma_is_value_true (match_value))
|
||||
{
|
||||
*out_iter_p = sub_iter;
|
||||
*out_str_p = sub_str_p;
|
||||
return match_value; /* match */
|
||||
}
|
||||
else if (ecma_is_completion_value_throw (match_value))
|
||||
@ -1002,14 +1004,14 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
}
|
||||
|
||||
/* restore if fails */
|
||||
re_ctx_p->saved_p[end_idx] = old_end;
|
||||
re_ctx_p->saved_p[end_idx] = old_end_p;
|
||||
re_ctx_p->num_of_iterations_p[iter_idx]--;
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); /* fail */
|
||||
}
|
||||
case RE_OP_NON_GREEDY_ITERATOR:
|
||||
{
|
||||
uint32_t min, max, offset, num_of_iter;
|
||||
lit_utf8_iterator_t sub_iter = lit_utf8_iterator_create (NULL, 0);
|
||||
lit_utf8_byte_t *sub_str_p = NULL;
|
||||
|
||||
min = re_get_value (&bc_p);
|
||||
max = re_get_value (&bc_p);
|
||||
@ -1023,11 +1025,14 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
{
|
||||
if (num_of_iter >= min)
|
||||
{
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p + offset, iter, &sub_iter);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p,
|
||||
bc_p + offset,
|
||||
str_curr_p,
|
||||
&sub_str_p);
|
||||
|
||||
if (ecma_is_value_true (match_value))
|
||||
{
|
||||
*out_iter_p = sub_iter;
|
||||
*out_str_p = sub_str_p;
|
||||
return match_value; /* match */
|
||||
}
|
||||
else if (ecma_is_completion_value_throw (match_value))
|
||||
@ -1036,7 +1041,10 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
}
|
||||
}
|
||||
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, iter, &sub_iter);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p,
|
||||
bc_p,
|
||||
str_curr_p,
|
||||
&sub_str_p);
|
||||
|
||||
if (!ecma_is_value_true (match_value))
|
||||
{
|
||||
@ -1048,7 +1056,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
break;
|
||||
}
|
||||
|
||||
iter = sub_iter;
|
||||
str_curr_p = sub_str_p;
|
||||
num_of_iter++;
|
||||
}
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); /* fail */
|
||||
@ -1056,7 +1064,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
case RE_OP_GREEDY_ITERATOR:
|
||||
{
|
||||
uint32_t min, max, offset, num_of_iter;
|
||||
lit_utf8_iterator_t sub_iter = lit_utf8_iterator_create (NULL, 0);
|
||||
lit_utf8_byte_t *sub_str_p = NULL;
|
||||
|
||||
min = re_get_value (&bc_p);
|
||||
max = re_get_value (&bc_p);
|
||||
@ -1069,7 +1077,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
|
||||
while (num_of_iter < max)
|
||||
{
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, iter, &sub_iter);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, str_curr_p, &sub_str_p);
|
||||
|
||||
if (!ecma_is_value_true (match_value))
|
||||
{
|
||||
@ -1081,17 +1089,20 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
break;
|
||||
}
|
||||
|
||||
iter = sub_iter;
|
||||
str_curr_p = sub_str_p;
|
||||
num_of_iter++;
|
||||
}
|
||||
|
||||
while (num_of_iter >= min)
|
||||
{
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p + offset, iter, &sub_iter);
|
||||
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p,
|
||||
bc_p + offset,
|
||||
str_curr_p,
|
||||
&sub_str_p);
|
||||
|
||||
if (ecma_is_value_true (match_value))
|
||||
{
|
||||
*out_iter_p = sub_iter;
|
||||
*out_str_p = sub_str_p;
|
||||
return match_value; /* match */
|
||||
}
|
||||
else if (ecma_is_completion_value_throw (match_value))
|
||||
@ -1104,7 +1115,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
|
||||
break;
|
||||
}
|
||||
|
||||
lit_utf8_iterator_read_prev (&iter);
|
||||
lit_utf8_read_prev (&str_curr_p);
|
||||
num_of_iter--;
|
||||
}
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); /* fail */
|
||||
@ -1236,16 +1247,22 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
ecma_string_t *input_string_p = ecma_get_string_from_value (input_string);
|
||||
lit_utf8_size_t input_string_size = ecma_string_get_size (input_string_p);
|
||||
|
||||
MEM_DEFINE_LOCAL_ARRAY (input_utf8_buffer_p, input_string_size, lit_utf8_byte_t);
|
||||
MEM_DEFINE_LOCAL_ARRAY (input_buffer_p, input_string_size, lit_utf8_byte_t);
|
||||
|
||||
ssize_t sz = ecma_string_to_utf8_string (input_string_p, input_utf8_buffer_p, (ssize_t) input_string_size);
|
||||
ssize_t sz = ecma_string_to_utf8_string (input_string_p, input_buffer_p, (ssize_t) input_string_size);
|
||||
JERRY_ASSERT (sz >= 0);
|
||||
|
||||
lit_utf8_iterator_t iterator = lit_utf8_iterator_create (input_utf8_buffer_p, input_string_size);
|
||||
lit_utf8_byte_t *input_curr_p = input_buffer_p;
|
||||
|
||||
if (!input_string_size)
|
||||
{
|
||||
input_curr_p = (lit_utf8_byte_t *) lit_get_magic_string_utf8 (LIT_MAGIC_STRING__EMPTY);
|
||||
}
|
||||
lit_utf8_byte_t *input_end_p = input_buffer_p + input_string_size;
|
||||
|
||||
re_matcher_ctx_t re_ctx;
|
||||
re_ctx.input_start_p = iterator.buf_p;
|
||||
re_ctx.input_end_p = iterator.buf_p + iterator.buf_size;
|
||||
re_ctx.input_start_p = input_buffer_p;
|
||||
re_ctx.input_end_p = input_buffer_p + input_string_size;
|
||||
|
||||
/* 1. Read bytecode header and init regexp matcher context. */
|
||||
re_ctx.flags = (uint8_t) re_get_value (&bc_p);
|
||||
@ -1264,15 +1281,12 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
JERRY_ASSERT (re_ctx.num_of_captures % 2 == 0);
|
||||
re_ctx.num_of_non_captures = re_get_value (&bc_p);
|
||||
|
||||
/* We create an invalid iterator, that will be used to identify unused result values. */
|
||||
lit_utf8_iterator_t unused_iter = lit_utf8_iterator_create (NULL, 0);
|
||||
unused_iter.buf_p = (lit_utf8_byte_t *) 1;
|
||||
|
||||
MEM_DEFINE_LOCAL_ARRAY (saved_p, re_ctx.num_of_captures + re_ctx.num_of_non_captures, lit_utf8_iterator_t);
|
||||
MEM_DEFINE_LOCAL_ARRAY (saved_p, re_ctx.num_of_captures + re_ctx.num_of_non_captures, lit_utf8_byte_t *);
|
||||
|
||||
for (uint32_t i = 0; i < re_ctx.num_of_captures + re_ctx.num_of_non_captures; i++)
|
||||
{
|
||||
saved_p[i] = unused_iter;
|
||||
saved_p[i] = NULL;
|
||||
}
|
||||
re_ctx.saved_p = saved_p;
|
||||
|
||||
@ -1287,9 +1301,9 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
bool is_match = false;
|
||||
re_ctx.num_of_iterations_p = num_of_iter_p;
|
||||
int32_t index = 0;
|
||||
ecma_length_t input_str_len = lit_utf8_string_length (iterator.buf_p, iterator.buf_size);
|
||||
ecma_length_t input_str_len = lit_utf8_string_length (input_buffer_p, input_string_size);
|
||||
|
||||
if (iterator.buf_p && (re_ctx.flags & RE_FLAG_GLOBAL))
|
||||
if (input_buffer_p && (re_ctx.flags & RE_FLAG_GLOBAL))
|
||||
{
|
||||
ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL);
|
||||
ecma_property_t *lastindex_prop_p = ecma_op_object_get_property (regexp_object_p, magic_str_p);
|
||||
@ -1297,19 +1311,21 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (lastindex_num, lastindex_prop_p->u.named_data_property.value, ret_value)
|
||||
index = ecma_number_to_int32 (lastindex_num);
|
||||
|
||||
JERRY_ASSERT (iterator.buf_pos.offset == 0 && !iterator.buf_pos.is_non_bmp_middle);
|
||||
if (!lit_utf8_iterator_is_eos (&iterator)
|
||||
if (input_curr_p < input_end_p
|
||||
&& index <= (int32_t) input_str_len
|
||||
&& index > 0)
|
||||
{
|
||||
lit_utf8_iterator_advance (&iterator, (ecma_length_t) index);
|
||||
for (int i = 0; i < index; i++)
|
||||
{
|
||||
lit_utf8_incr (&input_curr_p);
|
||||
}
|
||||
}
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (lastindex_num);
|
||||
ecma_deref_ecma_string (magic_str_p);
|
||||
}
|
||||
|
||||
/* 2. Try to match */
|
||||
lit_utf8_iterator_t sub_iter = lit_utf8_iterator_create (NULL, 0);
|
||||
lit_utf8_byte_t *sub_str_p = NULL;
|
||||
|
||||
while (ecma_is_completion_value_empty (ret_value))
|
||||
{
|
||||
@ -1330,17 +1346,16 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_TRY_CATCH (match_value, re_match_regexp (&re_ctx, bc_p, iterator, &sub_iter), ret_value);
|
||||
|
||||
ECMA_TRY_CATCH (match_value, re_match_regexp (&re_ctx, bc_p, input_curr_p, &sub_str_p), ret_value);
|
||||
if (ecma_is_value_true (match_value))
|
||||
{
|
||||
is_match = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!lit_utf8_iterator_is_eos (&iterator))
|
||||
if (input_curr_p < input_end_p)
|
||||
{
|
||||
lit_utf8_iterator_advance (&iterator, 1);
|
||||
lit_utf8_incr (&input_curr_p);
|
||||
}
|
||||
index++;
|
||||
|
||||
@ -1348,11 +1363,21 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
}
|
||||
}
|
||||
|
||||
if (iterator.buf_p && (re_ctx.flags & RE_FLAG_GLOBAL))
|
||||
if (input_curr_p && (re_ctx.flags & RE_FLAG_GLOBAL))
|
||||
{
|
||||
ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL);
|
||||
ecma_number_t *lastindex_num_p = ecma_alloc_number ();
|
||||
*lastindex_num_p = sub_iter.buf_pos.offset;
|
||||
|
||||
if (sub_str_p)
|
||||
{
|
||||
*lastindex_num_p = lit_utf8_string_length (input_buffer_p,
|
||||
(lit_utf8_size_t) (sub_str_p - input_buffer_p));
|
||||
}
|
||||
else
|
||||
{
|
||||
*lastindex_num_p = ECMA_NUMBER_ZERO;
|
||||
}
|
||||
|
||||
ecma_op_object_put (regexp_object_p, magic_str_p, ecma_make_number_value (lastindex_num_p), true);
|
||||
ecma_dealloc_number (lastindex_num_p);
|
||||
ecma_deref_ecma_string (magic_str_p);
|
||||
@ -1366,7 +1391,7 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
ecma_completion_value_t result_array = ecma_op_create_array_object (0, 0, false);
|
||||
ecma_object_t *result_array_obj_p = ecma_get_object_from_completion_value (result_array);
|
||||
|
||||
ecma_string_t *input_str_p = ecma_new_ecma_string_from_utf8 (iterator.buf_p, iterator.buf_size);
|
||||
ecma_string_t *input_str_p = ecma_new_ecma_string_from_utf8 (input_buffer_p, input_string_size);
|
||||
re_set_result_array_properties (result_array_obj_p, input_str_p, re_ctx.num_of_captures / 2, index);
|
||||
ecma_deref_ecma_string (input_str_p);
|
||||
|
||||
@ -1374,18 +1399,16 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
{
|
||||
ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (i / 2);
|
||||
|
||||
/* Note: 'iter_p->buf_p == NULL' means the input is empty string */
|
||||
if ((re_ctx.saved_p[i].buf_p != unused_iter.buf_p && re_ctx.saved_p[i + 1].buf_p != unused_iter.buf_p)
|
||||
&& re_ctx.saved_p[i + 1].buf_pos.offset >= re_ctx.saved_p[i].buf_pos.offset)
|
||||
if (((re_ctx.saved_p[i] && re_ctx.saved_p[i + 1])
|
||||
&& re_ctx.saved_p[i + 1] >= re_ctx.saved_p[i]))
|
||||
{
|
||||
ecma_length_t capture_str_len;
|
||||
capture_str_len = (ecma_length_t) re_ctx.saved_p[i + 1].buf_pos.offset - re_ctx.saved_p[i].buf_pos.offset;
|
||||
capture_str_len = (ecma_length_t) (re_ctx.saved_p[i + 1] - re_ctx.saved_p[i]);
|
||||
ecma_string_t *capture_str_p;
|
||||
|
||||
if (capture_str_len > 0)
|
||||
{
|
||||
const lit_utf8_byte_t *utf8_str_p = re_ctx.saved_p[i].buf_p + re_ctx.saved_p[i].buf_pos.offset;
|
||||
capture_str_p = ecma_new_ecma_string_from_utf8 (utf8_str_p, capture_str_len);
|
||||
capture_str_p = ecma_new_ecma_string_from_utf8 (re_ctx.saved_p[i], capture_str_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1413,7 +1436,7 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
|
||||
MEM_FINALIZE_LOCAL_ARRAY (num_of_iter_p);
|
||||
MEM_FINALIZE_LOCAL_ARRAY (saved_p);
|
||||
MEM_FINALIZE_LOCAL_ARRAY (input_utf8_buffer_p);
|
||||
MEM_FINALIZE_LOCAL_ARRAY (input_buffer_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_regexp_exec_helper */
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
lit_utf8_iterator_t *saved_p; /**< saved result string pointers, ECMA 262 v5, 15.10.2.1, State */
|
||||
lit_utf8_byte_t **saved_p; /**< saved result string pointers, ECMA 262 v5, 15.10.2.1, State */
|
||||
const lit_utf8_byte_t *input_start_p; /**< start of input pattern string */
|
||||
const lit_utf8_byte_t *input_end_p; /**< end of input pattern string */
|
||||
uint32_t num_of_captures; /**< number of capture groups */
|
||||
|
||||
@ -326,7 +326,7 @@ lit_char_hex_to_int (ecma_char_t c) /**< code unit, corresponding to
|
||||
* @return true if decoding was successful, false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_read_code_point_from_hex (const lit_utf8_byte_t *buf_p, /**< buffer with characters */
|
||||
lit_read_code_point_from_hex (lit_utf8_byte_t *buf_p, /**< buffer with characters */
|
||||
lit_utf8_size_t number_of_characters, /**< number of characters to be read */
|
||||
lit_code_point_t *out_code_point_p) /**< @out: decoded result */
|
||||
{
|
||||
|
||||
@ -216,7 +216,7 @@ extern bool lit_char_is_hex_digit (ecma_char_t);
|
||||
extern uint32_t lit_char_hex_to_int (ecma_char_t);
|
||||
|
||||
/* read a hex encoded code point from a zero terminated buffer */
|
||||
bool lit_read_code_point_from_hex (const lit_utf8_byte_t *, lit_utf8_size_t, lit_code_point_t *);
|
||||
bool lit_read_code_point_from_hex (lit_utf8_byte_t *, lit_utf8_size_t, lit_code_point_t *);
|
||||
|
||||
/**
|
||||
* Null character
|
||||
|
||||
@ -194,7 +194,7 @@ lit_is_cesu8_string_valid (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string
|
||||
|
||||
if (idx + extra_bytes_count > buf_size)
|
||||
{
|
||||
/* utf-8 string breaks in the middle */
|
||||
/* cesu-8 string breaks in the middle */
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ lit_is_cesu8_string_valid (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string
|
||||
|
||||
if (code_point < min_code_point)
|
||||
{
|
||||
/* utf-8 string doesn't encode valid unicode code point */
|
||||
/* cesu-8 string doesn't encode valid unicode code point */
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -254,8 +254,7 @@ lit_utf8_iterator_create (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string *
|
||||
lit_utf8_size_t buf_size) /**< string size */
|
||||
{
|
||||
JERRY_ASSERT (utf8_buf_p || !buf_size);
|
||||
/* TODO: Add back when builtins no longer use iterators */
|
||||
/* JERRY_ASSERT (lit_is_utf8_string_valid (utf8_buf_p, buf_size)); */
|
||||
JERRY_ASSERT (lit_is_utf8_string_valid (utf8_buf_p, buf_size));
|
||||
|
||||
lit_utf8_iterator_t buf_iter =
|
||||
{
|
||||
@ -277,16 +276,6 @@ lit_utf8_iterator_seek_bos (lit_utf8_iterator_t *iter_p) /**< iterator to reset
|
||||
iter_p->buf_pos.is_non_bmp_middle = false;
|
||||
} /* lit_utf8_iterator_seek_bos */
|
||||
|
||||
/**
|
||||
* Reset iterator to point to the end of a string
|
||||
*/
|
||||
void
|
||||
lit_utf8_iterator_seek_eos (lit_utf8_iterator_t *iter_p) /**< iterator to reset */
|
||||
{
|
||||
iter_p->buf_pos.offset = iter_p->buf_size & LIT_ITERATOR_OFFSET_MASK;
|
||||
iter_p->buf_pos.is_non_bmp_middle = false;
|
||||
} /* lit_utf8_iterator_seek_eos */
|
||||
|
||||
/**
|
||||
* Save iterator's position to restore it later
|
||||
*
|
||||
@ -315,17 +304,6 @@ lit_utf8_iterator_seek (lit_utf8_iterator_t *iter_p, /**< utf-8 string iterator
|
||||
iter_p->buf_pos = iter_pos;
|
||||
} /* lit_utf8_iterator_seek */
|
||||
|
||||
/**
|
||||
* Get offset (in code units) of the iterator
|
||||
*
|
||||
* @return current offset of the iterator in code units
|
||||
*/
|
||||
ecma_length_t
|
||||
lit_utf8_iterator_get_index (const lit_utf8_iterator_t *iter_p)
|
||||
{
|
||||
return lit_utf8_string_length (iter_p->buf_p, iter_p->buf_pos.offset) + iter_p->buf_pos.is_non_bmp_middle;
|
||||
} /* lit_utf8_iterator_get_index */
|
||||
|
||||
/**
|
||||
* Represents code point (>0xFFFF) as surrogate pair and returns its lower part
|
||||
*
|
||||
@ -357,7 +335,7 @@ convert_code_point_to_high_surrogate (lit_code_point_t code_point) /**< code poi
|
||||
code_unit_bits = (ecma_char_t) ((code_point - LIT_UTF16_FIRST_SURROGATE_CODE_POINT) >> LIT_UTF16_BITS_IN_SURROGATE);
|
||||
|
||||
return (LIT_UTF16_HIGH_SURROGATE_MARKER | code_unit_bits);
|
||||
} /* convert_code_point_to_low_surrogate */
|
||||
} /* convert_code_point_to_high_surrogate */
|
||||
|
||||
/**
|
||||
* Get next code unit form the iterated string
|
||||
@ -392,50 +370,6 @@ lit_utf8_iterator_peek_next (const lit_utf8_iterator_t *iter_p) /**< @in: utf-8
|
||||
}
|
||||
} /* lit_utf8_iterator_peek_next */
|
||||
|
||||
/**
|
||||
* Get previous code unit form the iterated string
|
||||
*
|
||||
* @return previous code unit
|
||||
*/
|
||||
ecma_char_t
|
||||
lit_utf8_iterator_peek_prev (const lit_utf8_iterator_t *iter_p) /**< @in: utf-8 string iterator */
|
||||
{
|
||||
JERRY_ASSERT (!lit_utf8_iterator_is_bos (iter_p));
|
||||
|
||||
lit_code_point_t code_point;
|
||||
lit_utf8_size_t offset = iter_p->buf_pos.offset;
|
||||
|
||||
if (iter_p->buf_pos.is_non_bmp_middle)
|
||||
{
|
||||
lit_read_code_point_from_utf8 (iter_p->buf_p + iter_p->buf_pos.offset,
|
||||
iter_p->buf_size - iter_p->buf_pos.offset,
|
||||
&code_point);
|
||||
return convert_code_point_to_high_surrogate (code_point);
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
JERRY_ASSERT (offset != 0);
|
||||
offset--;
|
||||
}
|
||||
while ((iter_p->buf_p[offset] & LIT_UTF8_EXTRA_BYTE_MASK) == LIT_UTF8_EXTRA_BYTE_MARKER);
|
||||
|
||||
JERRY_ASSERT (iter_p->buf_pos.offset - offset <= LIT_UTF8_MAX_BYTES_IN_CODE_POINT);
|
||||
|
||||
lit_read_code_point_from_utf8 (iter_p->buf_p + offset,
|
||||
iter_p->buf_size - offset,
|
||||
&code_point);
|
||||
|
||||
if (code_point <= LIT_UTF16_CODE_UNIT_MAX)
|
||||
{
|
||||
return (ecma_char_t) code_point;
|
||||
}
|
||||
else
|
||||
{
|
||||
return convert_code_point_to_low_surrogate (code_point);
|
||||
}
|
||||
} /* lit_utf8_iterator_peek_prev */
|
||||
|
||||
/**
|
||||
* Increment iterator to point to next code unit
|
||||
*/
|
||||
@ -443,16 +377,7 @@ void
|
||||
lit_utf8_iterator_incr (lit_utf8_iterator_t *iter_p) /**< @in-out: utf-8 string iterator */
|
||||
{
|
||||
lit_utf8_iterator_read_next (iter_p);
|
||||
} /* lit_utf8_iterator_read_next */
|
||||
|
||||
/**
|
||||
* Decrement iterator to point to previous code unit
|
||||
*/
|
||||
void
|
||||
lit_utf8_iterator_decr (lit_utf8_iterator_t *iter_p) /**< @in-out: utf-8 string iterator */
|
||||
{
|
||||
lit_utf8_iterator_read_prev (iter_p);
|
||||
} /* lit_utf8_iterator_decr */
|
||||
} /* lit_utf8_iterator_incr */
|
||||
|
||||
/**
|
||||
* Skip specified number of code units
|
||||
@ -504,56 +429,6 @@ lit_utf8_iterator_read_next (lit_utf8_iterator_t *iter_p) /**< @in-out: utf-8 st
|
||||
}
|
||||
} /* lit_utf8_iterator_read_next */
|
||||
|
||||
/**
|
||||
* Get previous code unit form the iterated string and decrement iterator to point to previous code unit
|
||||
*
|
||||
* @return previous code unit
|
||||
*/
|
||||
ecma_char_t
|
||||
lit_utf8_iterator_read_prev (lit_utf8_iterator_t *iter_p) /**< @in-out: utf-8 string iterator */
|
||||
{
|
||||
JERRY_ASSERT (!lit_utf8_iterator_is_bos (iter_p));
|
||||
|
||||
lit_code_point_t code_point;
|
||||
lit_utf8_size_t offset = iter_p->buf_pos.offset;
|
||||
|
||||
if (iter_p->buf_pos.is_non_bmp_middle)
|
||||
{
|
||||
lit_read_code_point_from_utf8 (iter_p->buf_p + iter_p->buf_pos.offset,
|
||||
iter_p->buf_size - iter_p->buf_pos.offset,
|
||||
&code_point);
|
||||
|
||||
iter_p->buf_pos.is_non_bmp_middle = false;
|
||||
|
||||
return convert_code_point_to_high_surrogate (code_point);
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
JERRY_ASSERT (offset != 0);
|
||||
offset--;
|
||||
}
|
||||
while ((iter_p->buf_p[offset] & LIT_UTF8_EXTRA_BYTE_MASK) == LIT_UTF8_EXTRA_BYTE_MARKER);
|
||||
|
||||
JERRY_ASSERT (iter_p->buf_pos.offset - offset <= LIT_UTF8_MAX_BYTES_IN_CODE_POINT);
|
||||
|
||||
iter_p->buf_pos.offset = (offset) & LIT_ITERATOR_OFFSET_MASK;
|
||||
lit_read_code_point_from_utf8 (iter_p->buf_p + iter_p->buf_pos.offset,
|
||||
iter_p->buf_size - iter_p->buf_pos.offset,
|
||||
&code_point);
|
||||
|
||||
if (code_point <= LIT_UTF16_CODE_UNIT_MAX)
|
||||
{
|
||||
return (ecma_char_t) code_point;
|
||||
}
|
||||
else
|
||||
{
|
||||
iter_p->buf_pos.is_non_bmp_middle = true;
|
||||
|
||||
return convert_code_point_to_low_surrogate (code_point);
|
||||
}
|
||||
} /* lit_utf8_iterator_read_prev */
|
||||
|
||||
/**
|
||||
* Checks iterator reached end of the string
|
||||
*
|
||||
@ -568,18 +443,6 @@ lit_utf8_iterator_is_eos (const lit_utf8_iterator_t *iter_p) /**< utf-8 string i
|
||||
return (iter_p->buf_pos.offset == iter_p->buf_size);
|
||||
} /* lit_utf8_iterator_is_eos */
|
||||
|
||||
/**
|
||||
* Checks iterator reached beginning of the string
|
||||
*
|
||||
* @return true - iterator is at the beginning of a string
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
lit_utf8_iterator_is_bos (const lit_utf8_iterator_t *iter_p)
|
||||
{
|
||||
return (iter_p->buf_pos.offset == 0 && iter_p->buf_pos.is_non_bmp_middle == false);
|
||||
} /* lit_utf8_iterator_is_bos */
|
||||
|
||||
/**
|
||||
* Calculate size of a zero-terminated utf-8 string
|
||||
*
|
||||
@ -595,7 +458,7 @@ lit_zt_utf8_string_size (const lit_utf8_byte_t *utf8_str_p) /**< zero-terminated
|
||||
} /* lit_zt_utf8_string_size */
|
||||
|
||||
/**
|
||||
* Calculate length of a cesu-8 string
|
||||
* Calculate length of a cesu-8 encoded string
|
||||
*
|
||||
* @return UTF-16 code units count
|
||||
*/
|
||||
@ -733,7 +596,7 @@ lit_read_prev_code_unit_from_utf8 (const lit_utf8_byte_t *buf_p, /**< buffer wit
|
||||
/**
|
||||
* Decodes a unicode code unit from non-empty cesu-8-encoded buffer
|
||||
*
|
||||
* @return read character
|
||||
* @return next code unit
|
||||
*/
|
||||
ecma_char_t
|
||||
lit_utf8_read_next (lit_utf8_byte_t **buf_p) /**< in-out:buffer with characters */
|
||||
@ -749,7 +612,7 @@ lit_utf8_read_next (lit_utf8_byte_t **buf_p) /**< in-out:buffer with characters
|
||||
/**
|
||||
* Decodes a unicode code unit from non-empty cesu-8-encoded buffer
|
||||
*
|
||||
* @return read character
|
||||
* @return previous code unit
|
||||
*/
|
||||
ecma_char_t
|
||||
lit_utf8_read_prev (lit_utf8_byte_t **buf_p) /**< in-out:buffer with characters */
|
||||
@ -766,7 +629,7 @@ lit_utf8_read_prev (lit_utf8_byte_t **buf_p) /**< in-out:buffer with characters
|
||||
/**
|
||||
* Decodes a unicode code unit from non-empty cesu-8-encoded buffer
|
||||
*
|
||||
* @return read character
|
||||
* @return next code unit
|
||||
*/
|
||||
ecma_char_t
|
||||
lit_utf8_peek_next (lit_utf8_byte_t *buf_p) /**< in-out:buffer with characters */
|
||||
@ -782,7 +645,7 @@ lit_utf8_peek_next (lit_utf8_byte_t *buf_p) /**< in-out:buffer with characters *
|
||||
/**
|
||||
* Decodes a unicode code unit from non-empty cesu-8-encoded buffer
|
||||
*
|
||||
* @return read character
|
||||
* @return previous code unit
|
||||
*/
|
||||
ecma_char_t
|
||||
lit_utf8_peek_prev (lit_utf8_byte_t *buf_p) /**< in-out:buffer with characters */
|
||||
@ -796,7 +659,7 @@ lit_utf8_peek_prev (lit_utf8_byte_t *buf_p) /**< in-out:buffer with characters *
|
||||
} /* lit_utf8_peek_prev */
|
||||
|
||||
/**
|
||||
* Increase character pointer by one code unit.
|
||||
* Increase cesu-8 encoded string pointer by one code unit.
|
||||
*/
|
||||
void
|
||||
lit_utf8_incr (lit_utf8_byte_t **buf_p) /**< in-out:buffer with characters */
|
||||
@ -807,7 +670,7 @@ lit_utf8_incr (lit_utf8_byte_t **buf_p) /**< in-out:buffer with characters */
|
||||
} /* lit_utf8_incr */
|
||||
|
||||
/**
|
||||
* Decrease character pointer by one code unit.
|
||||
* Decrease cesu-8 encoded string pointer by one code unit.
|
||||
*/
|
||||
void
|
||||
lit_utf8_decr (lit_utf8_byte_t **buf_p) /**< in-out:buffer with characters */
|
||||
@ -915,9 +778,9 @@ lit_get_unicode_char_size_by_utf8_first_byte (const lit_utf8_byte_t first_byte)
|
||||
} /* lit_get_unicode_char_size_by_utf8_first_byte */
|
||||
|
||||
/**
|
||||
* Convert code_unit to cesu-8 representation
|
||||
* Convert code unit to cesu-8 representation
|
||||
*
|
||||
* @return bytes count, stored required to represent specified code unit
|
||||
* @return byte count required to represent the code unit
|
||||
*/
|
||||
lit_utf8_size_t
|
||||
lit_code_unit_to_utf8 (ecma_char_t code_unit, /**< code unit */
|
||||
@ -964,7 +827,7 @@ lit_code_unit_to_utf8 (ecma_char_t code_unit, /**< code unit */
|
||||
/**
|
||||
* Convert code point to cesu-8 representation
|
||||
*
|
||||
* @return bytes count, stored required to represent specified code unit
|
||||
* @return byte count required to represent the code point
|
||||
*/
|
||||
lit_utf8_size_t
|
||||
lit_code_point_to_cesu8 (lit_code_point_t code_point, /**< code point */
|
||||
@ -986,7 +849,7 @@ lit_code_point_to_cesu8 (lit_code_point_t code_point, /**< code point */
|
||||
/**
|
||||
* Convert code point to utf-8 representation
|
||||
*
|
||||
* @return bytes count, stored required to represent specified code unit
|
||||
* @return byte count required to represent the code point
|
||||
*/
|
||||
lit_utf8_size_t
|
||||
lit_code_point_to_utf8 (lit_code_point_t code_point, /**< code point */
|
||||
@ -1073,7 +936,7 @@ lit_convert_surrogate_pair_to_code_point (ecma_char_t high_surrogate, /**< high
|
||||
|
||||
code_point |= (uint16_t) (low_surrogate - LIT_UTF16_LOW_SURROGATE_MIN);
|
||||
return code_point;
|
||||
} /* lit_surrogate_pair_to_code_point */
|
||||
} /* lit_convert_surrogate_pair_to_code_point */
|
||||
|
||||
/**
|
||||
* Compare cesu-8 string to cesu-8 string
|
||||
|
||||
@ -133,25 +133,18 @@ bool lit_is_code_unit_high_surrogate (ecma_char_t);
|
||||
lit_utf8_iterator_t lit_utf8_iterator_create (const lit_utf8_byte_t *, lit_utf8_size_t);
|
||||
|
||||
void lit_utf8_iterator_seek_bos (lit_utf8_iterator_t *);
|
||||
void lit_utf8_iterator_seek_eos (lit_utf8_iterator_t *);
|
||||
|
||||
lit_utf8_iterator_pos_t lit_utf8_iterator_get_pos (const lit_utf8_iterator_t *);
|
||||
void lit_utf8_iterator_seek (lit_utf8_iterator_t *, lit_utf8_iterator_pos_t);
|
||||
|
||||
ecma_length_t lit_utf8_iterator_get_index (const lit_utf8_iterator_t *);
|
||||
|
||||
ecma_char_t lit_utf8_iterator_peek_next (const lit_utf8_iterator_t *);
|
||||
ecma_char_t lit_utf8_iterator_peek_prev (const lit_utf8_iterator_t *);
|
||||
|
||||
void lit_utf8_iterator_incr (lit_utf8_iterator_t *);
|
||||
void lit_utf8_iterator_decr (lit_utf8_iterator_t *);
|
||||
void lit_utf8_iterator_advance (lit_utf8_iterator_t *, ecma_length_t);
|
||||
|
||||
ecma_char_t lit_utf8_iterator_read_next (lit_utf8_iterator_t *);
|
||||
ecma_char_t lit_utf8_iterator_read_prev (lit_utf8_iterator_t *);
|
||||
|
||||
bool lit_utf8_iterator_is_eos (const lit_utf8_iterator_t *);
|
||||
bool lit_utf8_iterator_is_bos (const lit_utf8_iterator_t *);
|
||||
|
||||
/* size */
|
||||
lit_utf8_size_t lit_zt_utf8_string_size (const lit_utf8_byte_t *);
|
||||
|
||||
@ -177,7 +177,7 @@ lexer_create_token_for_charset (token_type tt, /**< token type */
|
||||
|
||||
lit_utf8_byte_t *converted_str_p;
|
||||
|
||||
if (should_convert)
|
||||
if (unlikely (should_convert))
|
||||
{
|
||||
lit_utf8_iterator_seek_bos (&iter);
|
||||
converted_str_p = (lit_utf8_byte_t *) jsp_mm_alloc (new_size);
|
||||
@ -198,7 +198,7 @@ lexer_create_token_for_charset (token_type tt, /**< token type */
|
||||
literal_t lit = lit_find_literal_by_utf8_string (converted_str_p, new_length);
|
||||
if (lit != NULL)
|
||||
{
|
||||
if (should_convert)
|
||||
if (unlikely (should_convert))
|
||||
{
|
||||
jsp_mm_free (converted_str_p);
|
||||
}
|
||||
@ -210,7 +210,7 @@ lexer_create_token_for_charset (token_type tt, /**< token type */
|
||||
|| lit->get_type () == LIT_MAGIC_STR_T
|
||||
|| lit->get_type () == LIT_MAGIC_STR_EX_T);
|
||||
|
||||
if (should_convert)
|
||||
if (unlikely (should_convert))
|
||||
{
|
||||
jsp_mm_free (converted_str_p);
|
||||
}
|
||||
|
||||
@ -383,19 +383,15 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
uint32_t alterantive_offset = re_get_bytecode_length (re_ctx_p->bytecode_ctx_p);
|
||||
bool should_loop = true;
|
||||
|
||||
while (true)
|
||||
while (ecma_is_completion_value_empty (ret_value) && should_loop)
|
||||
{
|
||||
ECMA_TRY_CATCH (empty,
|
||||
re_parse_next_token (re_ctx_p->parser_ctx_p,
|
||||
&(re_ctx_p->current_token)),
|
||||
ret_value);
|
||||
ECMA_FINALIZE (empty);
|
||||
|
||||
if (!ecma_is_completion_value_empty (ret_value))
|
||||
{
|
||||
return ret_value; /* error */
|
||||
}
|
||||
uint32_t new_atom_start_offset = re_get_bytecode_length (re_ctx_p->bytecode_ctx_p);
|
||||
|
||||
switch (re_ctx_p->current_token.type)
|
||||
@ -411,10 +407,7 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
|
||||
{
|
||||
re_insert_into_group (re_ctx_p, new_atom_start_offset, idx, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ret_value; /* error */
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case RE_TOK_START_NON_CAPTURE_GROUP:
|
||||
@ -428,10 +421,7 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
|
||||
{
|
||||
re_insert_into_group (re_ctx_p, new_atom_start_offset, idx, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ret_value; /* error */
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case RE_TOK_CHAR:
|
||||
@ -506,10 +496,7 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
|
||||
|
||||
re_insert_into_group_with_jump (re_ctx_p, new_atom_start_offset, idx, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ret_value; /* error */
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case RE_TOK_ASSERT_START_NEG_LOOKAHEAD:
|
||||
@ -526,10 +513,7 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
|
||||
|
||||
re_insert_into_group_with_jump (re_ctx_p, new_atom_start_offset, idx, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ret_value; /* error */
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case RE_TOK_BACKREFERENCE:
|
||||
@ -580,10 +564,6 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
|
||||
|
||||
ECMA_FINALIZE (empty);
|
||||
|
||||
if (ecma_is_completion_value_throw (ret_value))
|
||||
{
|
||||
return ret_value; /* error */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RE_TOK_END_GROUP:
|
||||
@ -597,9 +577,9 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
|
||||
else
|
||||
{
|
||||
re_insert_u32 (bc_ctx_p, alterantive_offset, re_get_bytecode_length (bc_ctx_p) - alterantive_offset);
|
||||
should_loop = false;
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
break;
|
||||
}
|
||||
case RE_TOK_EOF:
|
||||
{
|
||||
@ -610,19 +590,20 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
|
||||
else
|
||||
{
|
||||
re_insert_u32 (bc_ctx_p, alterantive_offset, re_get_bytecode_length (bc_ctx_p) - alterantive_offset);
|
||||
should_loop = false;
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
ret_value = ecma_raise_syntax_error ("Unexpected RegExp token.");
|
||||
return ret_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ECMA_FINALIZE (empty);
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
return ret_value;
|
||||
} /* re_parse_alternative */
|
||||
|
||||
@ -656,10 +637,10 @@ re_compile_bytecode (re_bytecode_t **out_bytecode_p, /**< out:pointer to bytecod
|
||||
ssize_t sz = ecma_string_to_utf8_string (pattern_str_p, pattern_start_p, (ssize_t) pattern_str_size);
|
||||
JERRY_ASSERT (sz >= 0);
|
||||
|
||||
lit_utf8_iterator_t iter = lit_utf8_iterator_create (pattern_start_p, pattern_str_size);
|
||||
|
||||
re_parser_ctx_t parser_ctx;
|
||||
parser_ctx.iter = iter;
|
||||
parser_ctx.input_start_p = pattern_start_p;
|
||||
parser_ctx.input_curr_p = pattern_start_p;
|
||||
parser_ctx.input_end_p = pattern_start_p + pattern_str_size;
|
||||
parser_ctx.num_of_groups = -1;
|
||||
re_ctx.parser_ctx_p = &parser_ctx;
|
||||
|
||||
|
||||
@ -31,17 +31,17 @@
|
||||
* false, otherwise
|
||||
*/
|
||||
static bool
|
||||
re_hex_lookup (lit_utf8_iterator_t iter, /**< input string iterator */
|
||||
re_hex_lookup (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context */
|
||||
uint32_t lookup) /**< size of lookup */
|
||||
{
|
||||
ecma_char_t ch;
|
||||
bool is_digit = true;
|
||||
lit_utf8_byte_t *curr_p = parser_ctx_p->input_curr_p;
|
||||
|
||||
for (uint32_t i = 0; is_digit && i < lookup; i++)
|
||||
{
|
||||
if (!lit_utf8_iterator_is_eos (&iter))
|
||||
if (curr_p < parser_ctx_p->input_end_p)
|
||||
{
|
||||
ch = lit_utf8_iterator_read_next (&iter);
|
||||
is_digit = lit_char_is_hex_digit (ch);
|
||||
is_digit = lit_char_is_hex_digit (*curr_p++);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -59,11 +59,12 @@ re_hex_lookup (lit_utf8_iterator_t iter, /**< input string iterator */
|
||||
* false, otherwise
|
||||
*/
|
||||
static bool __attr_always_inline___
|
||||
re_parse_non_greedy_char (lit_utf8_iterator_t *iter_p) /**< RegExp pattern */
|
||||
re_parse_non_greedy_char (re_parser_ctx_t *parser_ctx_p) /**< RegExp parser context */
|
||||
{
|
||||
if (!lit_utf8_iterator_is_eos (iter_p) && lit_utf8_iterator_peek_next (iter_p) == LIT_CHAR_QUESTION)
|
||||
if (parser_ctx_p->input_curr_p < parser_ctx_p->input_end_p
|
||||
&& *parser_ctx_p->input_curr_p == LIT_CHAR_QUESTION)
|
||||
{
|
||||
lit_utf8_iterator_advance (iter_p, 1);
|
||||
parser_ctx_p->input_curr_p++;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -76,16 +77,16 @@ re_parse_non_greedy_char (lit_utf8_iterator_t *iter_p) /**< RegExp pattern */
|
||||
* @return uint32_t - parsed octal number
|
||||
*/
|
||||
static uint32_t
|
||||
re_parse_octal (lit_utf8_iterator_t *iter) /**< input string iterator */
|
||||
re_parse_octal (re_parser_ctx_t *parser_ctx_p) /**< RegExp parser context */
|
||||
{
|
||||
uint32_t number = 0;
|
||||
for (int index = 0;
|
||||
index < 3
|
||||
&& !lit_utf8_iterator_is_eos (iter)
|
||||
&& lit_char_is_octal_digit (lit_utf8_iterator_peek_next (iter));
|
||||
&& parser_ctx_p->input_curr_p < parser_ctx_p->input_end_p
|
||||
&& lit_char_is_octal_digit (*parser_ctx_p->input_curr_p);
|
||||
index++)
|
||||
{
|
||||
number = number * 8 + lit_char_hex_to_int (lit_utf8_iterator_read_next (iter));
|
||||
number = number * 8 + lit_char_hex_to_int (*parser_ctx_p->input_curr_p++);
|
||||
}
|
||||
|
||||
return number;
|
||||
@ -102,59 +103,59 @@ re_parse_iterator (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context */
|
||||
re_token_t *re_token_p) /**< out: output token */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
lit_utf8_iterator_t *iter_p = &(parser_ctx_p->iter);
|
||||
|
||||
re_token_p->qmin = 1;
|
||||
re_token_p->qmax = 1;
|
||||
re_token_p->greedy = true;
|
||||
|
||||
if (lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p >= parser_ctx_p->input_end_p)
|
||||
{
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
ecma_char_t ch = lit_utf8_iterator_peek_next (iter_p);
|
||||
ecma_char_t ch = *parser_ctx_p->input_curr_p;
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case LIT_CHAR_QUESTION:
|
||||
{
|
||||
lit_utf8_iterator_advance (iter_p, 1);
|
||||
parser_ctx_p->input_curr_p++;
|
||||
re_token_p->qmin = 0;
|
||||
re_token_p->qmax = 1;
|
||||
re_token_p->greedy = !re_parse_non_greedy_char (iter_p);
|
||||
re_token_p->greedy = !re_parse_non_greedy_char (parser_ctx_p);
|
||||
break;
|
||||
}
|
||||
case LIT_CHAR_ASTERISK:
|
||||
{
|
||||
lit_utf8_iterator_advance (iter_p, 1);
|
||||
parser_ctx_p->input_curr_p++;
|
||||
re_token_p->qmin = 0;
|
||||
re_token_p->qmax = RE_ITERATOR_INFINITE;
|
||||
re_token_p->greedy = !re_parse_non_greedy_char (iter_p);
|
||||
re_token_p->greedy = !re_parse_non_greedy_char (parser_ctx_p);
|
||||
break;
|
||||
}
|
||||
case LIT_CHAR_PLUS:
|
||||
{
|
||||
lit_utf8_iterator_advance (iter_p, 1);
|
||||
parser_ctx_p->input_curr_p++;
|
||||
re_token_p->qmin = 1;
|
||||
re_token_p->qmax = RE_ITERATOR_INFINITE;
|
||||
re_token_p->greedy = !re_parse_non_greedy_char (iter_p);
|
||||
re_token_p->greedy = !re_parse_non_greedy_char (parser_ctx_p);
|
||||
break;
|
||||
}
|
||||
case LIT_CHAR_LEFT_BRACE:
|
||||
{
|
||||
lit_utf8_iterator_advance (iter_p, 1);
|
||||
parser_ctx_p->input_curr_p++;
|
||||
uint32_t qmin = 0;
|
||||
uint32_t qmax = RE_ITERATOR_INFINITE;
|
||||
uint32_t digits = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p >= parser_ctx_p->input_end_p)
|
||||
{
|
||||
return ecma_raise_syntax_error ("invalid quantifier");
|
||||
}
|
||||
|
||||
ch = lit_utf8_iterator_read_next (iter_p);
|
||||
ch = *parser_ctx_p->input_curr_p++;
|
||||
|
||||
if (lit_char_is_decimal_digit (ch))
|
||||
{
|
||||
@ -172,19 +173,19 @@ re_parse_iterator (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context */
|
||||
return ecma_raise_syntax_error ("RegExp quantifier error: double comma.");
|
||||
}
|
||||
|
||||
if (lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p >= parser_ctx_p->input_end_p)
|
||||
{
|
||||
return ecma_raise_syntax_error ("invalid quantifier");
|
||||
}
|
||||
|
||||
if (lit_utf8_iterator_peek_next (iter_p) == LIT_CHAR_RIGHT_BRACE)
|
||||
if (*parser_ctx_p->input_curr_p == LIT_CHAR_RIGHT_BRACE)
|
||||
{
|
||||
if (digits == 0)
|
||||
{
|
||||
return ecma_raise_syntax_error ("RegExp quantifier error: missing digits.");
|
||||
}
|
||||
|
||||
lit_utf8_iterator_advance (iter_p, 1);
|
||||
parser_ctx_p->input_curr_p++;
|
||||
re_token_p->qmin = qmin;
|
||||
re_token_p->qmax = RE_ITERATOR_INFINITE;
|
||||
break;
|
||||
@ -219,7 +220,7 @@ re_parse_iterator (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context */
|
||||
}
|
||||
}
|
||||
|
||||
re_token_p->greedy = !re_parse_non_greedy_char (iter_p);
|
||||
re_token_p->greedy = !re_parse_non_greedy_char (parser_ctx_p);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -246,16 +247,15 @@ re_count_num_of_groups (re_parser_ctx_t *parser_ctx_p) /**< RegExp parser contex
|
||||
{
|
||||
int char_class_in = 0;
|
||||
parser_ctx_p->num_of_groups = 0;
|
||||
lit_utf8_iterator_t iter = lit_utf8_iterator_create (parser_ctx_p->iter.buf_p,
|
||||
parser_ctx_p->iter.buf_size);
|
||||
lit_utf8_byte_t *curr_p = parser_ctx_p->input_start_p;
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&iter))
|
||||
while (curr_p < parser_ctx_p->input_end_p)
|
||||
{
|
||||
switch (lit_utf8_iterator_read_next (&iter))
|
||||
switch (*curr_p++)
|
||||
{
|
||||
case LIT_CHAR_BACKSLASH:
|
||||
{
|
||||
lit_utf8_iterator_advance (&iter, 1);
|
||||
lit_utf8_incr (&curr_p);
|
||||
break;
|
||||
}
|
||||
case LIT_CHAR_LEFT_SQUARE:
|
||||
@ -273,8 +273,8 @@ re_count_num_of_groups (re_parser_ctx_t *parser_ctx_p) /**< RegExp parser contex
|
||||
}
|
||||
case LIT_CHAR_LEFT_PAREN:
|
||||
{
|
||||
if (!lit_utf8_iterator_is_eos (&iter)
|
||||
&& lit_utf8_iterator_peek_next (&iter) != LIT_CHAR_QUESTION
|
||||
if (curr_p < parser_ctx_p->input_end_p
|
||||
&& *curr_p != LIT_CHAR_QUESTION
|
||||
&& !char_class_in)
|
||||
{
|
||||
parser_ctx_p->num_of_groups++;
|
||||
@ -304,21 +304,21 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
|
||||
uint32_t start = RE_CHAR_UNDEF;
|
||||
bool is_range = false;
|
||||
parser_ctx_p->num_of_classes = 0;
|
||||
lit_utf8_iterator_t *iter_p = &(parser_ctx_p->iter);
|
||||
if (lit_utf8_iterator_peek_prev (iter_p) != LIT_CHAR_LEFT_SQUARE)
|
||||
|
||||
if (lit_utf8_peek_prev (parser_ctx_p->input_curr_p) != LIT_CHAR_LEFT_SQUARE)
|
||||
{
|
||||
lit_utf8_iterator_read_prev (iter_p);
|
||||
lit_utf8_iterator_read_prev (iter_p);
|
||||
lit_utf8_decr (&parser_ctx_p->input_curr_p);
|
||||
lit_utf8_decr (&parser_ctx_p->input_curr_p);
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p >= parser_ctx_p->input_end_p)
|
||||
{
|
||||
return ecma_raise_syntax_error ("invalid character class, end of string");
|
||||
}
|
||||
|
||||
uint32_t ch = lit_utf8_iterator_read_next (iter_p);
|
||||
uint32_t ch = lit_utf8_read_next (&parser_ctx_p->input_curr_p);
|
||||
|
||||
if (ch == LIT_CHAR_RIGHT_SQUARE)
|
||||
{
|
||||
@ -330,14 +330,14 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
|
||||
}
|
||||
else if (ch == LIT_CHAR_MINUS)
|
||||
{
|
||||
if (lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p >= parser_ctx_p->input_end_p)
|
||||
{
|
||||
return ecma_raise_syntax_error ("invalid character class, end of string after '-'");
|
||||
}
|
||||
|
||||
if (start != RE_CHAR_UNDEF
|
||||
&& !is_range
|
||||
&& lit_utf8_iterator_peek_next (iter_p) != LIT_CHAR_RIGHT_SQUARE)
|
||||
&& *parser_ctx_p->input_curr_p != LIT_CHAR_RIGHT_SQUARE)
|
||||
{
|
||||
is_range = true;
|
||||
continue;
|
||||
@ -345,12 +345,12 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
|
||||
}
|
||||
else if (ch == LIT_CHAR_BACKSLASH)
|
||||
{
|
||||
if (lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p >= parser_ctx_p->input_end_p)
|
||||
{
|
||||
return ecma_raise_syntax_error ("invalid character class, end of string after '\\'");
|
||||
}
|
||||
|
||||
ch = lit_utf8_iterator_read_next (iter_p);
|
||||
ch = *parser_ctx_p->input_curr_p++;
|
||||
|
||||
if (ch == LIT_CHAR_LOWERCASE_B)
|
||||
{
|
||||
@ -378,9 +378,9 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
|
||||
}
|
||||
else if (ch == LIT_CHAR_LOWERCASE_C)
|
||||
{
|
||||
if (!lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p < parser_ctx_p->input_end_p)
|
||||
{
|
||||
ch = lit_utf8_iterator_peek_next (iter_p);
|
||||
ch = *parser_ctx_p->input_curr_p;
|
||||
|
||||
if ((ch >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_END)
|
||||
|| (ch >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_END)
|
||||
@ -388,7 +388,7 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
|
||||
{
|
||||
/* See ECMA-262 v5, 15.10.2.10 (Point 3) */
|
||||
ch = (ch % 32);
|
||||
lit_utf8_iterator_incr (iter_p);
|
||||
parser_ctx_p->input_curr_p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -399,29 +399,25 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
|
||||
else if (ch == LIT_CHAR_LOWERCASE_X)
|
||||
{
|
||||
lit_code_point_t code_point;
|
||||
const lit_utf8_byte_t *hex_start_p = parser_ctx_p->iter.buf_p + parser_ctx_p->iter.buf_pos.offset;
|
||||
|
||||
if (!lit_read_code_point_from_hex (hex_start_p, 2, &code_point))
|
||||
if (!lit_read_code_point_from_hex (parser_ctx_p->input_curr_p, 2, &code_point))
|
||||
{
|
||||
return ecma_raise_syntax_error ("invalid character class, end of string after '\\x'");
|
||||
}
|
||||
|
||||
lit_utf8_iterator_advance (iter_p, 2);
|
||||
|
||||
parser_ctx_p->input_curr_p += 2;
|
||||
append_char_class (re_ctx_p, code_point, code_point);
|
||||
}
|
||||
else if (ch == LIT_CHAR_LOWERCASE_U)
|
||||
{
|
||||
lit_code_point_t code_point;
|
||||
const lit_utf8_byte_t *hex_start_p = parser_ctx_p->iter.buf_p + parser_ctx_p->iter.buf_pos.offset;
|
||||
|
||||
if (!lit_read_code_point_from_hex (hex_start_p, 4, &code_point))
|
||||
if (!lit_read_code_point_from_hex (parser_ctx_p->input_curr_p, 4, &code_point))
|
||||
{
|
||||
return ecma_raise_syntax_error ("invalid character class, end of string after '\\u'");
|
||||
}
|
||||
|
||||
lit_utf8_iterator_advance (iter_p, 4);
|
||||
|
||||
parser_ctx_p->input_curr_p += 4;
|
||||
append_char_class (re_ctx_p, code_point, code_point);
|
||||
}
|
||||
else if (ch == LIT_CHAR_LOWERCASE_D)
|
||||
@ -493,8 +489,8 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
|
||||
&& lit_char_is_octal_digit ((ecma_char_t) ch)
|
||||
&& ch != LIT_CHAR_0)
|
||||
{
|
||||
lit_utf8_iterator_decr (iter_p);
|
||||
ch = re_parse_octal (iter_p);
|
||||
parser_ctx_p->input_curr_p--;
|
||||
ch = re_parse_octal (parser_ctx_p);
|
||||
}
|
||||
} /* ch == LIT_CHAR_BACKSLASH */
|
||||
|
||||
@ -558,15 +554,14 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
|
||||
re_token_t *out_token_p) /**< out: output token */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
lit_utf8_iterator_t *iter_p = &(parser_ctx_p->iter);
|
||||
|
||||
if (lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p >= parser_ctx_p->input_end_p)
|
||||
{
|
||||
out_token_p->type = RE_TOK_EOF;
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
ecma_char_t ch = lit_utf8_iterator_read_next (iter_p);
|
||||
ecma_char_t ch = lit_utf8_read_next (&parser_ctx_p->input_curr_p);
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
@ -593,13 +588,13 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
|
||||
}
|
||||
case LIT_CHAR_BACKSLASH:
|
||||
{
|
||||
if (lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p >= parser_ctx_p->input_end_p)
|
||||
{
|
||||
return ecma_raise_syntax_error ("invalid regular experssion");
|
||||
}
|
||||
|
||||
out_token_p->type = RE_TOK_CHAR;
|
||||
ch = lit_utf8_iterator_read_next (iter_p);
|
||||
ch = lit_utf8_read_next (&parser_ctx_p->input_curr_p);
|
||||
|
||||
if (ch == LIT_CHAR_LOWERCASE_B)
|
||||
{
|
||||
@ -631,55 +626,53 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
|
||||
}
|
||||
else if (ch == LIT_CHAR_LOWERCASE_C)
|
||||
{
|
||||
if (!lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p < parser_ctx_p->input_end_p)
|
||||
{
|
||||
ch = lit_utf8_iterator_peek_next (iter_p);
|
||||
ch = *parser_ctx_p->input_curr_p;
|
||||
|
||||
if ((ch >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_END)
|
||||
|| (ch >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_END))
|
||||
{
|
||||
out_token_p->value = (ch % 32);
|
||||
lit_utf8_iterator_incr (iter_p);
|
||||
parser_ctx_p->input_curr_p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
out_token_p->value = LIT_CHAR_BACKSLASH;
|
||||
lit_utf8_iterator_decr (iter_p);
|
||||
parser_ctx_p->input_curr_p--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
out_token_p->value = LIT_CHAR_BACKSLASH;
|
||||
lit_utf8_iterator_decr (iter_p);
|
||||
parser_ctx_p->input_curr_p--;
|
||||
}
|
||||
}
|
||||
else if (ch == LIT_CHAR_LOWERCASE_X
|
||||
&& re_hex_lookup (*iter_p, 2))
|
||||
&& re_hex_lookup (parser_ctx_p, 2))
|
||||
{
|
||||
lit_code_point_t code_point;
|
||||
const lit_utf8_byte_t *hex_start_p = iter_p->buf_p + iter_p->buf_pos.offset;
|
||||
|
||||
if (!lit_read_code_point_from_hex (hex_start_p, 2, &code_point))
|
||||
if (!lit_read_code_point_from_hex (parser_ctx_p->input_curr_p, 2, &code_point))
|
||||
{
|
||||
return ecma_raise_syntax_error ("decode error");
|
||||
}
|
||||
|
||||
parser_ctx_p->input_curr_p += 2;
|
||||
out_token_p->value = code_point;
|
||||
lit_utf8_iterator_advance (iter_p, 2);
|
||||
}
|
||||
else if (ch == LIT_CHAR_LOWERCASE_U
|
||||
&& re_hex_lookup (*iter_p, 4))
|
||||
&& re_hex_lookup (parser_ctx_p, 4))
|
||||
{
|
||||
lit_code_point_t code_point;
|
||||
const lit_utf8_byte_t *hex_start_p = iter_p->buf_p + iter_p->buf_pos.offset;
|
||||
|
||||
if (!lit_read_code_point_from_hex (hex_start_p, 4, &code_point))
|
||||
if (!lit_read_code_point_from_hex (parser_ctx_p->input_curr_p, 4, &code_point))
|
||||
{
|
||||
return ecma_raise_syntax_error ("decode error");
|
||||
}
|
||||
|
||||
parser_ctx_p->input_curr_p += 4;
|
||||
out_token_p->value = code_point;
|
||||
lit_utf8_iterator_advance (iter_p, 4);
|
||||
}
|
||||
else if (ch == LIT_CHAR_LOWERCASE_D)
|
||||
{
|
||||
@ -715,8 +708,8 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
|
||||
{
|
||||
if (ch == LIT_CHAR_0)
|
||||
{
|
||||
if (!lit_utf8_iterator_is_eos (iter_p)
|
||||
&& lit_char_is_decimal_digit (lit_utf8_iterator_peek_next (iter_p)))
|
||||
if (parser_ctx_p->input_curr_p < parser_ctx_p->input_end_p
|
||||
&& lit_char_is_decimal_digit (*parser_ctx_p->input_curr_p))
|
||||
{
|
||||
return ecma_raise_syntax_error ("RegExp escape pattern error.");
|
||||
}
|
||||
@ -732,7 +725,7 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
|
||||
|
||||
if (parser_ctx_p->num_of_groups)
|
||||
{
|
||||
lit_utf8_iterator_read_prev (iter_p);
|
||||
parser_ctx_p->input_curr_p--;
|
||||
uint32_t number = 0;
|
||||
int index = 0;
|
||||
|
||||
@ -743,16 +736,16 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
|
||||
ret_value = ecma_raise_syntax_error ("RegExp escape pattern error: decimal escape too long.");
|
||||
return ret_value;
|
||||
}
|
||||
if (lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p >= parser_ctx_p->input_end_p)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
ecma_char_t digit = lit_utf8_iterator_read_next (iter_p);
|
||||
ecma_char_t digit = *parser_ctx_p->input_curr_p++;
|
||||
|
||||
if (!lit_char_is_decimal_digit (digit))
|
||||
{
|
||||
lit_utf8_iterator_read_prev (iter_p);
|
||||
parser_ctx_p->input_curr_p--;
|
||||
break;
|
||||
}
|
||||
number = number * 10 + lit_char_hex_to_int (digit);
|
||||
@ -768,22 +761,20 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
|
||||
/* Invalid backreference, fallback to octal */
|
||||
{
|
||||
/* Rewind to start of number. */
|
||||
while (index-- > 0)
|
||||
{
|
||||
lit_utf8_iterator_decr (iter_p);
|
||||
}
|
||||
parser_ctx_p->input_curr_p -= index;
|
||||
|
||||
/* Try to reparse as octal. */
|
||||
ecma_char_t digit = lit_utf8_iterator_peek_next (iter_p);
|
||||
ecma_char_t digit = *parser_ctx_p->input_curr_p;
|
||||
|
||||
if (!lit_char_is_octal_digit (digit))
|
||||
{
|
||||
/* Not octal, keep digit character value. */
|
||||
number = lit_utf8_iterator_read_next (iter_p);
|
||||
number = digit;
|
||||
parser_ctx_p->input_curr_p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
number = re_parse_octal (iter_p);
|
||||
number = re_parse_octal (parser_ctx_p);
|
||||
}
|
||||
}
|
||||
out_token_p->value = number;
|
||||
@ -798,8 +789,8 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
|
||||
}
|
||||
else
|
||||
{
|
||||
lit_utf8_iterator_decr (iter_p);
|
||||
out_token_p->value = re_parse_octal (iter_p);
|
||||
parser_ctx_p->input_curr_p--;
|
||||
out_token_p->value = re_parse_octal (parser_ctx_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -814,20 +805,20 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
|
||||
}
|
||||
case LIT_CHAR_LEFT_PAREN:
|
||||
{
|
||||
if (lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p >= parser_ctx_p->input_end_p)
|
||||
{
|
||||
return ecma_raise_syntax_error ("Unterminated group");
|
||||
}
|
||||
|
||||
if (lit_utf8_iterator_peek_next (iter_p) == LIT_CHAR_QUESTION)
|
||||
if (*parser_ctx_p->input_curr_p == LIT_CHAR_QUESTION)
|
||||
{
|
||||
lit_utf8_iterator_advance (iter_p, 1);
|
||||
if (lit_utf8_iterator_is_eos (iter_p))
|
||||
parser_ctx_p->input_curr_p++;
|
||||
if (parser_ctx_p->input_curr_p >= parser_ctx_p->input_end_p)
|
||||
{
|
||||
return ecma_raise_syntax_error ("Invalid group");
|
||||
}
|
||||
|
||||
ch = lit_utf8_iterator_read_next (iter_p);
|
||||
ch = *parser_ctx_p->input_curr_p++;
|
||||
|
||||
if (ch == LIT_CHAR_EQUALS)
|
||||
{
|
||||
@ -866,15 +857,15 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
|
||||
{
|
||||
out_token_p->type = RE_TOK_START_CHAR_CLASS;
|
||||
|
||||
if (lit_utf8_iterator_is_eos (iter_p))
|
||||
if (parser_ctx_p->input_curr_p >= parser_ctx_p->input_end_p)
|
||||
{
|
||||
return ecma_raise_syntax_error ("invalid character class");
|
||||
}
|
||||
|
||||
if (lit_utf8_iterator_peek_next (iter_p) == LIT_CHAR_CIRCUMFLEX)
|
||||
if (*parser_ctx_p->input_curr_p == LIT_CHAR_CIRCUMFLEX)
|
||||
{
|
||||
out_token_p->type = RE_TOK_START_INV_CHAR_CLASS;
|
||||
lit_utf8_iterator_advance (iter_p, 1);
|
||||
parser_ctx_p->input_curr_p++;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@ -81,7 +81,9 @@ typedef struct
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
lit_utf8_iterator_t iter; /**< iterator of input pattern */
|
||||
lit_utf8_byte_t *input_start_p; /**< start of input pattern */
|
||||
lit_utf8_byte_t *input_curr_p; /**< current position in input pattern */
|
||||
lit_utf8_byte_t *input_end_p; /**< end of input pattern */
|
||||
int num_of_groups; /**< number of groups */
|
||||
uint32_t num_of_classes; /**< number of character classes */
|
||||
} re_parser_ctx_t;
|
||||
|
||||
@ -107,29 +107,31 @@ main (int __attr_unused___ argc,
|
||||
|
||||
mem_init ();
|
||||
|
||||
lit_utf8_byte_t utf8_string[max_bytes_in_string];
|
||||
lit_utf8_byte_t cesu8_string[max_bytes_in_string];
|
||||
ecma_char_t code_units[max_code_units_in_string];
|
||||
lit_utf8_iterator_pos_t saved_positions[max_code_units_in_string];
|
||||
lit_utf8_byte_t *saved_positions[max_code_units_in_string];
|
||||
|
||||
for (int i = 0; i < test_iters; i++)
|
||||
{
|
||||
lit_utf8_size_t utf8_string_size = (i == 0) ? 0 : (lit_utf8_size_t) (rand () % max_bytes_in_string);
|
||||
ecma_length_t length = generate_cesu8_string (utf8_string, utf8_string_size);
|
||||
lit_utf8_size_t cesu8_string_size = (i == 0) ? 0 : (lit_utf8_size_t) (rand () % max_bytes_in_string);
|
||||
ecma_length_t length = generate_cesu8_string (cesu8_string, cesu8_string_size);
|
||||
|
||||
JERRY_ASSERT (lit_utf8_string_length (utf8_string, utf8_string_size) == length);
|
||||
JERRY_ASSERT (lit_utf8_string_length (cesu8_string, cesu8_string_size) == length);
|
||||
|
||||
lit_utf8_byte_t *curr_p = cesu8_string;
|
||||
const lit_utf8_byte_t *end_p = cesu8_string + cesu8_string_size;
|
||||
|
||||
lit_utf8_iterator_t iter = lit_utf8_iterator_create (utf8_string, utf8_string_size);
|
||||
ecma_length_t calculated_length = 0;
|
||||
|
||||
ecma_length_t code_units_count = 0;
|
||||
while (!lit_utf8_iterator_is_eos (&iter))
|
||||
|
||||
while (curr_p < end_p)
|
||||
{
|
||||
code_units[code_units_count] = lit_utf8_iterator_peek_next (&iter);
|
||||
saved_positions[code_units_count] = lit_utf8_iterator_get_pos (&iter);
|
||||
code_units[code_units_count] = lit_utf8_peek_next (curr_p);
|
||||
saved_positions[code_units_count] = curr_p;
|
||||
code_units_count++;
|
||||
calculated_length++;
|
||||
|
||||
lit_utf8_iterator_incr (&iter);
|
||||
lit_utf8_incr (&curr_p);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (length == calculated_length);
|
||||
@ -139,53 +141,52 @@ main (int __attr_unused___ argc,
|
||||
for (int j = 0; j < test_subiters; j++)
|
||||
{
|
||||
ecma_length_t index = (ecma_length_t) rand () % code_units_count;
|
||||
lit_utf8_iterator_seek (&iter, saved_positions[index]);
|
||||
JERRY_ASSERT (lit_utf8_iterator_peek_next (&iter) == code_units[index]);
|
||||
JERRY_ASSERT (lit_utf8_iterator_get_index (&iter) == index);
|
||||
curr_p = saved_positions[index];
|
||||
JERRY_ASSERT (lit_utf8_peek_next (curr_p) == code_units[index]);
|
||||
}
|
||||
}
|
||||
|
||||
lit_utf8_iterator_seek_eos (&iter);
|
||||
while (!lit_utf8_iterator_is_bos (&iter))
|
||||
curr_p = (lit_utf8_byte_t *) end_p;
|
||||
while (curr_p > cesu8_string)
|
||||
{
|
||||
JERRY_ASSERT (code_units_count > 0);
|
||||
calculated_length--;
|
||||
JERRY_ASSERT (code_units[calculated_length] == lit_utf8_iterator_peek_prev (&iter));
|
||||
lit_utf8_iterator_decr (&iter);
|
||||
JERRY_ASSERT (code_units[calculated_length] == lit_utf8_peek_prev (curr_p));
|
||||
lit_utf8_decr (&curr_p);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (calculated_length == 0);
|
||||
|
||||
while (!lit_utf8_iterator_is_eos (&iter))
|
||||
while (curr_p < end_p)
|
||||
{
|
||||
ecma_char_t code_unit = lit_utf8_iterator_read_next (&iter);
|
||||
ecma_char_t code_unit = lit_utf8_read_next (&curr_p);
|
||||
JERRY_ASSERT (code_unit == code_units[calculated_length]);
|
||||
calculated_length++;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (length == calculated_length);
|
||||
|
||||
while (!lit_utf8_iterator_is_bos (&iter))
|
||||
while (curr_p > cesu8_string)
|
||||
{
|
||||
JERRY_ASSERT (code_units_count > 0);
|
||||
calculated_length--;
|
||||
JERRY_ASSERT (code_units[calculated_length] == lit_utf8_iterator_read_prev (&iter));
|
||||
JERRY_ASSERT (code_units[calculated_length] == lit_utf8_read_prev (&curr_p));
|
||||
}
|
||||
|
||||
JERRY_ASSERT (calculated_length == 0);
|
||||
}
|
||||
|
||||
/* Overlong-encoded code point */
|
||||
lit_utf8_byte_t invalid_utf8_string_1[] = {0xC0, 0x82};
|
||||
JERRY_ASSERT (!lit_is_cesu8_string_valid (invalid_utf8_string_1, sizeof (invalid_utf8_string_1)));
|
||||
lit_utf8_byte_t invalid_cesu8_string_1[] = {0xC0, 0x82};
|
||||
JERRY_ASSERT (!lit_is_cesu8_string_valid (invalid_cesu8_string_1, sizeof (invalid_cesu8_string_1)));
|
||||
|
||||
/* Overlong-encoded code point */
|
||||
lit_utf8_byte_t invalid_utf8_string_2[] = {0xE0, 0x80, 0x81};
|
||||
JERRY_ASSERT (!lit_is_cesu8_string_valid (invalid_utf8_string_2, sizeof (invalid_utf8_string_2)));
|
||||
lit_utf8_byte_t invalid_cesu8_string_2[] = {0xE0, 0x80, 0x81};
|
||||
JERRY_ASSERT (!lit_is_cesu8_string_valid (invalid_cesu8_string_2, sizeof (invalid_cesu8_string_2)));
|
||||
|
||||
/* Pair of surrogates: 0xD901 0xDFF0 which encode Unicode character 0x507F0 */
|
||||
lit_utf8_byte_t invalid_utf8_string_3[] = {0xED, 0xA4, 0x81, 0xED, 0xBF, 0xB0};
|
||||
JERRY_ASSERT (lit_is_cesu8_string_valid (invalid_utf8_string_3, sizeof (invalid_utf8_string_3)));
|
||||
lit_utf8_byte_t invalid_cesu8_string_3[] = {0xED, 0xA4, 0x81, 0xED, 0xBF, 0xB0};
|
||||
JERRY_ASSERT (lit_is_cesu8_string_valid (invalid_cesu8_string_3, sizeof (invalid_cesu8_string_3)));
|
||||
|
||||
/* Isolated high surrogate 0xD901 */
|
||||
lit_utf8_byte_t valid_utf8_string_1[] = {0xED, 0xA4, 0x81};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user