JS_EncodeString 编辑
This article covers features introduced in SpiderMonkey 1.8
Convert a JavaScript string to a C string.
Syntax
char *
JS_EncodeString(JSContext *cx, JSString *str);
char *
JS_EncodeStringToUTF8(JSContext *cx, JS::HandleString str); // Added in SpiderMonkey 24
Name | Type | Description |
---|---|---|
cx | JSContext * | A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext .. |
str | JSString * / JS::HandleString | A string to encode. |
Description
JS_EncodeString
and JS_EncodeStringToUTF8
convert the specified JavaScript str
to a C string (an array of 8-bit chars).
If JS_CStringsAreUTF8
is true
, then the returned string of JS_EncodeString
is UTF-8, and the conversion is lossless. Otherwise the high byte is simply dropped from each char16_t
.
JS_EncodeStringToUTF8
encode the string to UTF-8.
The array returned by JS_EncodeString
on success is allocated as though by a call to JS_malloc
. The caller may modify it and is responsible for freeing it.
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.
On success, JS_EncodeString
and JS_EncodeStringToUTF8
return a pointer to the char array, which is null-terminated.
On failure, JS_EncodeString
and JS_EncodeStringToUTF8
return NULL
See Also
- MXR ID Search for
JS_EncodeString
- MXR ID Search for
JS_EncodeStringToUTF8
JS_EncodeStringToBuffer
- bug 397215 - added
JS_EncodeString
- bug 835719 - added
JS_EncodeStringToBuffer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论