[hackers] [lchat] use libgrapheme instead of libutf || Jan Klemkow
 
commit dbc8751dc6c034967d2b3133a58a627834992e8c
Author:     Jan Klemkow <j.klemkow_AT_wemelug.de>
AuthorDate: Sun Oct 2 00:59:19 2022 +0200
Commit:     Jan Klemkow <j.klemkow_AT_wemelug.de>
CommitDate: Sun Oct 2 01:00:03 2022 +0200
    use libgrapheme instead of libutf
diff --git a/config.mk b/config.mk
index 8315b62..15f86cc 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -9,7 +9,7 @@ CFLAGS = -std=c99 -pedantic -Wall -Wextra -g
 
 # utf.h
 CFLAGS += -I/usr/local/include
-LIBS = -L/usr/local/lib -lutf
+LIBS = -L/usr/local/lib -lgrapheme
 
 # For sbase users:
 #CFLAGS += -I../sbase
diff --git a/slackline.c b/slackline.c
index 0dc1f8e..d93fe7a 100644
--- a/slackline.c
+++ b/slackline.c
_AT_@ -19,7 +19,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <utf.h>
+#include <grapheme.h>
 
 #include "slackline.h"
 
_AT_@ -74,15 +74,8 @@ sl_postobyte(struct slackline *sl, size_t pos)
         char *ptr = &sl->buf[0];
         size_t byte = 0;
 
-	for (;pos > 0; pos--) {
-		for (size_t i = 0;; i++) {
-			if (fullrune(ptr, i) == 1) {
-				ptr += i;
-				byte += i;
-				break;
-			}
-		}
-	}
+	for (;pos > 0; pos--)
+		byte += grapheme_next_character_break(ptr+byte, sl->blen-byte);
 
         return byte;
 }
_AT_@ -90,18 +83,7 @@ sl_postobyte(struct slackline *sl, size_t pos)
 static char *
 sl_postoptr(struct slackline *sl, size_t pos)
 {
-	char *ptr = &sl->buf[0];
-
-	for (;pos > 0; pos--) {
-		for (size_t i = 0;; i++) {
-			if (fullrune(ptr, i) == 1) {
-				ptr += i;
-				break;
-			}
-		}
-	}
-
-	return ptr;
+	return &sl->buf[sl_postobyte(sl, pos)];
 }
 
 static void
_AT_@ -131,6 +113,8 @@ sl_backspace(struct slackline *sl)
 int
 sl_keystroke(struct slackline *sl, int key)
 {
+	uint_least32_t cp;
+
         if (sl == NULL || sl->rlen < sl->rcur)
                 return -1;
 
_AT_@ -245,7 +229,8 @@ sl_keystroke(struct slackline *sl, int key)
 compose:
         /* byte-wise composing of UTF-8 runes */
         sl->ubuf[sl->ubuf_len++] = key;
-	if (fullrune(sl->ubuf, sl->ubuf_len) == 0)
+	if (grapheme_decode_utf8(sl->ubuf, sl->ubuf_len, &cp) > sl->ubuf_len ||
+	    cp == GRAPHEME_INVALID_CODEPOINT)
                 return 0;
 
         if (sl->blen + sl->ubuf_len >= sl->bufsize) {
Received on Sun Oct 02 2022 - 02:01:34 CEST
This archive was generated by hypermail 2.3.0
: Sun Oct 02 2022 - 02:12:36 CEST