I have been looking around for a solution to escape single quotes in a std::string, without finding a clean way to do it.
This post gives few solutions like this one:
std::wstring regex_escape(const std::wstring& string_to_escape) {
static const boost::wregex re_boostRegexEscape( _T("[\\^\\.\\$\\|\\(\\)\\[\\]\\*\\+\\?\\/\\\\]") );
const std::wstring rep( _T("\\\\\\1&") );
std::wstring result = regex_replace(string_to_escape, re_boostRegexEscape, rep, boost::match_default | boost::format_sed);
return result;
}
Quite cool but too complicated for my requirement. Is there an easier, more understandable (and standard) way to solve this problem (without hitting performance)?
Note: maybe I am finding the above too compicated because I don't really understand what this line is doing: const std::wstring rep( _T("\\\\\\1&") )