Implement UnicodeEscape abstract method (#3959)
Also refactored ecma_builtin_json_quote to use the method above JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
@@ -331,6 +331,26 @@ lit_char_is_binary_digit (ecma_char_t c) /** code unit */
|
||||
} /* lit_char_is_binary_digit */
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
/**
|
||||
* UnicodeEscape abstract method
|
||||
*
|
||||
* See also: ECMA-262 v10, 24.5.2.3
|
||||
*/
|
||||
void
|
||||
lit_char_unicode_escape (ecma_stringbuilder_t *builder_p, /**< stringbuilder to append */
|
||||
ecma_char_t c) /**< code unit to convert */
|
||||
{
|
||||
ecma_stringbuilder_append_raw (builder_p, (lit_utf8_byte_t *) "\\u", 2);
|
||||
|
||||
for (int8_t i = 3; i >= 0; i--)
|
||||
{
|
||||
int32_t result_char = (c >> (i * 4)) & 0xF;
|
||||
ecma_stringbuilder_append_byte (builder_p, (lit_utf8_byte_t) (result_char + (result_char <= 9
|
||||
? LIT_CHAR_0
|
||||
: (LIT_CHAR_LOWERCASE_A - 10))));
|
||||
}
|
||||
} /* lit_char_unicode_escape */
|
||||
|
||||
/**
|
||||
* Convert a HexDigit character to its numeric value, as defined in ECMA-262 v5, 7.8.3
|
||||
*
|
||||
|
||||
@@ -223,6 +223,7 @@ bool lit_char_is_hex_digit (ecma_char_t c);
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
bool lit_char_is_binary_digit (ecma_char_t c);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
void lit_char_unicode_escape (ecma_stringbuilder_t *builder_p, ecma_char_t c);
|
||||
uint32_t lit_char_hex_to_int (ecma_char_t c);
|
||||
size_t lit_code_point_to_cesu8_bytes (uint8_t *dst_p, lit_code_point_t code_point);
|
||||
size_t lit_code_point_get_cesu8_length (lit_code_point_t code_point);
|
||||
|
||||
Reference in New Issue
Block a user