pub fn parse_string(s: &str) -> Result<String, ParseSequenceError>
Expand description
Parse the provided quoted string. This function was adopted from snailquote.
§Details
Parses a single or double quoted string and interprets escape sequences such as ‘\n’, ‘\r’, ‘'’, etc.
Supports raw strings prefixed with r
or R
in which case all escape sequences are ignored.///
The full set of supported escapes between quotes may be found below:
Escape | Code | Description |
---|---|---|
\a | 0x07 | Bell |
\b | 0x08 | Backspace |
\v | 0x0B | Vertical tab |
\f | 0x0C | Form feed |
\n | 0x0A | Newline |
\r | 0x0D | Carriage return |
\t | 0x09 | Tab |
\ | 0x5C | Backslash |
? | 0x?? | Question mark |
" | 0x22 | Double quote |
' | 0x27 | Single quote |
` | 0x60 | Backtick |
\xDD | 0xDD | Unicode character with hex code DD |
\uDDDD | 0xDDDD | Unicode character with hex code DDDD |
\UDDDDDDDD | 0xDDDDDDDD | Unicode character with hex code DDDDDDDD |
\DDD | 0DDD | Unicode character with octal code DDD |
§Errors
The returned result can display a human readable error if the string cannot be parsed as a valid quoted string.