diff options
author | bptato <nincsnevem662@gmail.com> | 2023-10-21 23:34:56 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-10-21 23:40:24 +0200 |
commit | 18008acc141a55449b28c1af487a080c4bbcb355 (patch) | |
tree | a81872bfc2e2add0b0c9b6f65f3be15f4d2790c8 /lib/quickjs/quickjs.c | |
parent | 69870f3b974e65d61b564b396e01d21cc023e6e9 (diff) | |
download | chawan-18008acc141a55449b28c1af487a080c4bbcb355.tar.gz |
base64: reduce pointless re-coding using JSString
We now expose some functions from QuickJS to interact with JavaScript strings without re-encoding them into UTF-8.
Diffstat (limited to 'lib/quickjs/quickjs.c')
-rw-r--r-- | lib/quickjs/quickjs.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/quickjs/quickjs.c b/lib/quickjs/quickjs.c index 61bcce93..697ced39 100644 --- a/lib/quickjs/quickjs.c +++ b/lib/quickjs/quickjs.c @@ -208,7 +208,6 @@ typedef enum JSErrorEnum { #define __exception __attribute__((warn_unused_result)) typedef struct JSShape JSShape; -typedef struct JSString JSString; typedef struct JSString JSAtomStruct; typedef enum { @@ -4101,6 +4100,34 @@ void JS_FreeCString(JSContext *ctx, const char *ptr) JS_FreeValue(ctx, JS_MKPTR(JS_TAG_STRING, p)); } +/* create a string from a narrow Unicode (latin-1) buffer */ +JSValue JS_NewNarrowStringLen(JSContext *ctx, const char *buf, size_t buf_len) +{ + if (buf_len > JS_STRING_LEN_MAX) + return JS_ThrowInternalError(ctx, "string too long"); + return js_new_string8(ctx, (const uint8_t *)buf, buf_len); +} + +JS_BOOL JS_IsStringWideChar(JSString *str) +{ + return str->is_wide_char; +} + +uint8_t *JS_GetNarrowStringBuffer(JSString *str) +{ + return str->u.str8; +} + +uint16_t *JS_GetWideStringBuffer(JSString *str) +{ + return str->u.str16; +} + +uint32_t JS_GetStringLength(JSString *str) +{ + return str->len; +} + static int memcmp16_8(const uint16_t *src1, const uint8_t *src2, int len) { int c, i; |