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);
NameTypeDescription
cxJSContext *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.
sconst char* or const char16_t *Pointer to the array of characters containing the text for the JS string to create.
nsize_tNumber 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:93 次

字数:3392

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文