diff options
author | Adam Kocoloski <adam@cloudant.com> | 2011-10-04 13:11:12 -0700 |
---|---|---|
committer | Adam Kocoloski <adam@cloudant.com> | 2011-10-04 13:11:12 -0700 |
commit | da7284ed2844926c7df0efef12ba30d8e2e6d039 (patch) | |
tree | 10fa2d5cf35bfae4d48fc632924cec98ee02a22a /couchjs/c_src/utf8.c | |
parent | b57aadd742e4f8cc925ba4f005ae658c43a7c5b4 (diff) | |
parent | 4e19639a64d3033e1cc7c22a0b7404d277643c78 (diff) |
Merge pull request #67 from cloudant/12645-merge_latest_1.1.x
Diffstat (limited to 'couchjs/c_src/utf8.c')
-rw-r--r-- | couchjs/c_src/utf8.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/couchjs/c_src/utf8.c b/couchjs/c_src/utf8.c index 57928ba9..ace6badb 100644 --- a/couchjs/c_src/utf8.c +++ b/couchjs/c_src/utf8.c @@ -11,13 +11,7 @@ // the License. #include "config.h" -#ifdef HAVE_JS_JSAPI_H -#include <js/jsapi.h> -#elif HAVE_MOZJS_JSAPI_H -#include <mozjs/jsapi.h> -#else -#include <jsapi.h> -#endif +#include "sm.h" static int enc_char(uint8 *utf8Buffer, uint32 ucs4Char) @@ -128,7 +122,7 @@ char* enc_string(JSContext* cx, jsval arg, size_t* buflen) { JSString* str = NULL; - jschar* src = NULL; + const jschar* src = NULL; char* bytes = NULL; size_t srclen = 0; size_t byteslen = 0; @@ -136,12 +130,16 @@ enc_string(JSContext* cx, jsval arg, size_t* buflen) str = JS_ValueToString(cx, arg); if(!str) goto error; +#ifdef SM185 + src = JS_GetStringCharsAndLength(cx, str, &srclen); +#else src = JS_GetStringChars(str); srclen = JS_GetStringLength(str); +#endif if(!enc_charbuf(src, srclen, NULL, &byteslen)) goto error; - bytes = JS_malloc(cx, (byteslen) + 1); + bytes = (char*) JS_malloc(cx, (byteslen) + 1); bytes[byteslen] = 0; if(!enc_charbuf(src, srclen, bytes, &byteslen)) goto error; @@ -273,7 +271,7 @@ dec_string(JSContext* cx, const char* bytes, size_t byteslen) if(!dec_charbuf(bytes, byteslen, NULL, &charslen)) goto error; - chars = JS_malloc(cx, (charslen + 1) * sizeof(jschar)); + chars = (jschar*) JS_malloc(cx, (charslen + 1) * sizeof(jschar)); if(!chars) return NULL; chars[charslen] = 0; |