summaryrefslogtreecommitdiffstats
path: root/utf8.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2016-10-12 09:45:49 +0100
committerThomas Adam <thomas@xteddy.org>2016-10-12 09:45:49 +0100
commitb9dc855016cf79c8bb8469c272dbc6bca24deadc (patch)
treea2049bea7b17ededbd12b77110d47353ed832e46 /utf8.c
parent27126f87976c63161fcae2ab1eb9c6df726a84ff (diff)
parent5c49e1d0c1afaf98512b2ffd1f31d91fecff9851 (diff)
Merge branch 'obsd-master'
Conflicts: format.c osdep-openbsd.c
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/utf8.c b/utf8.c
index eb9b47a9..9d3f8735 100644
--- a/utf8.c
+++ b/utf8.c
@@ -261,6 +261,33 @@ utf8_sanitize(const char *src)
return (dst);
}
+/* Get UTF-8 buffer length. */
+size_t
+utf8_strlen(const struct utf8_data *s)
+{
+ size_t i;
+
+ for (i = 0; s[i].size != 0; i++)
+ /* nothing */;
+ return (i);
+}
+
+/* Get UTF-8 string width. */
+u_int
+utf8_strwidth(const struct utf8_data *s, ssize_t n)
+{
+ ssize_t i;
+ u_int width;
+
+ width = 0;
+ for (i = 0; s[i].size != 0; i++) {
+ if (n != -1 && n == i)
+ break;
+ width += s[i].width;
+ }
+ return (width);
+}
+
/*
* Convert a string into a buffer of UTF-8 characters. Terminated by size == 0.
* Caller frees.