summaryrefslogtreecommitdiffstats
path: root/utf8.c
diff options
context:
space:
mode:
authornicm <nicm>2017-01-18 10:08:05 +0000
committernicm <nicm>2017-01-18 10:08:05 +0000
commitfaa05703091de29e5af06777513acd7a562433ba (patch)
tree7bea105a348664aa15078a726c914819d5059adb /utf8.c
parent4bb5a1d6a7d1cbf2aa3647afeab270f1afa5d4a7 (diff)
Plain stravis() because it will mangle UTF-8 characters, so add
utf8_stravis() which calls our existing utf8_strvis() and use it instead
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/utf8.c b/utf8.c
index 5ab2127a..ea8c99a2 100644
--- a/utf8.c
+++ b/utf8.c
@@ -193,6 +193,20 @@ utf8_strvis(char *dst, const char *src, size_t len, int flag)
return (dst - start);
}
+/* Same as utf8_strvis but allocate the buffer. */
+int
+utf8_stravis(char **dst, const char *src, int flag)
+{
+ char *buf;
+ int len;
+
+ buf = xreallocarray(NULL, 4, strlen(src) + 1);
+ len = utf8_strvis(buf, src, strlen(src), flag);
+
+ *dst = xrealloc(buf, len + 1);
+ return (len);
+}
+
/*
* Sanitize a string, changing any UTF-8 characters to '_'. Caller should free
* the returned string. Anything not valid printable ASCII or UTF-8 is