summaryrefslogtreecommitdiffstats
path: root/lib/mbsalign.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/mbsalign.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/mbsalign.c b/lib/mbsalign.c
index 7b8f5a6..b4ab7be 100644
--- a/lib/mbsalign.c
+++ b/lib/mbsalign.c
@@ -310,12 +310,33 @@ char *mbs_invalid_encode_to_buffer(const char *s, size_t *width, char *buf)
return buf;
}
+/*
+ * Guess size
+ */
size_t mbs_safe_encode_size(size_t bytes)
{
return (bytes * 4) + 1;
}
/*
+ * Count size of the original string in bytes (count \x?? as one byte)
+ */
+size_t mbs_safe_decode_size(const char *p)
+{
+ size_t bytes = 0;
+
+ while (p && *p) {
+ if (*p == '\\' && *(p + 1) == 'x' &&
+ isxdigit(*(p + 2)) && isxdigit(*(p + 3)))
+ p += 4;
+ else
+ p++;
+ bytes++;
+ }
+ return bytes;
+}
+
+/*
* Returns allocated string where all control and non-printable chars are
* replaced with \x?? hex sequence.
*/