]> git.kaiwu.me - quickjs.git/commitdiff
documented that JS_ToCStringLen2() with cesu8 = false uses the WTF-8 encoding (#626)
authorFabrice Bellard <fabrice@bellard.org>
Sat, 28 Nov 2026 10:15:57 +0000 (11:15 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 28 Nov 2026 10:15:57 +0000 (11:15 +0100)
doc/quickjs.texi
quickjs.c

index 79807e821904640afeb763d11b2b8dd3d2a8f6bc..09c9537f4f4a74e1283bddc8a6340c073935974b 100644 (file)
@@ -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
 
index 0f2a4c2e5327ffeb7e18f5885ee1300e5e85e1ac..06d9ecc498802e21b39635d28e49ec668dca34d1 100644 (file)
--- 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;