Add core unicode functionality.

Add utf-8 processing routines.
Change ecma_char_t from char/uint16_t to uint16_t.
Apply all utf-8 processing routines.
Change char to jerry_api_char in API functions' declarations.

JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
Andrey Shitov
2015-06-29 19:17:17 +03:00
parent c4b0cd2196
commit fd9ff8e3bd
56 changed files with 2468 additions and 1480 deletions
+11 -13
View File
@@ -79,32 +79,30 @@ opfunc_native_call (opcode_t opdata, /**< operation data */
ecma_string_t *str_p = ecma_get_string_from_value (str_value);
ecma_length_t chars = ecma_string_get_length (str_p);
lit_utf8_size_t bytes = ecma_string_get_size (str_p);
ssize_t zt_str_size = (ssize_t) (sizeof (ecma_char_t) * (chars + 1));
ecma_char_t *zt_str_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) zt_str_size,
MEM_HEAP_ALLOC_SHORT_TERM);
if (zt_str_p == NULL)
ssize_t utf8_str_size = (ssize_t) (bytes + 1);
lit_utf8_byte_t *utf8_str_p = (lit_utf8_byte_t*) mem_heap_alloc_block ((size_t) utf8_str_size,
MEM_HEAP_ALLOC_SHORT_TERM);
if (utf8_str_p == NULL)
{
jerry_fatal (ERR_OUT_OF_MEMORY);
}
ecma_string_to_zt_string (str_p, zt_str_p, zt_str_size);
ecma_string_to_utf8_string (str_p, utf8_str_p, utf8_str_size);
utf8_str_p[utf8_str_size - 1] = 0;
#if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII
FIXME ("Support unicode in printf.");
if (arg_index < args_read - 1)
{
printf ("%s ", (char*) zt_str_p);
printf ("%s ", (char*) utf8_str_p);
}
else
{
printf ("%s", (char*) zt_str_p);
printf ("%s", (char*) utf8_str_p);
}
#elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16
JERRY_UNIMPLEMENTED ("UTF-16 support is not implemented.");
#endif /* CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 */
mem_heap_free_block (zt_str_p);
mem_heap_free_block (utf8_str_p);
ret_value = set_variable_value (int_data, lit_oc, dst_var_idx,
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED));
+14 -13
View File
@@ -175,15 +175,14 @@ opfunc_assignment (opcode_t opdata, /**< operation data */
int_data->pos);
ecma_string_t *string_p = ecma_new_ecma_string_from_lit_cp (lit_cp);
ecma_length_t re_str_len = ecma_string_get_length (string_p);
MEM_DEFINE_LOCAL_ARRAY (re_str_p, re_str_len + 1, ecma_char_t);
lit_utf8_size_t re_utf8_buffer_size = ecma_string_get_size (string_p);
MEM_DEFINE_LOCAL_ARRAY (re_utf8_buffer_p, re_utf8_buffer_size, lit_utf8_byte_t);
ssize_t zt_str_size = (ssize_t) (sizeof (ecma_char_t) * (re_str_len + 1));
ecma_string_to_zt_string (string_p, re_str_p, zt_str_size);
ecma_string_to_utf8_string (string_p, re_utf8_buffer_p, (ssize_t) re_utf8_buffer_size);
ecma_char_t *ch_p = re_str_p;
ecma_char_t *last_slash_p = NULL;
while (*ch_p)
lit_utf8_byte_t *ch_p = re_utf8_buffer_p;
lit_utf8_byte_t *last_slash_p = NULL;
while (ch_p < re_utf8_buffer_p + re_utf8_buffer_size)
{
if (*ch_p == '/')
{
@@ -193,14 +192,16 @@ opfunc_assignment (opcode_t opdata, /**< operation data */
}
JERRY_ASSERT (last_slash_p != NULL);
JERRY_ASSERT ((re_str_p < last_slash_p) && (last_slash_p < ch_p));
JERRY_ASSERT ((last_slash_p - re_str_p) > 0);
ecma_string_t *pattern_p = ecma_new_ecma_string (re_str_p, (ecma_length_t) (last_slash_p - re_str_p));
JERRY_ASSERT ((re_utf8_buffer_p < last_slash_p) && (last_slash_p < ch_p));
JERRY_ASSERT ((last_slash_p - re_utf8_buffer_p) > 0);
ecma_string_t *pattern_p = ecma_new_ecma_string_from_utf8 (re_utf8_buffer_p,
(lit_utf8_size_t) (last_slash_p - re_utf8_buffer_p));
ecma_string_t *flags_p = NULL;
if ((ch_p - last_slash_p) > 1)
{
flags_p = ecma_new_ecma_string (last_slash_p + 1, (ecma_length_t) ((ch_p - last_slash_p - 1)));
flags_p = ecma_new_ecma_string_from_utf8 (last_slash_p + 1,
(lit_utf8_size_t) ((ch_p - last_slash_p - 1)));
}
ECMA_TRY_CATCH (regexp_obj_value,
@@ -220,7 +221,7 @@ opfunc_assignment (opcode_t opdata, /**< operation data */
ecma_deref_ecma_string (flags_p);
}
MEM_FINALIZE_LOCAL_ARRAY (re_str_p)
MEM_FINALIZE_LOCAL_ARRAY (re_utf8_buffer_p)
ecma_deref_ecma_string (string_p);
#else
JERRY_UNIMPLEMENTED ("Regular Expressions are not supported in compact profile!");
@@ -564,7 +565,7 @@ opfunc_func_decl_n (opcode_t opdata, /**< operation data */
int_data->pos++;
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ecma_completion_value_t ret_value;
MEM_DEFINE_LOCAL_ARRAY (params_names, params_number, ecma_string_t*);