commit ea9a8f549939e0f69dd40293161d6fc3f5891291
Author: Laslo Hunhold <[email protected]>
Date:   Thu Oct 6 22:37:42 2022 +0200

    Update code example
    
    Signed-off-by: Laslo Hunhold <[email protected]>

diff --git a/libs.suckless.org/libgrapheme/index.md 
b/libs.suckless.org/libgrapheme/index.md
index a868743f..d5cb59a7 100644
--- 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\"
", s);
        
+               /* print each grapheme cluster with byte-length */
+               printf("grapheme clusters in NUL-delimited input:
");
                for (off = 0; s[off] != '                       ret = 
grapheme_next_character_break_utf8(s + off, SIZE_MAX);
                        printf("%2zu bytes | %.*s
", ret, (int)ret, s + off, ret);
                }
+               printf("
");
+       
+               /* do the same, but this time string is length-delimited */
+               len = 17;
+               printf("grapheme clusters in input delimited to %zu bytes:
", len);
+               for (off = 0; off < len; off += ret) {
+                       ret = grapheme_next_character_break_utf8(s + off, len - 
off);
+                       printf("%2zu bytes | %.*s
", 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 ([email protected])
 
-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.


Reply via email to