@@ -3836,7 +3836,7 @@ jerry_error_type (const jerry_value_t value);
38363836
38373837```c
38383838{
3839- jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_RANGE, "error msg");
3839+ jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_RANGE, jerry_string_sz ( "error msg") );
38403840 jerry_error_t error_type = jerry_error_type (error_obj);
38413841
38423842 // error_type is now JERRY_ERROR_RANGE.
@@ -3958,7 +3958,7 @@ void main(void)
39583958
39593959 jerry_error_on_created (error_object_created_callback, NULL);
39603960
3961- jerry_value_free (jerry_error_sz (JERRY_ERROR_COMMON, "Message"));
3961+ jerry_value_free (jerry_error_sz (JERRY_ERROR_COMMON, jerry_string_sz ( "Message") ));
39623962
39633963 jerry_cleanup ();
39643964} /* main */
@@ -4153,7 +4153,7 @@ throw_exception (const jerry_call_info_t *call_info_p, /**< call info */
41534153 (void) argv;
41544154 (void) argc;
41554155
4156- jerry_value_t result_value = jerry_throw_sz (JERRY_ERROR_COMMON, "Error!");
4156+ jerry_value_t result_value = jerry_throw_sz (JERRY_ERROR_COMMON, jerry_string_sz ( "Error!") );
41574157
41584158 /* Ignore calling the vm_throw_callback function. */
41594159 jerry_exception_allow_capture (result_value, false);
@@ -4541,7 +4541,7 @@ main (void)
45414541
45424542 jerry_string_external_on_free (external_string_free_callback);
45434543
4544- const char * string_p = "This is a long external string, should not be duplicated!";
4544+ #define string_p "This is a long external string, should not be duplicated!"
45454545 jerry_value_t external_string = jerry_string_external_sz (string_p, NULL);
45464546 /* The external_string_free_callback is called. */
45474547 jerry_value_free (external_string);
@@ -4602,7 +4602,7 @@ main (void)
46024602{
46034603 jerry_init (JERRY_INIT_EMPTY);
46044604
4605- const char * string_p = "This is a long external string, should not be duplicated!";
4605+ #define string_p "This is a long external string, should not be duplicated!"
46064606
46074607 jerry_value_t external_string = jerry_string_external_sz (string_p, (void *) &user_value);
46084608
@@ -7158,12 +7158,12 @@ jerry_boolean (bool value);
71587158
71597159**Summary**
71607160
7161- Create new JavaScript Error object with the specified error message.
7162-
7163- Important! The `error_type` argument *must not be* `JERRY_ERROR_NONE`.
7164- Creating an Error object with no error type is not valid.
7161+ Create an Error object with the provided `message` string value as the error `message` property.
7162+ If the `message` value is not a string, the created error will not have a `message` property.
71657163
71667164*Note*:
7165+ - Important! The `error_type` argument *must not be* `JERRY_ERROR_NONE`.
7166+ Creating an Error object with no error type is not valid.
71677167- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it
71687168 is no longer needed.
71697169
@@ -7206,21 +7206,25 @@ jerry_error (jerry_error_t error_type, jerry_value_t message);
72067206
72077207**Summary**
72087208
7209- Create new JavaScript Error object, using the a zero-terminated string as the error message.
7209+ Create an Error object with the provided `message_sz` string value as the error `message` property.
7210+ If the `message_sz` value is not a string, the created error will not have a `message` property.
72107211
72117212*Note*:
7213+ - Important! The `error_type` argument *must not be* `JERRY_ERROR_NONE`.
7214+ Creating an Error object with no error type is not valid.
72127215- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it
72137216 is no longer needed.
7217+ - The `message_sz` value will be freed in this function.
72147218
72157219**Prototype**
72167220
72177221```c
72187222jerry_value_t
7219- jerry_error_sz (jerry_error_t error_type, const char *message_p );
7223+ jerry_error_sz (jerry_error_t error_type, const jerry_value_t message_sz );
72207224```
72217225
72227226- `error_type` - type of the error
7223- - `message_p ` - value of ' message' property of the constructed error object
7227+ - `message_sz ` - message of the error that will be free/take
72247228- return value - constructed error object
72257229
72267230*Renamed in version 3.0, it was previously known as `jerry_create_error` in earlier versions.*
@@ -7229,7 +7233,7 @@ jerry_error_sz (jerry_error_t error_type, const char *message_p);
72297233
72307234```c
72317235{
7232- jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_TYPE, "error");
7236+ jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_TYPE, jerry_string_sz ( "error") );
72337237
72347238 ... // usage of error_obj
72357239
@@ -7757,20 +7761,21 @@ main (void)
77577761
77587762**Summary**
77597763
7760- Create string from a zero-terminated ASCII string.
7764+ Create string value from the zero-terminated UTF-8 encoded literal string.
7765+ The content of the buffer is assumed be encoded correctly, it's the callers
7766+ responsibility to validate the input.
77617767
77627768*Note*:
7763- - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it
7764- is no longer needed.
7769+ - This is a macro that only accept literal string
7770+ - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed.
77657771
77667772**Prototype**
77677773
77687774```c
7769- jerry_value_t
7770- jerry_string_sz (const char *str_p);
7775+ #define jerry_string_sz(str)
77717776```
77727777
7773- - `str_p ` - non-null pointer to zero-terminated string
7778+ - `str ` - A zero-terminated UTF-8 encoded literal string
77747779- return value - created string
77757780
77767781*Renamed in version 3.0, it was previously known as `jerry_create_string` in earlier versions.*
@@ -7779,7 +7784,7 @@ jerry_string_sz (const char *str_p);
77797784
77807785```c
77817786{
7782- const char char_array[] = "a string";
7787+ #define char_array "a string"
77837788 jerry_value_t string_value = jerry_string_sz (char_array);
77847789
77857790 ... // usage of string_value
@@ -7790,7 +7795,7 @@ jerry_string_sz (const char *str_p);
77907795
77917796**See also**
77927797
7793- - [jerry_string ](#jerry_string )
7798+ - [jerry_string_utf8 ](#jerry_string_utf8 )
77947799
77957800
77967801## jerry_string
@@ -7839,31 +7844,120 @@ jerry_string (const jerry_char_t *buffer_p,
78397844
78407845- [jerry_validate_string](#jerry_validate_string)
78417846- [jerry_string_sz](#jerry_string_sz)
7847+ - [jerry_string_utf8](#jerry_string_utf8)
7848+ - [jerry_string_cesu8](#jerry_string_cesu8)
7849+
7850+
7851+ ## jerry_string_utf8
7852+
7853+ **Summary**
7854+
7855+ Create a string value from the input buffer using the UTF-8 encoding.
7856+ The content of the buffer is assumed to be valid in the UTF-8 encoding,
7857+ it's the callers responsibility to validate the input.
7858+
7859+ *Note*:
7860+ - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed.
7861+
7862+ **Prototype**
7863+
7864+ ```c
7865+ jerry_value_t
7866+ jerry_string_utf8 (const jerry_char_t *buffer_p,
7867+ jerry_size_t buf_size)
7868+ ```
7869+
7870+ - `buffer_p` - non-null pointer to buffer
7871+ - `buf_size` - size of the buffer
7872+
7873+ **Example**
7874+
7875+ ```c
7876+ {
7877+ const jerry_char_t char_array[] = "a string";
7878+ jerry_value_t string_value = jerry_string_utf8 (char_array,
7879+ sizeof (char_array) - 1);
7880+
7881+ ... // usage of string_value
7882+
7883+ jerry_value_free (string_value);
7884+ }
7885+
7886+ ```
7887+
7888+ **See also**
7889+
7890+ - [jerry_validate_string](#jerry_validate_string)
7891+ - [jerry_string_sz](#jerry_string_sz)
7892+ - [jerry_string](#jerry_string)
7893+
7894+
7895+ ## jerry_string_cesu8
7896+
7897+ **Summary**
7898+
7899+ Create a string value from the input buffer using the CESU-8 encoding.
7900+ The content of the buffer is assumed to be valid in the CESU-8 encoding,
7901+ it's the callers responsibility to validate the input.
7902+
7903+ *Note*:
7904+ - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed.
7905+
7906+ **Prototype**
7907+
7908+ ```c
7909+ jerry_value_t
7910+ jerry_string_cesu8 (const jerry_char_t *buffer_p,
7911+ jerry_size_t buf_size)
7912+ ```
7913+
7914+ - `buffer_p` - non-null pointer to buffer
7915+ - `buf_size` - size of the buffer
7916+
7917+ **Example**
7918+
7919+ ```c
7920+ {
7921+ const jerry_char_t char_array[] = "\xed\xa0\x83\xed\xb2\x80";
7922+ jerry_value_t string_value = jerry_string_cesu8 (char_array,
7923+ sizeof (char_array) - 1);
7924+
7925+ ... // usage of string_value
7926+
7927+ jerry_value_free (string_value);
7928+ }
7929+
7930+ ```
7931+
7932+ **See also**
7933+
7934+ - [jerry_validate_string](#jerry_validate_string)
7935+ - [jerry_string](#jerry_string)
78427936
78437937
78447938## jerry_string_external_sz
78457939
78467940**Summary**
78477941
7848- Create an external string from a zero-terminated ASCII string. The string buffer passed to the function
7849- should not be modified until the free callback is called. This function can be used to avoid
7850- the duplication of large strings .
7942+ Create external string from the zero-terminated CESU encoded literal string.
7943+ The content of the buffer is assumed be encoded correctly, it's the callers
7944+ responsibility to validate the input .
78517945
78527946*Note*:
7947+ - This is a macro that only accept literal string
78537948- The free callback can be set by [jerry_string_external_on_free](#jerry_string_external_on_free)
78547949- Returned value must be freed with [jerry_value_free](#jerry_value_free)
78557950 when it is no longer needed.
78567951
78577952**Prototype**
78587953
78597954```c
7860- jerry_value_t
7861- jerry_string_external_sz (const char *str_p, void *user_p);
7955+ #define jerry_string_external_sz(str, user_p)
78627956```
78637957
7864- - `str_p` - non-null pointer to a zero-terminated string
7958+ - `str_p` - A zero-terminated CESU-8 encoded literal string
78657959- `user_p` - user pointer passed to the callback when the string is freed
7866- - return value - value of the created string
7960+ - return value - created external string
78677961
78687962*Introduced in version 2.4*.
78697963
@@ -8096,10 +8190,10 @@ jerry_regexp_sz (const jerry_char_t *pattern_p, uint16_t flags);
80968190
80978191```c
80988192{
8099- jerry_char_t pattern_p = "[cgt]gggtaaa|tttaccc[acg]";
8193+ #define pattern "[cgt]gggtaaa|tttaccc[acg]"
81008194 uint16_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE;
81018195
8102- jerry_value_t regexp = jerry_regexp_sz (pattern_p , pattern_flags);
8196+ jerry_value_t regexp = jerry_regexp_sz (jerry_string_sz (pattern) , pattern_flags);
81038197
81048198 ...
81058199
@@ -8141,7 +8235,7 @@ jerry_regexp (const jerry_value_t pattern, uint16_t flags);
81418235{
81428236 jerry_char_t pattern_p = "[cgt]gggtaaa|tttaccc[acg]";
81438237 jerry_size_t pattern_size = sizeof (pattern_p) - 1;
8144- jerry_value_t pattern_str = jerry_string (pattern_p, pattern_size, JERRY_ENCODING_UTF8 );
8238+ jerry_value_t pattern_str = jerry_string_utf8 (pattern_p, pattern_size);
81458239
81468240 uint16_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE;
81478241
0 commit comments