Skip to content

Commit 49facac

Browse files
committed
Add API documentation for create_string_from_utf8 and jerry_create_string_sz_from_utf8 functions.
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka [email protected]
1 parent 4a0f78b commit 49facac

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

docs/02.API-REFERENCE.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,78 @@ jerry_create_string_sz (const jerry_char_t *str_p,
19811981

19821982
- [jerry_create_string](#jerry_create_string)
19831983

1984+
## jerry_create_string_from_utf8
1985+
1986+
**Summary**
1987+
1988+
Create string from a valid UTF8 string.
1989+
1990+
*Note*: It differs from [jerry_create_string](#jerry_create_string) function in this converts all 4-bytes long unicode sequences into two 3-bytes long sequences.
1991+
1992+
**Prototype**
1993+
1994+
```c
1995+
jerry_value_t
1996+
jerry_create_string_from_utf8 (const jerry_char_t *str_p);
1997+
```
1998+
1999+
- `str_p` - pointer to string
2000+
- return value - value of the created string
2001+
2002+
**Example**
2003+
2004+
```c
2005+
{
2006+
const jerry_char_t char_array[] = "a string";
2007+
jerry_value_t string_value = jerry_create_string_from_utf8 (char_array);
2008+
2009+
... // usage of string_value
2010+
2011+
jerry_release_value (string_value);
2012+
}
2013+
```
2014+
2015+
**See also**
2016+
2017+
- [jerry_create_string_sz_from_utf8](#jerry_create_string_sz_from_utf8)
2018+
2019+
2020+
## jerry_create_string_sz_from_utf8
2021+
2022+
**Summary**
2023+
2024+
Create string from a valid UTF8 string.
2025+
2026+
**Prototype**
2027+
2028+
```c
2029+
jerry_value_t
2030+
jerry_create_string_sz (const jerry_char_t *str_p,
2031+
jerry_size_t str_size)
2032+
```
2033+
2034+
- `str_p` - pointer to string
2035+
- `str_size` - size of the string
2036+
- return value - value of the created string
2037+
2038+
**Example**
2039+
2040+
```c
2041+
{
2042+
const jerry_char_t char_array[] = "a string";
2043+
jerry_value_t string_value = jerry_create_string_sz_from_utf8 (char_array,
2044+
strlen ((const char *) char_array));
2045+
2046+
... // usage of string_value
2047+
2048+
jerry_release_value (string_value);
2049+
}
2050+
2051+
```
2052+
2053+
**See also**
2054+
2055+
- [jerry_create_string_from_utf8](#jerry_create_string_from_utf8)
19842056

19852057
## jerry_create_undefined
19862058

tests/unit/test-api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ main (void)
339339
TEST_ASSERT (sz == 0);
340340
jerry_release_value (args[0]);
341341

342+
// Test create_jerry_string_from_utf8 with 4-byte long unicode sequences
343+
args[0] = jerry_create_string_from_utf8 ((jerry_char_t *) "𝔡𝔢𝔣𝔤");
344+
sz = jerry_get_string_size (res);
345+
sz = jerry_string_to_char_buffer (res, (jerry_char_t *) buffer, sz);
346+
TEST_ASSERT (!strncmp (buffer, "𝔡𝔢𝔣𝔤", (size_t) sz));
347+
jerry_release_value (args[0]);
348+
342349
// Get global.boo (non-existing field)
343350
val_t = get_property (global_obj_val, "boo");
344351
TEST_ASSERT (!jerry_value_has_error_flag (val_t));

0 commit comments

Comments
 (0)