Literals/String: Difference between revisions

Added TOML
No edit summary
(Added TOML)
Line 2,634:
There are no escape characters.
Quotes in strings are doubled: <code>"This > "" < is one double-quote."</code>
 
=={{header|TOML}}==
There are four ways to express strings: basic, multi-line basic, literal, and multi-line literal. All strings must contain only valid UTF-8 characters.
 
'''Basic strings''' are surrounded by quotation marks. Any Unicode character may be used except those that must be escaped: quotation mark, backslash, and the control characters other than tab (U+0000 to U+0008, U+000A to U+001F, U+007F).
<lang TOML>str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."</lang>
 
'''Multi-line basic strings''' are surrounded by three quotation marks on each side and allow newlines. A newline immediately following the opening delimiter will be trimmed. All other whitespace and newline characters remain intact.
<lang TOML>str1 = """
Roses are red
Violets are blue"""</lang>
 
When the last non-whitespace character on a line is a <code>\</code> ("line ending backslash"), it will be trimmed along with all whitespace (including newlines) up to the next non-whitespace character or closing delimiter. All of the escape sequences that are valid for basic strings are also valid for multi-line basic strings.
<lang TOML># The following strings are byte-for-byte equivalent:
str1 = "The quick brown fox jumps over the lazy dog."
 
str2 = """
The quick brown \
 
 
fox jumps over \
the lazy dog."""
 
str3 = """\
The quick brown \
fox jumps over \
the lazy dog.\
"""</lang>
 
'''Literal strings''' are surrounded by single quotes and do not support escaping. This means that there is no way to write a single quote in a literal string. Like basic strings, they must appear on a single line.
<lang TOML># What you see is what you get.
winpath = 'C:\Users\nodejs\templates'
winpath2 = '\\ServerX\admin$\system32\'
quoted = 'Tom "Dubs" Preston-Werner'
regex = '<\i\c*\s*>'</lang>
 
'''Multi-line literal strings''' are surrounded by three single quotes on each side and allow newlines. Like literal strings, there is no escaping whatsoever. A newline immediately following the opening delimiter will be trimmed. All other content between the delimiters is interpreted as-is without modification. One or two single quotes are allowed anywhere within a multi-line literal string, but sequences of three or more single quotes are not permitted.
<lang TOML>regex2 = '''I [dw]on't need \d{2} apples'''
lines = '''
The first newline is
trimmed in raw strings.
All other whitespace
is preserved.
'''</lang>
 
=={{header|TUSCRIPT}}==
5

edits