This article needs a technical review. How you can help.
This article covers features introduced in SpiderMonkey 1.8
char * JS_EncodeString(JSContext *cx, JSString *str); char * JS_EncodeStringToUTF8(JSContext *cx, JS::HandleString str); // Added in SpiderMonkey 24
||A context. Requires request. In a
||A string to encode.|
str to a C string (an array of 8-bit chars).
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
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_EncodeStringToUTF8 return a pointer to the char array, which is null-terminated.
JS_EncodeStringToUTF8 return NULL