Skip to content

Commit

Permalink
doc: add String manipulation functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaozg committed Oct 10, 2024
1 parent 6e1a437 commit 29aee6f
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29aee6f

Please sign in to comment.