diff --git a/src/timew.h b/src/timew.h index 60363445..376f4bf9 100644 --- a/src/timew.h +++ b/src/timew.h @@ -40,5 +40,6 @@ int dispatchCommand (const std::vector &, Database&, Rules&, Extens // utiƀ.cpp std::string osName (); +std::string escape (const std::string&, int); #endif diff --git a/src/util.cpp b/src/util.cpp index 5a62c152..f07760eb 100644 --- a/src/util.cpp +++ b/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; +} + +////////////////////////////////////////////////////////////////////////////////