![]() |
General Utility Library for C++14
2.13
|
Escaping and unescaping special characters in strings.
Functions | |
| GUL_EXPORT std::string | gul14::escape (string_view in) |
| Create a new string that looks like an ASCII-only C string literal of the input string. More... | |
| GUL_EXPORT std::string | gul14::unescape (string_view in) |
| Evaluate a string with escaped characters to get the original string back. More... | |
| GUL_EXPORT std::string gul14::escape | ( | string_view | in | ) |
Create a new string that looks like an ASCII-only C string literal of the input string.
This is achieved by replacing all non-printable and non-ASCII characters with a hex code escape in the form \x01.
A few special cases are implemented to give more readable representations for very common control characters, and of course backslash and double quotes are escaped as well:
CR -> \r NL -> \n TAB -> \t \ -> \\ " -> \"
Output (assuming that the string literal was in Latin-1 encoding):
Zwei\tFl\xfcsse\nflie\xdfen ins Meer.
"\x200" is invalid and not equal to " 0" from the standard's point of view.| in | The input string. |
| GUL_EXPORT std::string gul14::unescape | ( | string_view | in | ) |
Evaluate a string with escaped characters to get the original string back.
Does only know the escape sequences used by gul14::escape() and can be used as in inverse function.
| in | The string with escape sequences |