[hackers] [[dwm][PATCH]] drw / utf8decode : simpler is better ?

From: nenesses <la.luge_AT_free.fr>
Date: Tue, 19 Jul 2022 16:38:34 +0200

---
 drw.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/drw.c b/drw.c
index ced7d37..b6073a4 100644
--- a/drw.c
+++ b/drw.c
_AT_@ -25,16 +25,6 @@ utf8decodebyte(const char c, size_t *i)
 	return 0;
 }
 
-static size_t
-utf8validate(long *u, size_t i)
-{
-	if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
-		*u = UTF_INVALID;
-	for (i = 1; *u > utfmax[i]; ++i)
-		;
-	return i;
-}
-
 static size_t
 utf8decode(const char *c, long *u, size_t clen)
 {
_AT_@ -54,8 +44,9 @@ utf8decode(const char *c, long *u, size_t clen)
 	}
 	if (j < len)
 		return 0;
-	*u = udecoded;
-	utf8validate(u, len);
+
+	*u = (!BETWEEN(udecoded, utfmin[i], utfmax[i]) || BETWEEN(udecoded, 0xD800, 0xDFFF))
+		? UTF_INVALID : udecoded;
 
 	return len;
 }
-- 
2.30.2
Received on Tue Jul 19 2022 - 16:38:34 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 19 2022 - 16:48:30 CEST