Skip to content

Commit 494c5ad

Browse files
committed
Rebase the function of unescape to cesu8
JerryScript-DCO-1.0-Signed-off-by: Szilard Ledan szledan.u-szeged@partner.samsung.com
1 parent b9c768d commit 494c5ad

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-global.cpp

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,8 @@ ecma_builtin_global_object_unescape (ecma_value_t this_arg __attr_unused___, /**
13901390
ssize_t sz = ecma_string_to_utf8_string (input_string_p, input_start_p, (ssize_t) (input_size));
13911391
JERRY_ASSERT (sz >= 0);
13921392

1393-
lit_utf8_iterator_t iterator = lit_utf8_iterator_create (input_start_p, input_size);
1393+
lit_utf8_byte_t *input_curr_p = input_start_p;
1394+
lit_utf8_byte_t *input_end_p = input_start_p + input_size;
13941395
/* 4. */
13951396
/* The length of input string is always greater than output string
13961397
* so we re-use the input string buffer.
@@ -1409,30 +1410,29 @@ ecma_builtin_global_object_unescape (ecma_value_t this_arg __attr_unused___, /**
14091410
* 8 found valid '%uwxyz' pattern
14101411
*/
14111412
uint8_t status = 0;
1412-
lit_code_point_t high_surrogate = 0;
1413-
lit_code_point_t hex_digits = 0;
1413+
ecma_char_t hex_digits = 0;
14141414
/* 5. */
1415-
while (!lit_utf8_iterator_is_eos (&iterator))
1415+
while (input_curr_p < input_end_p)
14161416
{
14171417
/* 6. */
1418-
lit_code_point_t code_point = lit_utf8_iterator_read_next (&iterator);
1418+
ecma_char_t chr = lit_utf8_read_next (&input_curr_p);
14191419

14201420
/* 7-8. */
1421-
if (status == 0 && code_point == LIT_CHAR_PERCENT)
1421+
if (status == 0 && chr == LIT_CHAR_PERCENT)
14221422
{
14231423
/* Found '%' char, start of escape sequence. */
14241424
status = 1;
14251425
}
14261426
/* 9-10. */
1427-
else if (status == 1 && code_point == LIT_CHAR_LOWERCASE_U)
1427+
else if (status == 1 && chr == LIT_CHAR_LOWERCASE_U)
14281428
{
14291429
/* Found 'u' char after '%'. */
14301430
status = 4;
14311431
}
1432-
else if (status > 0 && lit_char_is_hex_digit ((ecma_char_t) code_point))
1432+
else if (status > 0 && lit_char_is_hex_digit (chr))
14331433
{
14341434
/* Found hexadecimal digit in escape sequence. */
1435-
hex_digits = hex_digits * 16 + lit_char_hex_to_int ((ecma_char_t) code_point);
1435+
hex_digits = (ecma_char_t) (hex_digits * 16 + (ecma_char_t) lit_char_hex_to_int (chr));
14361436
status++;
14371437
}
14381438

@@ -1441,34 +1441,14 @@ ecma_builtin_global_object_unescape (ecma_value_t this_arg __attr_unused___, /**
14411441
{
14421442
output_char_p -= (status == 3) ? 2 : 5;
14431443
status = 0;
1444-
code_point = (ecma_char_t) hex_digits;
1444+
chr = hex_digits;
14451445
hex_digits = 0;
14461446
}
14471447

1448-
/* Handle surrogate pairs. */
1449-
bool is_non_bmp_middle = iterator.buf_pos.is_non_bmp_middle;
1450-
if (!high_surrogate && lit_is_code_unit_high_surrogate ((ecma_char_t) code_point))
1451-
{
1452-
high_surrogate = code_point;
1453-
1454-
if (is_non_bmp_middle)
1455-
{
1456-
code_point = lit_utf8_iterator_read_next (&iterator);
1457-
}
1458-
}
1459-
1460-
if (high_surrogate && lit_is_code_unit_low_surrogate ((ecma_char_t) code_point))
1461-
{
1462-
output_char_p -= is_non_bmp_middle ? 0 : 3;
1463-
code_point = lit_convert_surrogate_pair_to_code_point ((ecma_char_t) high_surrogate,
1464-
(ecma_char_t) code_point);
1465-
high_surrogate = 0;
1466-
}
1467-
14681448
/* Copying character. */
1469-
lit_utf8_size_t lit_size = lit_code_point_to_utf8 (code_point, output_char_p);
1449+
lit_utf8_size_t lit_size = lit_code_unit_to_utf8 (chr, output_char_p);
14701450
output_char_p += lit_size;
1471-
JERRY_ASSERT (output_char_p - input_start_p <= iterator.buf_pos.offset);
1451+
JERRY_ASSERT (output_char_p <= input_curr_p);
14721452
}
14731453

14741454
lit_utf8_size_t output_length = (lit_utf8_size_t) (output_char_p - input_start_p);

0 commit comments

Comments
 (0)