Escape Sequences in Nu Strings
With Nu-0.2.0, Nu now supports character escape sequences in strings.
Supported sequences
These escape sequences are supported:
\n | newline (0x0a) |
\r | carriage return (0x0d) |
\f | formfeed (0x0c) |
\b | backspace (0x08) |
\a | bell (0x07) |
\e | escape (0x1b) |
\s | space (0x20) |
\nnn | octal byte |
\xnn | hexadecimal byte |
\unnnn | unicode character (16 bits) |
\x | character x |
Controlling escaping
Escape sequences are supported in both double-quoted and here strings. Double-quoted strings are escaped by default. For example, "foo\nbar"
is parsed as a seven-character string with a newline in the middle.
Strings that are prefixed with a minus sign (-) explicitly
disable escaping. For example, -"foo\nbar"
is parsed as an eight character string with a slash and 'n' in the middle.
Strings that are prefixed with a plus sign (+) explicitly
enable escaping. For example, +"foo\nbar"
is parsed as a seven-character string with a newline in the middle.
Here strings that begin with the "<<-" notation explicitly disable escaping. The following example shows an unescaped string:
(set x <<-END foo\nbarEND)
Here strings that begin with the new "<<+" notation explicitly enable escaping. The following example shows an escaped string:
(set x <<+END foo\nbarEND)
There is no ambiguous form for here strings.
Unsupported sequences
These sequences were considered but are currently not supported:
\cx, \C-x | control-x |
\M-x | meta-x (c + 0x80) |
\M-\C-x | Meta-Control-x |