Last active
December 16, 2015 11:28
-
-
Save fstamour/5427061 to your computer and use it in GitHub Desktop.
A simple helper function to handle escapes in parsing, you may choose the kind of error handling you want (by return value or by exception) and it is really easily converted to C.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#include <stdexcept> | |
/// @warning The parameter is also the return value. | |
/// @return true if the escape sequence was valid, false otherwise | |
bool escapeChar( char& c ) { | |
switch( c ) { | |
case 't': | |
c = '\t'; | |
break; | |
case 'n': | |
c = '\n'; | |
break; | |
case '\n': | |
return true; | |
case ' ': | |
case '\\': | |
case '"': | |
break; | |
default: | |
//throw std::runtime_error("Undefined escape sequence."); | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment