libgrapheme

Freestanding C library for unicode string handling
git clone https://git.sinitax.com/suckless/libgrapheme
Log | Files | Refs | README | LICENSE | sfeed.txt

commit 21f9067a0574ebed57d70f39f359e92d9990d3e9
parent 7353c6fb372b4bf7d22f62a0decf911be2653761
Author: Laslo Hunhold <dev@frign.de>
Date:   Tue, 31 Mar 2020 12:41:49 +0200

Include example in grapheme_len(3) manpage

Based on a patch by Ivan Tham, but using the original example.

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

Diffstat:
Mman/grapheme_len.3 | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/man/grapheme_len.3 b/man/grapheme_len.3 @@ -12,6 +12,28 @@ .Nm returns the length (in bytes) of the grapheme cluster beginning at the provided char-address. +.Sh EXAMPLES +.Bd -literal +/* cc (-static) -o example example.c -lgrapheme */ +#include <grapheme.h> +#include <stdio.h> + +int +main(void) +{ + char *s = "Tëst 👨\\u200d👩\\u200d👦 🇺🇸 नी நி!"; + size_t len; + + /* print each grapheme cluster with accompanying byte-length */ + while (*s != '\\0') { + len = grapheme_len(s); + printf("%2zu bytes | %.*s\\n", len, (int)len, s, len); + s += len; + } + + return 0; +} +.Ed .Sh SEE ALSO .Xr libgrapheme 7 .Sh AUTHORS