[swift-evolution] multi-line string literals

Travis Tilley ttilley at gmail.com
Mon Dec 14 15:10:50 CST 2015


I was thinking of keeping it really simple and having just a few main rules.

1) using " means that the string contents are escaped
2) using ' means that the string contents are unescaped/raw
3) using """ or ''' means that it's a multi-line string and indentation
erasure rules are in effect
4) indentation erasure is from the least indented line (from start of line,
not start of quote)
5) the first line, if it contains only a newline, is removed entirely (this
lets you just start your text on the next line)

I'm wibbly wobbly about the last line containing only a newline. I'm not
sure whether to err on the side of caution and assume it's intentional, or
remove it as well. At the moment I'm leaning toward assuming it's
intentional.

I'm also not entirely sure what to do in the case of mixed indentation. I
could absolutely see the leading indentation being tabs (with the editor
displaying them as equivalent to 4 spaces), but the slight indentation of
one to three characters being spaces.

Here is the SQL example for reference to show what I mean:

func findMentions(account: String) -> Array<String> {
    let db = databaseFactory().findDatabase()
    let q = '''SELECT array_agg(mentioner.id)
                 FROM account
                 JOIN mention ON (account.id = mentioned)
                 JOIN account AS mentioner ON (mentioner.id = mentioner)
                WHERE account.handle = :1
                ORDER BY timestamp DESC
                LIMIT 1'''

    return db.query(q).parameterize(account).run()
}

​- Travis Tilley​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151214/57101ebf/attachment.html>


More information about the swift-evolution mailing list