You mean something like this?
GeSHi (cpp):
// everything else as it was
cout << regex_replace( indata, escseq, "\\x$1");
Created by GeSHI 1.0.7.18
I'm not sure you can replace the matched char with it's ascii value just using strings. The xpressive
string substitution page suggests that this would be more inline with what you want:
GeSHi (cpp):
#include <boost/xpressive/regex_constants.hpp>
#include <iostream>
#include <sstream>
using namespace std;
using namespace boost::xpressive;
std::string escaper(const smatch &what)
{
std::stringstream stream("\\x");
stream << std::hex << (int)what[1].str()[0];
return stream.str();
}
int main()
{
string indata="\x42\x01\x20\x21\x02\x03-";
sregex escseq = sregex::compile("([^\\x20-\\x7D])");
cout << regex_replace( indata, escseq, escaper);
cin.get();
return 0;
}
Created by GeSHI 1.0.7.18
But I don't have 1.36 installed at the mo so I can't test it