Add eina_str_escape

SVN revision: 45949
This commit is contained in:
Sebastian Dransfeld 2010-02-06 21:42:51 +00:00
parent b7e2624123
commit 72fccca0eb
2 changed files with 30 additions and 0 deletions

View File

@ -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.

View File

@ -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;
}