ztcl::text
ztcl::text subcommand ?arg ...?
Cuts a string into grapheme clusters, words, or sentences by the rules of Unicode 18.0.0 (UAX #29), and gives its display width in columns (UAX #11 and UTS #51). Load it with package require ztcl::text.
This page also has ztcl::text::graphemes, ztcl::text::words, ztcl::text::sentences, ztcl::text::width, ztcl::text::bounds.
Subcommands
| Synopsis | What it does |
|---|---|
graphemes STRING |
The list of the grapheme clusters: the characters that a user sees, such as an emoji with a skin tone or a letter with accents. |
words ?-all? STRING |
The list of the word segments that have a letter or a number. With -all, each segment, so join of the list gives the string again. |
sentences STRING |
The list of the sentences, each with its spaces and line end. |
| `width ?-ambiguous narrow | wide? STRING` |
| `bounds ?-unit grapheme | word |
Examples
A click on an example runs it in the shell of the page.
package require ztcl::textllength [ztcl::text graphemes "e\u0301\U1F44D\U1F3FD"]:2ztcl::text words "Hello, world.":Hello worldztcl::text width "\u4E2D\u6587 ok":7ztcl::text bounds "ab\u0301c":0 1 3 4
Facts
- Capability: none.
- Compute cost: One compute unit for each 4,096 bytes of the string.
- The full page: ztcl::text.