sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit ea9a8f549939e0f69dd40293161d6fc3f5891291
parent 9bbd89ed21bd73259613139f863061d83e0653d7
Author: Laslo Hunhold <dev@frign.de>
Date:   Thu,  6 Oct 2022 22:37:42 +0200

Update code example

Signed-off-by: Laslo Hunhold <dev@frign.de>

Diffstat:
Mlibs.suckless.org/libgrapheme/index.md | 25++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/libs.suckless.org/libgrapheme/index.md b/libs.suckless.org/libgrapheme/index.md @@ -78,14 +78,25 @@ into its user-perceived characters: "\x9F\x91\xA9\xE2\x80\x8D\xF0\x9F\x91\xA6 \xF0" "\x9F\x87\xBA\xF0\x9F\x87\xB8 \xE0\xA4\xA8\xE0" "\xA5\x80 \xE0\xAE\xA8\xE0\xAE\xBF!"; - size_t ret, off; + size_t ret, len, off; printf("Input: \"%s\"\n", s); + /* print each grapheme cluster with byte-length */ + printf("grapheme clusters in NUL-delimited input:\n"); for (off = 0; s[off] != '\0'; off += ret) { ret = grapheme_next_character_break_utf8(s + off, SIZE_MAX); printf("%2zu bytes | %.*s\n", ret, (int)ret, s + off, ret); } + printf("\n"); + + /* do the same, but this time string is length-delimited */ + len = 17; + printf("grapheme clusters in input delimited to %zu bytes:\n", len); + for (off = 0; off < len; off += ret) { + ret = grapheme_next_character_break_utf8(s + off, len - off); + printf("%2zu bytes | %.*s\n", ret, (int)ret, s + off, ret); + } return 0; } @@ -97,6 +108,7 @@ This code can be compiled with and the output is Input: "Tëst 👨‍👩‍👦 🇺🇸 नी நி!" + grapheme clusters in NUL-delimited input: 1 bytes | T 2 bytes | ë 1 bytes | s @@ -110,7 +122,14 @@ and the output is 1 bytes | 6 bytes | நி 1 bytes | ! - + + grapheme clusters in input delimited to 17 bytes: + 1 bytes | T + 2 bytes | ë + 1 bytes | s + 1 bytes | t + 1 bytes | + 11 bytes | 👨‍👩 Motivation ---------- @@ -154,4 +173,4 @@ Author ------ * Laslo Hunhold (dev@frign.de) -Please contact me if you find information that could be added to this page. +Please contact me if you have information that could be added to this page.