cedric pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=37c58d4397dfc3e62fef324ef932d704d55bcf33
commit 37c58d4397dfc3e62fef324ef932d704d55bcf33 Author: Mykyta Biliavskyi <m.biliavs...@samsung.net> Date: Fri Mar 13 08:15:57 2015 +0100 eina: extend eina_str_escape to escape more common case. 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 <ced...@osg.samsung.com> --- src/lib/eina/eina_str.c | 28 ++++++++++++++++++++++++---- src/lib/eina/eina_str.h | 7 ++++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/lib/eina/eina_str.c b/src/lib/eina/eina_str.c index e1445f2..cec1f78 100644 --- a/src/lib/eina/eina_str.c +++ b/src/lib/eina/eina_str.c @@ -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; diff --git a/src/lib/eina/eina_str.h b/src/lib/eina/eina_str.h index f3e9f9f..100cc81 100644 --- a/src/lib/eina/eina_str.h +++ b/src/lib/eina/eina_str.h @@ -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); --