lynx_value_get_string_utf8

介绍

从 lynx_value 中读取一个 UTF8 编码的字符串,字符串将会被拷贝。

语法

lynx_api_status lynx_value_get_string_utf8(lynx_api_env env,
                                           lynx_value value,
                                           char* buf,
                                           size_t bufsize,
                                           size_t* result);

参数

KeyDescription
[in] envlynx_value 的运行环境,一般情况下是 nullptr
[in] valuestring 类型 lynx_value
[in] buf用于容纳 UTF8 字符串的 Buffer,如果它传 NULL,将会返回数组长度
[in] bufsize想要读取字符串的长度,如果这个值为零,则不会返回字符串
[out] result复制到缓冲区的字节数,不包括空终止符

返回值

Returns lynx_api_ok if the API succeeded. Returns lynx_api_string_expected if the types do not match.

示例

size_t length = 0;
lynx_api_status status = lynx_value_get_string_utf8(env, string_value, nullptr, 0, &length);
if (status != lynx_api_ok) {
  // handle error.
}
std::string str;
str.resize(length);
status = lynx_value_get_string_utf8(env, string_value, &str[0], length + 1, &length);
if (status != lynx_api_ok) {
  // handle error.
}
除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。