Add an API function to calculate the UTF-8 encoded string length from Jerry string. (#1460)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
This commit is contained in:
+10
-3
@@ -305,7 +305,7 @@ main (void)
|
||||
|
||||
bool is_ok;
|
||||
jerry_size_t sz, utf8_sz, cesu8_sz;
|
||||
jerry_length_t cesu8_length;
|
||||
jerry_length_t cesu8_length, utf8_length;
|
||||
jerry_value_t val_t, val_foo, val_bar, val_A, val_A_prototype, val_a, val_a_foo, val_value_field, val_p, val_np;
|
||||
jerry_value_t val_call_external;
|
||||
jerry_value_t global_obj_val, obj_val;
|
||||
@@ -365,10 +365,12 @@ main (void)
|
||||
args[0] = jerry_create_string_from_utf8 ((jerry_char_t *) "\x73\x74\x72\x3a \xf0\x9d\x94\xa3 \xf0\x9d\x94\xa4");
|
||||
|
||||
cesu8_length = jerry_get_string_length (args[0]);
|
||||
utf8_length = jerry_get_utf8_string_length (args[0]);
|
||||
|
||||
cesu8_sz = jerry_get_string_size (args[0]);
|
||||
utf8_sz = jerry_get_utf8_string_size (args[0]);
|
||||
|
||||
TEST_ASSERT (cesu8_length == 10);
|
||||
TEST_ASSERT (cesu8_length == 10 && utf8_length == 8);
|
||||
TEST_ASSERT (cesu8_sz != utf8_sz);
|
||||
TEST_ASSERT (utf8_sz == 14 && cesu8_sz == 18);
|
||||
jerry_release_value (args[0]);
|
||||
@@ -377,10 +379,12 @@ main (void)
|
||||
args[0] = jerry_create_string ((jerry_char_t *) "\x73\x74\x72\x3a \xed\xa0\x81\xed\xb0\x80");
|
||||
|
||||
cesu8_length = jerry_get_string_length (args[0]);
|
||||
utf8_length = jerry_get_utf8_string_length (args[0]);
|
||||
|
||||
cesu8_sz = jerry_get_string_size (args[0]);
|
||||
utf8_sz = jerry_get_utf8_string_size (args[0]);
|
||||
|
||||
TEST_ASSERT (cesu8_length == 7);
|
||||
TEST_ASSERT (cesu8_length == 7 && utf8_length == 6);
|
||||
TEST_ASSERT (cesu8_sz != utf8_sz);
|
||||
TEST_ASSERT (utf8_sz == 9 && cesu8_sz == 11);
|
||||
|
||||
@@ -390,9 +394,12 @@ main (void)
|
||||
args[0] = jerry_create_string_from_utf8 ((jerry_char_t *) "\x70\x72\x69\x63\x65\x3a \x31\x30\xe2\x82\xac");
|
||||
|
||||
cesu8_length = jerry_get_string_length (args[0]);
|
||||
utf8_length = jerry_get_utf8_string_length (args[0]);
|
||||
|
||||
cesu8_sz = jerry_get_string_size (args[0]);
|
||||
utf8_sz = jerry_get_utf8_string_size (args[0]);
|
||||
|
||||
TEST_ASSERT (cesu8_length == utf8_length);
|
||||
TEST_ASSERT (cesu8_length == 10);
|
||||
TEST_ASSERT (cesu8_sz == utf8_sz);
|
||||
TEST_ASSERT (utf8_sz == 12);
|
||||
|
||||
Reference in New Issue
Block a user