mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
util: Added ::escape
This commit is contained in:
parent
b83d3f0ace
commit
cbd3ea3c0d
2 changed files with 24 additions and 0 deletions
23
src/util.cpp
23
src/util.cpp
|
@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue