napi_get_value_string_utf8
napi_status napi_get_value_string_utf8(napi_env env,
napi_value value,
char* buf,
size_t bufsize,
size_t* result) -
[in] env:调用 API 的环境。¥
[in] env: The environment that the API is invoked under. -
[in] value:napi_value代表 JavaScript 字符串。¥
[in] value:napi_valuerepresenting JavaScript string. -
[in] buf:将 UTF8 编码的字符串写入的缓冲区。如果传入NULL,则在result中返回以字节为单位的字符串长度,不包括空终止符。¥
[in] buf: Buffer to write the UTF8-encoded string into. IfNULLis passed in, the length of the string in bytes and excluding the null terminator is returned inresult. -
[in] bufsize:目标缓冲区的大小。当此值不足时,返回的字符串将被截断并以 null 终止。如果此值为零,则不返回字符串,也不会对缓冲区进行任何更改。¥
[in] bufsize: Size of the destination buffer. When this value is insufficient, the returned string is truncated and null-terminated. If this value is zero, then the string is not returned and no changes are done to the buffer. -
[out] result:复制到缓冲区中的字节数,不包括空终止符。¥
[out] result: Number of bytes copied into the buffer, excluding the null terminator.
如果 API 成功,则返回 napi_ok。如果传入非 string napi_value,则返回 napi_string_expected。
¥Returns napi_ok if the API succeeded. If a non-string napi_value
is passed in it returns napi_string_expected.
此 API 返回对应于传入值的 UTF8 编码字符串。
¥This API returns the UTF8-encoded string corresponding the value passed in.