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

Ricardo Parada rparada at mac.com
Tue Apr 11 18:52:23 CDT 2017


Sure. Let me quote the proposal:

"We propose that, when the opening delimiter ends its line and the closing delimiter starts its line, tripled string literals should automatically remove whatever indentation is present before the closing delimiter from each line above it, as well as removing the leading newline. "

let str = """····My favorite things in life don't cost any money.↵
····It's really clear that the most precious resource we all have is time. - Steve Jobs"""


If I understand correctly, in this example, the opening delimiter does not end its line and the closing delimiter does not begin its line.  Therefore, the indentation stripping is not enabled and would yield this:

····My favorite things in life don't cost any money.↵
····It's really clear that the most precious resource we all have is time. - Steve Jobs


I personally do not care if indentation stripping is always enabled.  But after having seen all kinds of responses I would not be surprised if someone will ask for the ability to turn indentation stripping on/off.   :-)

I think the enabling of the indentation stripping could be relaxed a little bit and not require the opening delimiter to end its line.  So for example, it would be possible to do this:


let xml = """<?xml version="1.0"?>
             <catalog>
                 <book id="bk101" empty="">
                     <author>\(author)</author>
                     <title>XML Developer's Guide</title>
                     <genre>Computer</genre>
                     <price>44.95</price>
                     <publish_date>2000-10-01</publish_date>
                     <descr>An in-depth look at creating applications with XML.</descr>
                 </book>
             </catalog>
             """

Notice that here, the opening delimiter does not end its line but the closing delimiter does begin its line.  This could produce the following:

<?xml version="1.0"?>
<catalog>
    <book id="bk101" empty="">
        <author>John Doe</author>
        <title>XML Developer's Guide</title>
        <genre>Computer</genre>
        <price>44.95</price>
        <publish_date>2000-10-01</publish_date>
        <descr>An in-depth look at creating applications with XML.</descr>
    </book>
</catalog>


I think Brent did a super awesome job.  The proposal is very detailed with a ton of examples. I think it covers just about everything that people have asked for.  

Regards,
Ricardo



On Apr 11, 2017, at 1:06 PM, Adrian Zubarev <adrian.zubarev at devandartist.com <mailto:adrian.zubarev at devandartist.com>> wrote:

> Can you elaborate a small example please, so I can better understand what you asked for?
> 
> 
> 
> 
> -- 
> Adrian Zubarev
> Sent with Airmail
> 
> Am 11. April 2017 um 18:51:45, Ricardo Parada (rparada at mac.com <mailto:rparada at mac.com>) schrieb:
> 
>> 
>> 
>> Hi Adrian,
>> 
>> I think having the closing """ on a line by itself activates the indentation stripping feature. So if it was to change as you suggest then how would you turn off indentation stripping?
>> 
>> 
>> 
>> On Apr 11, 2017, at 11:08 AM, Adrian Zubarev via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>>> This would be consistent and less confusing to learn.
>>> 
>>> Can’t we make the indent algorithm work like this instead?
>>> let string = """\↵
>>> ····<tag>↵
>>> ······content text↵
>>> ····</tag>""" // Indent starts with the first non space character
>>> 
>>> // result
>>> 
>>> <tag>↵
>>> ··content text↵
>>> </tag>
>>> The line where the closing delimiter is trims all space chapters and the indent for the whole multi-line string is starting at the point where the first non-space chapters is in that line.
>>> 
>>> What do you think?
>>> 
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170411/4d32d722/attachment.html>


More information about the swift-evolution mailing list