Here's the dup: Convert string with explicit escape sequence into relative character
How do I write the fixup()
function (below) to make the assertion pass? I would like this to be generalized so that it can handle arbitrary strings which may contain any standard escape sequence.
I'm hoping that there's a simple solution, using standard functions.
/*BINFMTCXX: -Wall -Werror
*/
#include <string>
#include <cassert>
#include <iostream>
using std::string; using std::cerr;
string fixup( string input ) { return input; }
int main()
{
string target="\101";
string input="\\101";
string actual=fixup(input);
cerr<<"target=["<<target<<"], input=["<<input<<"], actual=["<<actual<<"]\n";
assert( actual == target );
}
Current output:
target=[A], input=[\101], actual=[\101]
int main(): Assertion `actual == target' failed.
Desired output:
target=[A], input=[\101], actual=[A]