Skip to content
Snippets Groups Projects
Commit 4d2b5818 authored by Sebastien Barre's avatar Sebastien Barre
Browse files

ENH: add method to escape some chars in a string

parent 895f7c11
No related branches found
No related tags found
No related merge requests found
......@@ -1205,6 +1205,41 @@ int SystemTools::EstimateFormatLength(const char *format, va_list ap)
return length;
}
kwsys_stl::string SystemTools::EscapeChars(
const char *str,
const char *chars_to_escape,
char escape_char)
{
kwsys_stl::string n;
if (str)
{
if (!chars_to_escape | !*chars_to_escape)
{
n.append(str);
}
else
{
n.reserve(strlen(str));
while (*str)
{
const char *ptr = chars_to_escape;
while (*ptr)
{
if (*str == *ptr)
{
n += escape_char;
break;
}
++ptr;
}
n += *str;
++str;
}
}
}
return n;
}
// convert windows slashes to unix slashes
void SystemTools::ConvertToUnixSlashes(kwsys_stl::string& path)
{
......
......@@ -220,6 +220,12 @@ public:
*/
static int EstimateFormatLength(const char *format, va_list ap);
/**
* Escape specific characters in 'str'.
*/
static kwsys_stl::string EscapeChars(
const char *str, const char *chars_to_escape, char escape_char = '\\');
/** -----------------------------------------------------------------
* Filename Manipulation Routines
* -----------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment