static bool process( std:: string & macro)
{
if ( macro == "error" )
{
return false ; // fail the parse
}
if ( macro == "hello" )
{
macro = "bye" ;
}
else if ( macro == "bye" )
{
macro = "We meet again" ;
}
else if ( macro == "sideeffect" )
{
std:: cerr << "this is a side effect while parsing\n " ;
macro = "(done)" ;
}
else if ( std:: string :: npos ! = macro.find ( '~' ) )
{
std:: reverse ( macro.begin ( ) , macro.end ( ) ) ;
macro.erase ( std:: remove ( macro.begin ( ) , macro.end ( ) , '~' ) ) ;
}
else
{
macro = std:: string ( "<<" ) + macro + ">>" ; // this makes the unsupported macros appear unchanged
}
return true ;
}
c3RhdGljIGJvb2wgcHJvY2VzcyhzdGQ6OnN0cmluZyYgbWFjcm8pCnsKICAgIGlmIChtYWNybyA9PSAiZXJyb3IiKQogICAgewogICAgICAgIHJldHVybiBmYWxzZTsgLy8gZmFpbCB0aGUgcGFyc2UKICAgIH0KCiAgICBpZiAobWFjcm8gPT0gImhlbGxvIikKICAgIHsKICAgICAgICBtYWNybyA9ICJieWUiOwogICAgfQogICAgZWxzZSBpZiAobWFjcm8gPT0gImJ5ZSIpCiAgICB7CiAgICAgICAgbWFjcm8gPSAiV2UgbWVldCBhZ2FpbiI7CiAgICB9CiAgICBlbHNlIGlmIChtYWNybyA9PSAic2lkZWVmZmVjdCIpCiAgICB7CiAgICAgICAgc3RkOjpjZXJyIDw8ICJ0aGlzIGlzIGEgc2lkZSBlZmZlY3Qgd2hpbGUgcGFyc2luZ1xuIjsKICAgICAgICBtYWNybyA9ICIoZG9uZSkiOwogICAgfQogICAgZWxzZSBpZiAoc3RkOjpzdHJpbmc6Om5wb3MgIT0gbWFjcm8uZmluZCgnficpKQogICAgewogICAgICAgIHN0ZDo6cmV2ZXJzZShtYWNyby5iZWdpbigpLCBtYWNyby5lbmQoKSk7CiAgICAgICAgbWFjcm8uZXJhc2Uoc3RkOjpyZW1vdmUobWFjcm8uYmVnaW4oKSwgbWFjcm8uZW5kKCksICd+JykpOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgIG1hY3JvID0gc3RkOjpzdHJpbmcoIjw8IikgKyBtYWNybyArICI+PiI7IC8vIHRoaXMgbWFrZXMgdGhlIHVuc3VwcG9ydGVkIG1hY3JvcyBhcHBlYXIgdW5jaGFuZ2VkCiAgICB9CgogICAgcmV0dXJuIHRydWU7Cn0K
compilation info
prog.cpp:1: error: ‘string’ is not a member of ‘std’
prog.cpp:1: error: ‘macro’ was not declared in this scope
prog.cpp:2: error: expected ‘,’ or ‘;’ before ‘{’ token
prog.cpp:1: warning: ‘process’ defined but not used
stdout