summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/escape.c16
-rw-r--r--src/basic/escape.h1
2 files changed, 12 insertions, 5 deletions
diff --git a/src/basic/escape.c b/src/basic/escape.c
index 4815161b09..42a84c9317 100644
--- a/src/basic/escape.c
+++ b/src/basic/escape.c
@@ -89,20 +89,20 @@ size_t cescape_char(char c, char *buf) {
return buf - buf_old;
}
-char *cescape(const char *s) {
- char *r, *t;
+char *cescape_length(const char *s, size_t n) {
const char *f;
+ char *r, *t;
- assert(s);
+ assert(s || n == 0);
/* Does C style string escaping. May be reversed with
* cunescape(). */
- r = new(char, strlen(s)*4 + 1);
+ r = new(char, n*4 + 1);
if (!r)
return NULL;
- for (f = s, t = r; *f; f++)
+ for (f = s, t = r; f < s + n; f++)
t += cescape_char(*f, t);
*t = 0;
@@ -110,6 +110,12 @@ char *cescape(const char *s) {
return r;
}
+char *cescape(const char *s) {
+ assert(s);
+
+ return cescape_length(s, strlen(s));
+}
+
int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_unicode) {
int r = 1;
diff --git a/src/basic/escape.h b/src/basic/escape.h
index 30604c58f9..52ebf11c4a 100644
--- a/src/basic/escape.h
+++ b/src/basic/escape.h
@@ -35,6 +35,7 @@ typedef enum UnescapeFlags {
} UnescapeFlags;
char *cescape(const char *s);
+char *cescape_length(const char *s, size_t n);
size_t cescape_char(char c, char *buf);
int cunescape(const char *s, UnescapeFlags flags, char **ret);