Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 1 | [TOC](Readme.md) [Prev](numberlit.md) [Next](bytes.md) |
| 2 | |
Marcel van Lohuizen | af0932f | 2019-01-11 13:03:56 +0100 | [diff] [blame] | 3 | _JSON Sugar and other Goodness_ |
| 4 | |
Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 5 | # String Literals |
| 6 | |
Marcel van Lohuizen | 3eb3a3c | 2019-01-11 12:39:52 +0100 | [diff] [blame] | 7 | CUE strings allow a richer set of escape sequences than JSON. |
Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 8 | |
| 9 | CUE also supports multi-line strings, enclosed by a pair of triple quotes `"""`. |
| 10 | The opening quote must be followed by a newline. |
| 11 | The closing quote must also be on a newline. |
| 12 | The whitespace directly preceding the closing quote must match the preceding |
| 13 | whitespace on all other lines and is removed from these lines. |
| 14 | |
| 15 | Strings may also contain [interpolations](interpolation.md). |
| 16 | |
| 17 | <!-- CUE editor --> |
| 18 | ``` |
| 19 | // 21-bit unicode characters |
| 20 | a: "\U0001F60E" // 😎 |
| 21 | |
| 22 | // multiline strings |
| 23 | b: """ |
| 24 | Hello |
| 25 | World! |
| 26 | """ |
| 27 | ``` |
| 28 | |
| 29 | <!-- JSON result --> |
| 30 | ```json |
| 31 | { |
| 32 | a: "😎" |
| 33 | b: "Hello\nWorld!" |
| 34 | } |
| 35 | ``` |