You can. I wish I remembered the language this was in (not sure if it's in 
Scala), but you can do something like:

let xml = '''
                |<?xml version="1.0"?> 
                |<catalog> 
                |       <...>
                |</catalog> 
                '''

This way, if you care about the leading whitespace, you define the line 
beginning using "|".

Two characters aren't harmful, but in my experience when working with HTML 
strings, etc. the quote-escaping is extremely tedious.

> On Apr 3, 2017, at 11:06 AM, Adrian Zubarev <[email protected]> 
> wrote:
> 
> My main concern with this approach is that you don’t have any control about 
> indent and you loose pre- and post spacing characters.
> 
> A concatenating approach is a little tedious but it’s precise. In any 
> situation a multi-lined string is not softly wrapped string, which implies 
> that you will have to press enter for each new line you wish to have. IMHO 
> adding two more characters for each line isn’t that harmful. ;-)
> 
> 
> 
> 
> -- 
> Adrian Zubarev
> Sent with Airmail
> 
> Am 3. April 2017 um 10:49:02, Charlie Monroe ([email protected] 
> <mailto:[email protected]>) schrieb:
> 
>> While I long for multiline string literals, I'd also very like to see a 
>> different syntax as in many cases, these can be XML/HTML snippets and the 
>> use of quotes is ubiqituous. I'd very much like to see a variant where you 
>> can simply paste almost any string without escaping it.
>> 
>> For example, Scala uses a tripple-quote syntax... As we've gotten rid of ' 
>> for character literals, we could use it for multiline strings?
>> 
>> Or possibly tripple-apostrophe for multiline strings?
>> 
>> let xml = '''
>> <?xml version="1.0"?> 
>> <catalog/> 
>> '''
>> 
>> 
>>> On Apr 3, 2017, at 9:01 AM, Adrian Zubarev via swift-evolution 
>>> <[email protected] <mailto:[email protected]>> wrote:
>>> 
>>> Hello Swift community,
>>> 
>>> on Github there is a PR for this proposal, but I couldn’t find any up to 
>>> date thread, so I’m going to start by replying to the last message I found, 
>>> without the last content.
>>> 
>>> I really like where this proposal is going, and my personal preference are 
>>> *continuation quotes*. However the proposed solution is still not perfect 
>>> enough for me, because it still lacks of precise control about the trailing 
>>> space characters in each line of a multi-line string.
>>> 
>>> Proposed version looks like 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>
>>>     "        <description>An in-depth look at creating applications with 
>>> XML.</description>
>>>     "    </book>
>>>     "</catalog>
>>>     ""
>>> I would like to pitch an enhancement to fix the last tiny part by adding 
>>> the escaping character ‘' to the end of each line from 1 to (n - 1) of the 
>>> n-lined string. This is similar to what Javascript allows us to do, except 
>>> that we also have precise control about the leading space character through 
>>> ’"’.
>>> 
>>> The proposed version will become this:
>>> 
>>> let xml = "<?xml version=\"1.0\"?>\   
>>>     "<catalog>\ // If you need you can comment here
>>>     "    <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>\
>>>     "        <description>An in-depth look at creating applications with 
>>> XML.</description>\
>>>     "    </book>\
>>>     "</catalog>\
>>>     ""
>>> Here is another example:
>>> 
>>> let multilineString: String = "123__456__\ // indicates there is another 
>>> part of the string on the next line
>>>                               "__789_____\ // aways starts with `"` and 
>>> ends with either `\` or `"`
>>>                               "_____0_" // precise control about pre- and 
>>> post-space-characters
>>> 
>>> let otherString = "\(someInstance)\ /* only comments are allowed in between 
>>> */ "text \(someOtherInstance) text"
>>> This is simply continuation quotes combined with backslash concatenation.
>>> 
>>> 
>>> 
>>> 
>>> 
>>> -- 
>>> Adrian Zubarev
>>> Sent with Airmail
>>> 
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> [email protected] <mailto:[email protected]>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution 
>>> <https://lists.swift.org/mailman/listinfo/swift-evolution>
>> 
> 
> 

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to