@@ -23,6 +23,9 @@ The syntax for scalars is similar to the PHP syntax.
23
23
Strings
24
24
~~~~~~~
25
25
26
+ Strings in YAML can be wrapped both in single and double quotes. In some cases,
27
+ they can also be unquoted:
28
+
26
29
.. code-block :: yaml
27
30
28
31
A string in YAML
@@ -31,26 +34,50 @@ Strings
31
34
32
35
' A singled-quoted string in YAML'
33
36
34
- .. tip ::
37
+ .. code-block :: yaml
35
38
36
- In a single quoted string, a single quote `` ' `` must be doubled:
39
+ " A double- quoted string in YAML "
37
40
38
- .. code-block :: yaml
41
+ Quoted styles are useful when a string starts or ends with one or more
42
+ relevant spaces, because unquoted strings are trimmed on both ends when parsing
43
+ their contents.
39
44
40
- ' A single quote '' in a single-quoted string'
45
+ When using single-quoted strings, any single quote ``' `` inside its contents
46
+ must be doubled to escape it:
41
47
42
- .. code-block :: yaml
48
+ .. code-block :: yaml
43
49
44
- " A double -quoted string in YAML \n "
50
+ ' A single quote '' inside a single -quoted string'
45
51
46
- Quoted styles are useful when a string starts or ends with one or more
47
- relevant spaces.
52
+ The double-quoted style provides a way to express arbitrary strings, by
53
+ using ``\ `` escape sequences. It is very useful when you need to embed a
54
+ ``\n `` or a Unicode character in a string.
55
+
56
+ .. code-block :: yaml
48
57
49
- .. tip ::
58
+ " A double-quoted string in YAML \n "
50
59
51
- The double-quoted style provides a way to express arbitrary strings, by
52
- using ``\ `` escape sequences. It is very useful when you need to embed a
53
- ``\n `` or a unicode character in a string.
60
+ If the string contains any of the following characters, it must be escaped with
61
+ single quotes:
62
+
63
+ ===== ===== ===== ===== =====
64
+ ``: `` ``{ `` ``} `` ``[ `` ``] ``
65
+ ``, `` ``& `` ``* `` ``# `` ``? ``
66
+ ``| `` ``- `` ``< `` ``> `` ``= ``
67
+ ``! `` ``% `` ``@ `` ``\` ``
68
+ ===== ===== ===== ===== =====
69
+
70
+ If the string contains any of the following control characters, it must be
71
+ escaped with double quotes. In addition, the escaping must use a double slash
72
+ ``\\ `` to avoid parsing issues:
73
+
74
+ ======== ======== ======== ======== ======== ======== ======== ========
75
+ ``\0 `` ``\x01 `` ``\x02 `` ``\x03 `` ``\x04 `` ``\x05 `` ``\x06 `` ``\a ``
76
+ ``\b `` ``\t `` ``\n `` ``\v `` ``\f `` ``\r `` ``\x0e `` ``\x0f ``
77
+ ``\x10 `` ``\x11 `` ``\x12 `` ``\x13 `` ``\x14 `` ``\x15 `` ``\x16 `` ``\x17 ``
78
+ ``\x18 `` ``\x19 `` ``\x1a `` ``\e `` ``\x1c `` ``\x1d `` ``\x1e `` ``\x1f ``
79
+ ``\N `` ``\_ `` ``\L `` ``\P ``
80
+ ======== ======== ======== ======== ======== ======== ======== ========
54
81
55
82
When a string contains line breaks, you can use the literal style, indicated
56
83
by the pipe (``| ``), to indicate that the string will span several lines. In
0 commit comments