util: Added ::escape

This commit is contained in:
Paul Beckingham 2016-03-20 14:08:28 -04:00
parent b83d3f0ace
commit cbd3ea3c0d
2 changed files with 24 additions and 0 deletions

View file

@ -56,3 +56,26 @@ std::string osName ()
}
////////////////////////////////////////////////////////////////////////////////
// Escape all 'c' --> '\c'.
std::string escape (const std::string& input, int c)
{
std::string output;
auto last = input.begin ();
for (auto i = input.begin (); i != input.end (); ++i)
{
if (*i == c)
{
output.append (last, i);
output += std::string ("\\") + *i;
last = i + 1;
}
// Default NOP.
}
output.append (last, input.end ());
return output;
}
////////////////////////////////////////////////////////////////////////////////