summaryrefslogtreecommitdiffstats
path: root/utf8.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2023-09-19 09:29:04 +0100
committerNicholas Marriott <nicholas.marriott@gmail.com>2023-09-19 09:29:04 +0100
commit51b80b985e0a14c904100a20b72c1a3ada946577 (patch)
treedb6596b09fb2a539346a643ce3885b68f311cdc3 /utf8.c
parent789a98982eac63a02bb06fbd07a010fc2eec0e92 (diff)
Restore utf8proc code.
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/utf8.c b/utf8.c
index ece1bb7e..5053e459 100644
--- a/utf8.c
+++ b/utf8.c
@@ -409,6 +409,10 @@ utf8_width(struct utf8_data *ud, int *width)
*width = 2;
return (UTF8_DONE);
}
+#ifdef HAVE_UTF8PROC
+ *width = utf8proc_wcwidth(wc);
+ log_debug("utf8proc_wcwidth(%05X) returned %d", (u_int)wc, *width);
+#else
*width = wcwidth(wc);
log_debug("wcwidth(%05X) returned %d", (u_int)wc, *width);
if (*width < 0) {
@@ -418,6 +422,7 @@ utf8_width(struct utf8_data *ud, int *width)
*/
*width = (wc >= 0x80 && wc <= 0x9f) ? 0 : 1;
}
+#endif
if (*width >= 0 && *width <= 0xff)
return (UTF8_DONE);
return (UTF8_ERROR);
@@ -427,7 +432,11 @@ utf8_width(struct utf8_data *ud, int *width)
enum utf8_state
utf8_towc(const struct utf8_data *ud, wchar_t *wc)
{
+#ifdef HAVE_UTF8PROC
+ switch (utf8proc_mbtowc(wc, ud->data, ud->size)) {
+#else
switch (mbtowc(wc, ud->data, ud->size)) {
+#endif
case -1:
log_debug("UTF-8 %.*s, mbtowc() %d", (int)ud->size, ud->data,
errno);