diff --git a/quickjs.c b/quickjs.c index 2423d40..76b990b 100644 --- a/quickjs.c +++ b/quickjs.c @@ -3994,6 +3994,18 @@ JSValue JS_NewAtomString(JSContext *ctx, const char *str) return val; } +uint8_t *JS_ToCStringLenRaw(JSContext *ctx, size_t *plen, JSValueConst val) +{ + if (JS_VALUE_GET_TAG(val) != JS_TAG_STRING) + { + if(plen) *plen = 0; + return NULL; + } + JSString *str = JS_VALUE_GET_STRING(val); + if(plen) *plen = str->len; + return str->u.str8; +} + /* return (NULL, 0) if exception. */ /* return pointer into a JSString with a live ref_count */ /* cesu8 determines if non-BMP1 codepoints are encoded as 1 or 2 utf-8 sequences */ diff --git a/quickjs.h b/quickjs.h index 09ad07d..5f9f805 100644 --- a/quickjs.h +++ b/quickjs.h @@ -702,6 +702,7 @@ JSValue JS_NewString(JSContext *ctx, const char *str); JSValue JS_NewAtomString(JSContext *ctx, const char *str); JSValue JS_ToString(JSContext *ctx, JSValueConst val); JSValue JS_ToPropertyKey(JSContext *ctx, JSValueConst val); +uint8_t *JS_ToCStringLenRaw(JSContext *ctx, size_t *plen, JSValueConst val1); const char *JS_ToCStringLen2(JSContext *ctx, size_t *plen, JSValueConst val1, JS_BOOL cesu8); static inline const char *JS_ToCStringLen(JSContext *ctx, size_t *plen, JSValueConst val1) {