git-svn-id: https://klish.googlecode.com/svn/trunk@197 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
@@ -0,0 +1,56 @@
+/*
+ * string_escape.c
+ */
+#include "private.h"
+
+#include <stdlib.h>
+#include <string.h>
+/*--------------------------------------------------------- */
+char *
+lub_string_decode(const char *string)
+{
+ const char *s = string;
+ char *res, *p;
+ int esc = 0;
+ if (!string)
+ return NULL;
+ /* Allocate enough memory for result */
+ p = res = malloc(strlen(string) + 1);
+ while (*s) {
+ if (!esc) {
+ if ('\\' == *s)
+ esc = 1;
+ else
+ *p = *s;
+ } else {
+ switch (*s) {
+ case 'r':
+ case 'n':
+ *p = '\n';
+ break;
+ case 't':
+ *p = '\t';
+ default:
+ }
+ esc = 0;
+ if (!esc)
+ p++;
+ s++;
+ *p = '\0';
+ /* Optimize the memory allocated for result */
+ p = lub_string_dup(res);
+ free(res);
+ return p;
+}