Implement String.fromCodePoint method (#3281)

The algorithm is based on ECMA-262 v6, 21.1.2.2

JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
Szilagyi Adam
2019-11-08 13:48:05 +01:00
committed by Robert Fancsik
parent e1fc90db0e
commit 35d9b1ab17
7 changed files with 172 additions and 1 deletions
+23
View File
@@ -243,6 +243,29 @@ convert_code_point_to_high_surrogate (lit_code_point_t code_point) /**< code poi
return (LIT_UTF16_HIGH_SURROGATE_MARKER | code_unit_bits);
} /* convert_code_point_to_high_surrogate */
/**
* UTF16 Encoding method for a code point
*
* See also:
* ECMA-262 v6, 10.1.1
*
* @return uint8_t, the number of returning code points
*/
uint8_t
lit_utf16_encode_code_point (lit_code_point_t cp, /**< the code point we encode */
ecma_char_t *cu_p) /**< result of the encoding */
{
if (cp <= LIT_UTF16_CODE_UNIT_MAX)
{
cu_p[0] = (ecma_char_t) cp;
return 1;
}
cu_p[0] = convert_code_point_to_high_surrogate (cp);
cu_p[1] = convert_code_point_to_low_surrogate (cp);
return 2;
} /* lit_utf16_encode_code_point */
/**
* Calculate size of a zero-terminated utf-8 string
*