raw access to string bytes

This commit is contained in:
Zia 2024-03-14 01:24:16 +03:30
parent adcfe4cadb
commit 619be5b1a4
2 changed files with 13 additions and 0 deletions

View file

@ -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 */

View file

@ -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)
{