JS_GetStringBytes 编辑
Obsolete since JSAPI 1.8.5
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
Convert a JavaScript string to a C string.
Syntax
char *
JS_GetStringBytes(JSString *str);
const char *
JS_GetStringBytesZ(JSContext *cx, JSString *str); // Added in JSAPI 1.8.2
Name | Type | Description |
---|---|---|
cx | JSContext * | (JS_GetStringBytesZ and JS_EncodeString only) A context. |
str | JSString * | String to retrieve bytes from. |
Description
JS_GetStringBytes
and JS_GetStringBytesZ
convert the specified JavaScript string, str
, to a C string (an array of 8-bit char
s). If JS_CStringsAreUTF8
is true, then the returned string is UTF-8, and the conversion is lossless. Otherwise the high byte is simply dropped from each jschar
. On success, the return value is a pointer to the char array, which is null-terminated. On failure, JS_GetStringBytes
returns a pointer to a null-terminated empty string; JS_GetStringBytesZ
returns NULL
.
JS_GetStringBytes()
and JS_GetStringBytesZ()
have both been removed as of JavaScript 1.8.5 (Firefox 4). Instead, you should use JS_EncodeString
, JS_GetStringEncodingLength
, JS_EncodeStringToBuffer
.The array returned by JS_GetStringBytes
or JS_GetStringBytesZ
is automatically freed when str
is finalized by the JavaScript garbage collection mechanism. The application must not modify the contents of the array.
Note that for non-ASCII strings, if JS_CStringsAreUTF8
is false, these functions can return a corrupted copy of the contents of the string. Use JS_GetStringChars
to access the 16-bit characters of a JavaScript string without conversions or copying.
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论