forked from enlightenment/efl
parent
b7e2624123
commit
72fccca0eb
|
@ -27,6 +27,8 @@ EAPI size_t eina_str_join_len(char *dst, size_t size, char sep, const char *a, s
|
|||
|
||||
EAPI char *eina_str_convert(const char *enc_from, const char *enc_to, const char *text);
|
||||
|
||||
EAPI char *eina_str_escape(const char *str);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Join two strings of known length.
|
||||
|
|
|
@ -421,3 +421,31 @@ eina_str_convert(const char *enc_from, const char *enc_to, const char *text)
|
|||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Put a \ before and Space( ), \ or ' in a string.
|
||||
*
|
||||
* @param str the string to escape
|
||||
*
|
||||
* A newly allocated string is returned.
|
||||
*/
|
||||
EAPI char *
|
||||
eina_str_escape(const char *str)
|
||||
{
|
||||
char *s2, *d;
|
||||
const char *s;
|
||||
|
||||
s2 = malloc((strlen(str) * 2) + 1);
|
||||
if (!s2) return NULL;
|
||||
for (s = str, d = s2; *s != 0; s++, d++)
|
||||
{
|
||||
if ((*s == ' ') || (*s == '\\') || (*s == '\''))
|
||||
{
|
||||
*d = '\\';
|
||||
d++;
|
||||
}
|
||||
*d = *s;
|
||||
}
|
||||
*d = 0;
|
||||
return s2;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue