Add an API function to calculate the UTF-8 encoded string size from Jerry string. (#1450)

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
This commit is contained in:
Robert Sipka
2016-11-29 12:25:18 +01:00
committed by GitHub
parent 6a2f54456f
commit 0467239d03
8 changed files with 189 additions and 11 deletions
+37
View File
@@ -1150,6 +1150,43 @@ jerry_get_string_size (const jerry_value_t value);
- [jerry_get_string_length](#jerry_get_string_length)
## jerry_get_utf8_string_size
**Summary**
Get the size of an utf8-encoded string. Returns zero, if the value parameter is not a string.
*Note*: The difference from [jerry_get_string_size](#jerry_get_string_size) is that it returns with utf-8 string size
instead of the cesu-8 string size.
**Prototype**
```c
jerry_size_t
jerry_get_utf8_string_size (const jerry_value_t value);
```
- `value` - api value
- return value - number of bytes in the buffer needed to represent the utf8-encoded string.
**Example**
```c
{
const jerry_char_t char_array[] = "a string";
jerry_value_t string = jerry_create_string (char_array);
jerry_size_t string_size = jerry_get_utf8_string_size (string);
... // usage of string_size
jerry_release_value (string);
}
```
**See also**
- [jerry_create_string_from_utf8](#jerry_create_string_from_utf8)
## jerry_get_string_length
**Summary**