From: Fabrice Bellard Date: Sat, 28 Nov 2026 10:15:57 +0000 (+0100) Subject: documented that JS_ToCStringLen2() with cesu8 = false uses the WTF-8 encoding (#626) X-Git-Url: https://git.kaiwu.me/http/%22..//%22?a=commitdiff_plain;h=88d5d76bbbeed0d02f1fb4c59e1ecc9c5b91d71f;p=quickjs.git documented that JS_ToCStringLen2() with cesu8 = false uses the WTF-8 encoding (#626) --- diff --git a/doc/quickjs.texi b/doc/quickjs.texi index 79807e8..09c9537 100644 --- a/doc/quickjs.texi +++ b/doc/quickjs.texi @@ -973,9 +973,10 @@ example is only used to test the binary object format functions. Strings are stored either as an 8 bit or a 16 bit array of characters. Hence random access to characters is always fast. -The C API provides functions to convert Javascript Strings to C UTF-8 encoded -strings. The most common case where the Javascript string contains -only ASCII characters involves no copying. +The C API provides functions to convert Javascript Strings to C WTF-8 +encoded strings (UTF-8 with lone surrogates if they are not in a +pair). The most common case where the Javascript string contains only +ASCII characters involves no copying. @subsection Objects diff --git a/quickjs.c b/quickjs.c index 0f2a4c2..06d9ecc 100644 --- a/quickjs.c +++ b/quickjs.c @@ -4654,7 +4654,9 @@ JSValue JS_NewAtomString(JSContext *ctx, const char *str) /* 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 */ +/* If cesu8 is false, a WTF-8 string is returned (UTF-8 with lone + surrogates if they are not in a pair). If cesu8 is true, paired or + unpaired surrogates are encoded. */ const char *JS_ToCStringLen2(JSContext *ctx, size_t *plen, JSValueConst val1, BOOL cesu8) { JSValue val;