JS_NewStringCopyN 编辑
Create a new JS string.
Syntax
JSString *
JS_NewStringCopyN(JSContext *cx, const char *s, size_t n);
JSString *
JS_NewUCStringCopyN(JSContext *cx, const char16_t *s, size_t n);
Name | Type | Description |
---|---|---|
cx | JSContext * | Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
s | const char* or const char16_t * | Pointer to the array of characters containing the text for the JS string to create. |
n | size_t | Number of characters to copy from s into the new string. |
Description
JS_NewStringCopyN
allocates space for a JavaScript string and its underlying storage, and copies n
characters from a C character array, s
, into the new JSString
. JS_NewUCStringCopyN
is the Unicode version of the function. The two functions differ only in the type of the character array s
; both functions create ordinary JavaScript strings, and all JavaScript strings are made up of 16-bit characters.
If the array s
contains more than n
characters, the new string contains a truncated version of the original string. The string may contain null characters ('\0'
). They are copied into the new string like any other character.
You can use JS_NewStringCopyN
to copy binary data or to copy only a certain portion of a C string into a JavaScript string.
On success, JS_NewStringCopyN
and JS_NewUCStringCopyN
return a pointer to the new JS string. Otherwise they return NULL
.
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论