eina: extend eina_str_escape to escape more common case.
authorMykyta Biliavskyi <m.biliavskyi@samsung.net>
Fri, 13 Mar 2015 07:15:57 +0000 (08:15 +0100)
committerCedric BAIL <cedric@osg.samsung.com>
Fri, 13 Mar 2015 08:33:28 +0000 (09:33 +0100)
Summary: Added new symbols, that will be escaped. There are '\"', '\t' and '\n'.

Reviewers: raster, cedric

Reviewed By: cedric

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D2130

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/lib/eina/eina_str.c
src/lib/eina/eina_str.h

index e1445f2..cec1f78 100644 (file)
@@ -629,12 +629,32 @@ eina_str_escape(const char *str)
 
    for (s = str, d = s2; *s != 0; s++, d++)
      {
-        if ((*s == ' ') || (*s == '\\') || (*s == '\''))
-          {
+        switch (*s)
+        {
+         case ' ':
+         case '\\':
+         case '\'':
+         case '\"':
+           {
              *d = '\\';
              d++;
-          }
-
+             break;
+           }
+         case '\n':
+           {
+             *d = '\\'; d++;
+             *d = 'n'; d++;
+             s++;
+             break;
+           }
+         case '\t':
+           {
+             *d = '\\'; d++;
+             *d = 't'; d++;
+             s++;
+             break;
+           }
+        }
         *d = *s;
      }
    *d = 0;
index f3e9f9f..100cc81 100644 (file)
@@ -293,9 +293,10 @@ EAPI char           *eina_str_convert_len(const char *enc_from, const char *enc_
  * @param str The string to escape.
  * @return The escaped string.
  *
- * Escaping is done by adding a slash "\" before any occurrence of slashes "\",
- * spaces " " or apostrophes "'". This function returns a newly allocated
- * escaped string on success, @c NULL on failure. When not used anymore, the
+ * Escaping is done by adding a slash "\" before any occurrence of slashes "\"
+ * include '\n' and '\t', spaces " ", apostrophes "'" or quotes """. This
+ * function returns a newly allocated escaped string on success, @c NULL on
+ * failure. When not used anymore, the
  * returned value must be freed.
  */
 EAPI char           *eina_str_escape(const char *str) EINA_WARN_UNUSED_RESULT EINA_MALLOC EINA_ARG_NONNULL(1);