commit 21f9067a0574ebed57d70f39f359e92d9990d3e9
Author:     Laslo Hunhold <d...@frign.de>
AuthorDate: Tue Mar 31 12:41:49 2020 +0200
Commit:     Laslo Hunhold <d...@frign.de>
CommitDate: Tue Mar 31 12:41:49 2020 +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 <d...@frign.de>

diff --git a/man/grapheme_len.3 b/man/grapheme_len.3
index b7f13b7..73b500e 100644
--- 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

Reply via email to