summaryrefslogtreecommitdiff
path: root/src/dged/utf8.c
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2023-06-01 00:18:08 +0200
committerAlbert Cervin <albert@acervin.com>2023-06-01 00:18:08 +0200
commitbc5696e5bbd4739691f53563f3506b30b9be1ad3 (patch)
treebea29a74ba35e1c7da1acb2087d9648d82718335 /src/dged/utf8.c
parentf2614efe03e04575e1b9ded663a553557452c7ae (diff)
downloaddged-bc5696e5bbd4739691f53563f3506b30b9be1ad3.tar.gz
dged-bc5696e5bbd4739691f53563f3506b30b9be1ad3.tar.xz
dged-bc5696e5bbd4739691f53563f3506b30b9be1ad3.zip
Simplify rendering and prepare for props
Mark rendering is now a lot simpler and uses "properties".
Diffstat (limited to 'src/dged/utf8.c')
-rw-r--r--src/dged/utf8.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/dged/utf8.c b/src/dged/utf8.c
index abf5ef7..30344be 100644
--- a/src/dged/utf8.c
+++ b/src/dged/utf8.c
@@ -1,6 +1,7 @@
#include "utf8.h"
#include <stdio.h>
+#include <wchar.h>
bool utf8_byte_is_unicode_start(uint8_t byte) { return (byte & 0xc0) == 0xc0; }
bool utf8_byte_is_unicode_continuation(uint8_t byte) {
@@ -65,3 +66,19 @@ uint32_t utf8_nbytes(uint8_t *bytes, uint32_t nbytes, uint32_t nchars) {
return bi;
}
+
+uint32_t utf8_visual_char_width(uint8_t *bytes, uint32_t len) {
+ if (utf8_byte_is_unicode_start(*bytes)) {
+ wchar_t wc;
+ size_t nbytes = 0;
+ if (nbytes = mbrtowc(&wc, (char *)bytes, len, NULL) > 0) {
+ return wcwidth(wc);
+ } else {
+ return 0;
+ }
+ } else if (utf8_byte_is_unicode_continuation(*bytes)) {
+ return 0;
+ } else {
+ return 1;
+ }
+}