[swift-evolution] multi-line string literals
jason.dusek at gmail.com
Fri Dec 11 00:04:31 CST 2015
On Thu, 10 Dec 2015 at 21:45, Travis Tilley via swift-evolution <
swift-evolution at swift.org> wrote:
The ruby <<- heredoc syntax, unlike the << heredoc syntax, will strip
> indentation if necessary. Technically, it searches for the "least indented
> line" in the whole string, and removes exactly that amount from each line.
> So yes, the indentation problem -is- solved in ruby (though it might break
> entirely if you have empty lines, since the least indented line has no
To my mind, the rules should be:
1. The indentation level is set from the least indented line that is not
the first line and is not empty.
2. A leading empty line is removed.
3. The leading line, if there is any text in it, is not subject to
I genuinely believe these three rules taken together address all the errors
and infelicities to which triple quotes and HEREDOCs subject us. Here are
text = """
"""# From (1): The indentation is taken from the third line below
`text`, so it's 2.# From (2): First line is: "\n" so it is removed.#
>From (3): No effect.
text = """ Some
"""# From (1): The indentation is taken again from the line reading
"Features". Here it is 10.# From (2): No effect.# From (3): The
leading whitespace in ` Some` is preserved.
Do you all think these rules pass muster?
A fourth rule — one which seems advisable but also less necessary than the
others — is that a string constructed in this way always ends with a
newline. It is a rule that perhaps leads to surprises and inconsistencies.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution