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:
Robert Sipka
2016-12-01 10:51:23 +01:00
committed by GitHub
parent 958344ee16
commit 23cf7fd177
8 changed files with 160 additions and 11 deletions
+39
View File
@@ -1186,6 +1186,7 @@ jerry_get_utf8_string_size (const jerry_value_t value);
**See also**
- [jerry_create_string_from_utf8](#jerry_create_string_from_utf8)
- [jerry_get_utf8_string_length](#jerry_get_utf8_string_length)
## jerry_get_string_length
@@ -1223,6 +1224,44 @@ jerry_get_string_length (const jerry_value_t value);
- [jerry_create_string](#jerry_create_string)
- [jerry_get_string_size](#jerry_get_string_size)
## jerry_get_utf8_string_length
**Summary**
Get the length of an UTF-8 encoded string. Returns zero, if the value parameter is not a string.
*Note*: The difference from [jerry_get_string_length](#jerry_get_string_length) is that it
returns with utf-8 string length instead of the cesu-8 string length.
**Prototype**
```c
jerry_length_t
jerry_get_utf8_string_length (const jerry_value_t value);
```
- `value` - input string value
- return value - number of characters in the string
**Example**
```c
{
const jerry_char_t char_array[] = "a string";
jerry_value_t string = jerry_create_string_from_utf8 (char_array);
jerry_length_t string_length = jerry_get_utf8_string_length (string);
... // usage of string_length
jerry_release_value (string);
}
```
**See also**
- [jerry_create_string_from_utf8](#jerry_create_string_from_utf8)
- [jerry_get_utf8_string_size](#jerry_get_utf8_string_size)
## jerry_string_to_char_buffer