Marcel van Lohuizen | 0117d90 | 2019-02-21 23:55:39 +0100 | [diff] [blame] | 1 | [TOC](Readme.md) [Prev](stringlit.md) [Next](bytes.md) |
| 2 | |
| 3 | _JSON Sugar and other Goodness_ |
| 4 | |
| 5 | # "Raw" Strings |
| 6 | |
| 7 | CUE does not support raw strings in the strictest sense. |
| 8 | Instead it allows modifying the escape delimiter by requiring |
| 9 | an arbitrary number of hash `#` signs after the backslash by |
| 10 | enclosing a string literal in an equal number of hash signs on either end. |
| 11 | |
| 12 | This works for normal and interpolated strings. |
| 13 | Quotes do not have to be escaped in such strings. |
| 14 | |
| 15 | <!-- CUE editor --> |
Marcel van Lohuizen | f0c9404 | 2019-02-22 22:46:37 +0100 | [diff] [blame] | 16 | _stringraw.cue:_ |
Marcel van Lohuizen | 0117d90 | 2019-02-21 23:55:39 +0100 | [diff] [blame] | 17 | ``` |
| 18 | msg1: #"The sequence "\U0001F604" renders as \#U0001F604."# |
| 19 | |
| 20 | msg2: ##""" |
| 21 | A regular expression can conveniently be written as: |
| 22 | |
| 23 | #"\d{3}"# |
| 24 | |
Marcel van Lohuizen | f0c9404 | 2019-02-22 22:46:37 +0100 | [diff] [blame] | 25 | This construct works for bytes, strings and their |
| 26 | multi-line variants. |
Marcel van Lohuizen | 0117d90 | 2019-02-21 23:55:39 +0100 | [diff] [blame] | 27 | """## |
| 28 | ``` |
| 29 | |
| 30 | <!-- JSON result --> |
Marcel van Lohuizen | f0c9404 | 2019-02-22 22:46:37 +0100 | [diff] [blame] | 31 | `$ cue eval stringraw.cue` |
Tarun Gupta Akirala | bb2b651 | 2019-06-03 13:24:12 +0000 | [diff] [blame] | 32 | ``` |
Marcel van Lohuizen | 0117d90 | 2019-02-21 23:55:39 +0100 | [diff] [blame] | 33 | { |
| 34 | msg1: "The sequence \"\\U0001F604\" renders as 😄." |
| 35 | msg2: """ |
| 36 | A regular expression can conveniently be written as: |
| 37 | |
| 38 | #\"\\d{3}\"# |
| 39 | |
Marcel van Lohuizen | f0c9404 | 2019-02-22 22:46:37 +0100 | [diff] [blame] | 40 | This construct works for bytes, strings and their |
| 41 | multi-line variants. |
Marcel van Lohuizen | 0117d90 | 2019-02-21 23:55:39 +0100 | [diff] [blame] | 42 | """ |
| 43 | } |
| 44 | ``` |