changeset 20339:327fcf6d2205

lib: Added t_str_tabunescape()
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 06 May 2016 17:24:42 +0300
parents 2a05c653d223
children 0788113759af
files src/lib/strescape.c src/lib/strescape.h src/lib/test-strescape.c
diffstat 3 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/strescape.c	Mon Jun 20 02:25:47 2016 +0300
+++ b/src/lib/strescape.c	Fri May 06 17:24:42 2016 +0300
@@ -226,6 +226,14 @@
 	return start;
 }
 
+const char *t_str_tabunescape(const char *str)
+{
+	if (strchr(str, '\001') == NULL)
+		return str;
+	else
+		return str_tabunescape(t_strdup_noconst(str));
+}
+
 char **p_strsplit_tabescaped(pool_t pool, const char *str)
 {
 	char **args;
--- a/src/lib/strescape.h	Mon Jun 20 02:25:47 2016 +0300
+++ b/src/lib/strescape.h	Fri May 06 17:24:42 2016 +0300
@@ -23,6 +23,7 @@
 void str_append_tabescaped(string_t *dest, const char *src);
 void str_append_tabunescaped(string_t *dest, const void *src, size_t src_size);
 char *str_tabunescape(char *str);
+const char *t_str_tabunescape(const char *str);
 
 char **p_strsplit_tabescaped(pool_t pool, const char *str);
 const char *const *t_strsplit_tabescaped(const char *str);
--- a/src/lib/test-strescape.c	Mon Jun 20 02:25:47 2016 +0300
+++ b/src/lib/test-strescape.c	Fri May 06 17:24:42 2016 +0300
@@ -70,6 +70,8 @@
 
 	test_begin("str_tabescape");
 	for (i = 0; i < N_ELEMENTS(tabesc); i++) {
+		test_assert(strcmp(t_str_tabunescape(tabesc[i].output),
+				   tabesc[i].input) == 0);
 		test_assert(strcmp(str_tabunescape(t_strdup_noconst(tabesc[i].output)),
 				   tabesc[i].input) == 0);
 		test_assert(strcmp(str_tabescape(tabesc[i].input),