Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: added napi_get_value_string_latin1 #14678

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 50 additions & 23 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1393,51 +1393,51 @@ The JavaScript Number type is described in
[Section 6.1.6](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type)
of the ECMAScript Language Specification.

#### *napi_create_string_utf16*
#### *napi_create_string_latin1*
<!-- YAML
added: v8.0.0
-->
```C
napi_status napi_create_string_utf16(napi_env env,
const char16_t* str,
size_t length,
napi_value* result)
NAPI_EXTERN napi_status napi_create_string_latin1(napi_env env,
const char* str,
size_t length,
napi_value* result);
```

- `[in] env`: The environment that the API is invoked under.
- `[in] str`: Character buffer representing a UTF16-LE-encoded string.
- `[in] length`: The length of the string in two-byte code units, or -1 if
it is null-terminated.
- `[in] str`: Character buffer representing a ISO-8859-1-encoded string.
- `[in] length`: The length of the string in bytes, or -1 if it is
null-terminated.
- `[out] result`: A `napi_value` representing a JavaScript String.

Returns `napi_ok` if the API succeeded.

This API creates a JavaScript String object from a UTF16-LE-encoded C string
This API creates a JavaScript String object from a ISO-8859-1-encoded C string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For V8 at least, the text doesn't have to be ISO-8859-1. "String encoded using a one-byte encoding" is perhaps more accurate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyGu huh? V8 does interpret that string as ISO-8859-1. We do use the …OneByte… methods in core for that encoding, and that’s what the V8 docs say (which, granted, I wrote, but also did pass review. 😄).


The JavaScript String type is described in
[Section 6.1.4](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-string-type)
of the ECMAScript Language Specification.

#### *napi_create_string_latin1*
#### *napi_create_string_utf16*
<!-- YAML
added: v8.0.0
-->
```C
NAPI_EXTERN napi_status napi_create_string_latin1(napi_env env,
const char* str,
size_t length,
napi_value* result);
napi_status napi_create_string_utf16(napi_env env,
const char16_t* str,
size_t length,
napi_value* result)
```

- `[in] env`: The environment that the API is invoked under.
- `[in] str`: Character buffer representing a latin1-encoded string.
- `[in] length`: The length of the string in bytes, or -1 if it is
null-terminated.
- `[in] str`: Character buffer representing a UTF16-LE-encoded string.
- `[in] length`: The length of the string in two-byte code units, or -1 if
it is null-terminated.
- `[out] result`: A `napi_value` representing a JavaScript String.

Returns `napi_ok` if the API succeeded.

This API creates a JavaScript String object from a latin1-encoded C string.
This API creates a JavaScript String object from a UTF16-LE-encoded C string

The JavaScript String type is described in
[Section 6.1.4](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-string-type)
Expand Down Expand Up @@ -1726,6 +1726,33 @@ is passed in it returns `napi_number_expected`.
This API returns the C int64 primitive equivalent of the given
JavaScript Number

#### *napi_get_value_string_latin1*
<!-- YAML
added: v8.0.0
-->
```C
NAPI_EXTERN napi_status napi_get_value_string_latin1(napi_env env,
napi_value value,
char* buf,
size_t bufsize,
size_t* result)
```

- `[in] env`: The environment that the API is invoked under.
- `[in] value`: `napi_value` representing JavaScript string.
- `[in] buf`: Buffer to write the ISO-8859-1-encoded string into. If NULL is
passed in, the length of the string (in bytes) is returned.
- `[in] bufsize`: Size of the destination buffer.
- `[out] result`: Number of bytes copied into the buffer including the null
terminator. If the buffer size is insufficient, the string will be truncated
including a null terminator.

Returns `napi_ok` if the API succeeded. If a non-String `napi_value`
is passed in it returns `napi_string_expected`.

This API returns the ISO-8859-1-encoded string corresponding the value passed
in.

#### *napi_get_value_string_utf8*
<!-- YAML
added: v8.0.0
Expand All @@ -1741,14 +1768,14 @@ napi_status napi_get_value_string_utf8(napi_env env,
- `[in] env`: The environment that the API is invoked under.
- `[in] value`: `napi_value` representing JavaScript string.
- `[in] buf`: Buffer to write the UTF8-encoded string into. If NULL is passed
in, the length of the string (in bytes) is returned.
in, the length of the string (in bytes) is returned.
- `[in] bufsize`: Size of the destination buffer.
- `[out] result`: Number of bytes copied into the buffer including the null.
- `[out] result`: Number of bytes copied into the buffer including the null
terminator. If the buffer size is insufficient, the string will be truncated
including a null terminator.

Returns `napi_ok` if the API succeeded. Ifa non-String `napi_value`
x is passed in it returns `napi_string_expected`.
Returns `napi_ok` if the API succeeded. If a non-String `napi_value`
is passed in it returns `napi_string_expected`.

This API returns the UTF8-encoded string corresponding the value passed in.

Expand All @@ -1770,7 +1797,7 @@ napi_status napi_get_value_string_utf16(napi_env env,
passed in, the length of the string (in 2-byte code units) is returned.
- `[in] bufsize`: Size of the destination buffer.
- `[out] result`: Number of 2-byte code units copied into the buffer including
the null terminateor. If the buffer size is insufficient, the string will be
the null terminator. If the buffer size is insufficient, the string will be
truncated including a null terminator.

Returns `napi_ok` if the API succeeded. If a non-String `napi_value`
Expand Down