forked from enlightenment/efl
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 <cedric@osg.samsung.com>
This commit is contained in:
parent
65d0c2a1e1
commit
37c58d4397
|
@ -629,12 +629,32 @@ eina_str_escape(const char *str)
|
||||||
|
|
||||||
for (s = str, d = s2; *s != 0; s++, d++)
|
for (s = str, d = s2; *s != 0; s++, d++)
|
||||||
{
|
{
|
||||||
if ((*s == ' ') || (*s == '\\') || (*s == '\''))
|
switch (*s)
|
||||||
{
|
{
|
||||||
|
case ' ':
|
||||||
|
case '\\':
|
||||||
|
case '\'':
|
||||||
|
case '\"':
|
||||||
|
{
|
||||||
*d = '\\';
|
*d = '\\';
|
||||||
d++;
|
d++;
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
case '\n':
|
||||||
|
{
|
||||||
|
*d = '\\'; d++;
|
||||||
|
*d = 'n'; d++;
|
||||||
|
s++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '\t':
|
||||||
|
{
|
||||||
|
*d = '\\'; d++;
|
||||||
|
*d = 't'; d++;
|
||||||
|
s++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
*d = *s;
|
*d = *s;
|
||||||
}
|
}
|
||||||
*d = 0;
|
*d = 0;
|
||||||
|
|
|
@ -293,9 +293,10 @@ EAPI char *eina_str_convert_len(const char *enc_from, const char *enc_
|
||||||
* @param str The string to escape.
|
* @param str The string to escape.
|
||||||
* @return The escaped string.
|
* @return The escaped string.
|
||||||
*
|
*
|
||||||
* Escaping is done by adding a slash "\" before any occurrence of slashes "\",
|
* Escaping is done by adding a slash "\" before any occurrence of slashes "\"
|
||||||
* spaces " " or apostrophes "'". This function returns a newly allocated
|
* include '\n' and '\t', spaces " ", apostrophes "'" or quotes """. This
|
||||||
* escaped string on success, @c NULL on failure. When not used anymore, the
|
* function returns a newly allocated escaped string on success, @c NULL on
|
||||||
|
* failure. When not used anymore, the
|
||||||
* returned value must be freed.
|
* returned value must be freed.
|
||||||
*/
|
*/
|
||||||
EAPI char *eina_str_escape(const char *str) EINA_WARN_UNUSED_RESULT EINA_MALLOC EINA_ARG_NONNULL(1);
|
EAPI char *eina_str_escape(const char *str) EINA_WARN_UNUSED_RESULT EINA_MALLOC EINA_ARG_NONNULL(1);
|
||||||
|
|
Loading…
Reference in New Issue