[swift-evolution] [Review] SE-0168: Multi-Line String Literals

Adrian Zubarev adrian.zubarev at devandartist.com
Wed Apr 12 15:48:23 CDT 2017


Below you can read a part of my message to John, where I was testing the toolchain.

If that design for the trailing spaces is indented then I disagree with that design choice.

In a normal string literal it’s crystal clear that it contains multiple space characters at the end, because it’s visible to the reader of that code. As shown below, if Xcode wouldn’t help here, the end result might contain spaces which could be caused by an accident and are not clear to the reader at all.

I suggest to align this behavior with normal string literals by stripping all space characters at the end of each line, just like Xcode does, unless they are explicitly annotated by a backslash, which would be clear to the reader of the code.

That said, this:

let s0 = "abc\n"

let s1 = """↵
    abc···↵
    """
     
let s2 = """↵
    abc···\↵
    """
     
let s3 = """↵
    abc···\n\↵
    """
     
s0 == s1         // => true
s0 == s2         // => false
s2 == "abc···"   // => true
s3 == "abc···\n" // => true
Xcode does trip trailing spaces by default for me, however I was able to press spacebar a couple times and these spaces where not trimmed by the current toolchain.

“”"↵
AA····↵
“”"

The string was equivalent to “\nAA····\n”




The strange character is actually a white space displayed by Xcode.

-- 
Adrian Zubarev
Sent with Airmail

Am 12. April 2017 um 22:06:01, Adrian Zubarev (adrian.zubarev at devandartist.com) schrieb:

Exactly, I feel like we found a Swifty version of a multi-line string literal. :)



-- 
Adrian Zubarev
Sent with Airmail

Am 12. April 2017 um 21:58:37, Vladimir.S via swift-evolution (swift-evolution at swift.org) schrieb:

this:
"""
one
two
"""
should be just the same as "one\ntwo\n"

If one wants some advanced tuning of line ends, he/she can use a backslash, for example
"""
one
two\
"""
should produce "one\ntwo"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170412/2c28b062/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 27DCFF63-7467-42FC-901F-0B085EB37DBD
Type: application/octet-stream
Size: 19549 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170412/2c28b062/attachment.obj>


More information about the swift-evolution mailing list