From 29aee6fc9357613c8d5a4f9ce8d9ffc21f79f9ee Mon Sep 17 00:00:00 2001 From: George Zhao Date: Wed, 9 Oct 2024 15:26:16 +0800 Subject: [PATCH] doc: add String manipulation functions --- docs.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/docs.md b/docs.md index ca85c43f..76c555e9 100644 --- a/docs.md +++ b/docs.md @@ -4051,6 +4051,55 @@ metrics counters. - `events` : `integer` - `events_waiting` : `integer` +## String manipulation functions + +These string utilities are needed internally for dealing with Windows, and are exported to allow clients to work uniformly with this data when the libuv API is not complete. + +**Notes**: + +1. New in luv version 1.49.0. +2. A UTF-16 character is 2 bytes, and a UTF-8 character is 1 byte. +3. Luv use Lua style string, which means that all inputs and return values (UTF-8 or UTF-16 strings) not include NUL terminated. + +### `uv.utf16_length_as_wtf8()` + +Get the length of a UTF-16 (or UCS-2) string `utf16` value after converting it to WTF-8. + +**Parameters:** +- `utf16`: `string` +- `len`: `integer` or `nil` (default: `#utf16/2`) + +**Returns:** `integer` + +### `uv.utf16_to_wtf8()` + +Convert UTF-16 (or UCS-2) string `utf16` to UTF-8 string. The `len` count (in characters) +gives the length of utf16. + +**Parameters:** +- `utf16`: `string` +- `len`: `integer` or `nil` (default: `#utf16/2`) + +**Returns:** `string` + +### `uv.wtf8_length_as_utf16()` + +Get the length in characters of a WTF-8 `wtf8` value after converting it to UTF-16 (or UCS-2). + +**Parameters:** +- `wtf8`: `string` + +**Returns:** `integer` + +### `uv.wtf8_to_utf16()` + +Convert WTF-8 string in `wtf8` to UTF-16 (or UCS-2) string. + +**Parameters:** +- `wtf8`: `string` + +**Returns:** `string` + --- [luv]: https://github.com/luvit/luv