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

Thorsten Seitz tseitz42 at icloud.com
Sat Apr 15 07:41:31 CDT 2017


> Am 14.04.2017 um 23:35 schrieb BJ Homer <bjhomer at gmail.com>:
> 
> 
>> Consider these two examples:
>> 
>> let string_1 = """foo"""
>> 
>> 
>> let string_2 = """
>>     foo
>>     """
>> What’s the intuitive result you’d expect without taking all the long talk from the list into account?
>> 
>> Personally, I’d say string_1 == string_2 is true.
>> 
> 
> I think it’s reasonable to expect them to be different, actually. I might call these “single-line” and “multi-line” mode strings. The single-line mode is primarily useful for being able to include unescaped double-quotes in the string. If you’re in multi-line mode, though, it’s reasonable to be thinking about things in terms of “lines”, and having a trailing newline there seems reasonable. For example, I think it’s reasonable to expect this:
> 
> let a = """
> This is line one
> This is line two"
> """
> 
> let b = """
> This is line three
> This is line four
> """
> 
> (a + b) == """
> This is line one
> This is line two
> This is line three
> This is line four
> """
> 
> That seems like a reasonable model to work with multi-line strings.

+1

-Thorsten

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170415/92c0affd/attachment.html>


More information about the swift-evolution mailing list