<html><head><style>
body {
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        padding:1em;
        margin:auto;
        background:#fefefe;
}
h1, h2, h3, h4, h5, h6 {
        font-weight: bold;
}
h1 {
        color: #000000;
        font-size: 28pt;
}
h2 {
        border-bottom: 1px solid #CCCCCC;
        color: #000000;
        font-size: 24px;
}
h3 {
        font-size: 18px;
}
h4 {
        font-size: 16px;
}
h5 {
        font-size: 14px;
}
h6 {
        color: #777777;
        background-color: inherit;
        font-size: 14px;
}
hr {
        height: 0.2em;
        border: 0;
        color: #CCCCCC;
        background-color: #CCCCCC;
display: inherit;
}
p, blockquote, ul, ol, dl, li, table, pre {
        margin: 15px 0;
}
a, a:visited {
        color: #4183C4;
        background-color: inherit;
        text-decoration: none;
}
#message {
        border-radius: 6px;
        border: 1px solid #ccc;
        display:block;
        width:100%;
        height:60px;
        margin:6px 0px;
}
button, #ws {
        font-size: 12 pt;
        padding: 4px 6px;
        border-radius: 5px;
        border: 1px solid #bbb;
        background-color: #eee;
}
code, pre, #ws, #message {
        font-family: Monaco;
        font-size: 10pt;
        border-radius: 3px;
        background-color: #F8F8F8;
        color: inherit;
}
code {
        border: 1px solid #EAEAEA;
        margin: 0 2px;
        padding: 0 5px;
}
pre {
        border: 1px solid #CCCCCC;
        overflow: auto;
        padding: 4px 8px;
}
pre > code {
        border: 0;
        margin: 0;
        padding: 0;
}
#ws { background-color: #f8f8f8; }
.bloop_markdown table {
border-collapse: collapse;
font-family: Helvetica, arial, freesans, clean, sans-serif;
color: rgb(51, 51, 51);
font-size: 15px; line-height: 25px;
padding: 0; }
.bloop_markdown table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0; }
.bloop_markdown table tr:nth-child(2n) {
background-color: #f8f8f8; }
.bloop_markdown table tr th {
font-weight: bold;
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }
.bloop_markdown table tr td {
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }
.bloop_markdown table tr th :first-child, table tr td :first-child {
margin-top: 0; }
.bloop_markdown table tr th :last-child, table tr td :last-child {
margin-bottom: 0; }
.bloop_markdown blockquote{
border-left: 4px solid #dddddd;
padding: 0 15px;
color: #777777; }
blockquote > :first-child {
margin-top: 0; }
blockquote > :last-child {
margin-bottom: 0; }
code, pre, #ws, #message {
word-break: normal;
word-wrap: normal;
}
hr {
display: inherit;
}
.bloop_markdown :first-child {
-webkit-margin-before: 0;
}
code, pre, #ws, #message {
font-family: Menlo, Consolas, Liberation Mono, Courier, monospace;
}
.send { color:#77bb77; }
.server { color:#7799bb; }
.error { color:#AA0000; }</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="bloop_markdown"><p>Yep I really did pitched this instead of a triple quoted multi-line literal string.</p>
<pre><code class="swift">let string =
"Hello \ // Three trailing space characters
"Swift\
" 4.0" // Three leading space characters
print(string) // prints: "Hello___Swift___4.0" where _ is a space character
</code></pre>
<p>Ignore the comments above so we can focus on an easy design for both single and triple quoted literals.</p>
<p>The idea here was to fix the problem *<em>continuation quotes</em>* had and allow trailing precision. Now that we established a much simpler design for multi-line string literals, this can be reused in a much consistent way as a hard wrapping feature for both literals, where the backslash disables the new line injection in triple quoted literals.</p>
<p></p></div><div class="bloop_original_html"><style>body{font-family:Helvetica,Arial;font-size:13px}</style><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div> <br> <div id="bloop_sign_1492957953141936896" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Adrian Zubarev<br>Sent with Airmail</div></div> <br><p class="airmail_on">Am 23. April 2017 um 16:30:35, Adrian Zubarev (<a href="mailto:adrian.zubarev@devandartist.com">adrian.zubarev@devandartist.com</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div></div><div>
<title></title>
<div class="bloop_markdown">
<p>I’ve never thought about allowing hard wrapping from single
quoted string literals until it come up during the latest
discussion.</p>
<p>At first glance I don’t have anything against it. I wouldn’t put
comments into the mix for now, to keep things simple. (I’ve already
asked about comments, but the community rejected the idea _for
now_.)</p>
<p>What was the exact use case for hard wrapping for the single
quoted literals again? (Again I’m not against it.) Actually I
believe I pitched a very similar design in the discussion thread
(not during the review).</p>
</div>
<div class="bloop_original_html">
<div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">
<br></div>
<br>
<div id="bloop_sign_1492957351171724032" class="bloop_sign">
<div style="font-family:helvetica,arial;font-size:13px">
-- <br>
Adrian Zubarev<br>
Sent with Airmail</div>
</div>
<br>
<p class="airmail_on">Am 23. April 2017 um 13:14:35, Pyry Jahkola
via swift-evolution (<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)
schrieb:</p>
<blockquote type="cite" class="clean_bq">
<div dir="auto">
<div>
<div>
<div><span>Hmm, I can see that Wux already replied to this question
but let me give another more or less obvious answer which I believe
has come up in a shape or another already:</span></div>
<div><span><br></span></div>
<div><span>Brent Royal-Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>
wrote:</span></div>
<div><span><br></span></div>
<blockquote type="cite">
<div>
<div>
<blockquote type="cite" class="">
<div class="">
<div dir="ltr" class="">
<div class="gmail_extra">
<div class="gmail_quote">
<div class=""><span>No, I am suggesting that whatever design is
used for escaped newlines, if at all possible it should be equally
apt for "strings" and """strings""" such that it will not require
indentation stripping.</span></div>
</div>
</div>
</div>
</div>
</blockquote>
<span><br class=""></span></div>
<div><span>Could you share an example of such a
design?</span></div>
</div>
</blockquote>
<div><span><br></span></div>
<div><span>One way to achieve the criteria below for both singly
and triply quoted strings would be to borrow the <i>repeated
opening quote</i> syntax (from earlier discussions) for singly
quoted strings:</span></div>
<div><span><br></span></div>
<div><span> <b>let s1 = "abc\</b></span></div>
<div><span>
<b>"def\n\</b></span></div>
<div><span> <b>"ghi
\</b></span></div>
<div><span>
<b>"xyz"</b></span></div>
<div><span><b> </b><span style="background-color: rgba(255, 255, 255, 0);">assert(s1
== <b>"abcdef\nghi xyz"</b>)</span></span></div>
<div><span style="background-color: rgba(255, 255, 255, 0);">
</span></div>
<div> <b>let s2 = "abc\</b></div>
<div><b>
"def\n\</b></div>
<div> /* Leading white space, */ <b>"ghi \</b></div>
<div> // as well as comments</div>
<div> </div>
<div> // and empty lines in between are</div>
<div> // insignificant when it comes to singly</div>
<div> // quoted literals.</div>
<div> "<b>xyz"</b></div>
<div><b> </b><span style="background-color: rgba(255, 255, 255, 0);">assert(s2 ==
s1)</span></div>
<div><span style="background-color: rgba(255, 255, 255, 0);">
</span></div>
<div> <b>let s3 = """</b></div>
<div><b> abc\</b></div>
<div><b> def</b></div>
<div><b> ghi \</b></div>
<div><b> xyz</b></div>
<div><b> """</b></div>
<div> <span style="background-color: rgba(255, 255, 255, 0);">assert(s3 ==
s1)</span></div>
<div>
<div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div>
<div><span style="background-color: rgba(255, 255, 255, 0);">The
criteria:</span></div>
<div><br></div>
</div>
<blockquote type="cite">
<div>* Permits non-significant hard-wrapping in a string
literal.</div>
</blockquote>
<div><br></div>
<div>✅ The string continues from the position of the backslash,
with no extra space or line break inserted.</div>
<br>
<blockquote type="cite">
<div>
<div>* Works equally well with single and triple string
literals.</div>
</div>
</blockquote>
<div><br></div>
<div>✅ <span style="background-color: rgba(255, 255, 255, 0);">In
both cases, a trailing `\` has the same meaning. In singly quoted
strings, the only way to insert a newline is by quoting (`\n`), as
it always was.</span></div>
<br>
<blockquote type="cite">
<div>
<div>* Preserves code indentation, but does not require single
string literals to do indentation stripping.</div>
</div>
</blockquote>
<div><br></div>
<div>✅ The indentation is just more explicit with singly quoted
string literals.</div>
<br>
<blockquote type="cite">
<div>
<div>* Is not horribly inconvenient.</div>
</div>
</blockquote>
<br>
<div>🤷♂️ Depends who you ask, I guess, but I think not horrible.
And, after all, the programmer is free to choose between two
quoting styles with different trade offs.</div>
<div><br></div>
<div>* * *</div>
<div><br></div>
<div>One thing that remains to be defined is whether trailing space
is allowed (and ignored) after the backslash or not (and thus an
error). I initially thought it's best to make into a compiler
error, just like the indenting white space of the triple quoted
string literals.</div>
<div><br></div>
<div>OTOH, we could also allow inline comments after the
backslash:</div>
<div><br></div>
<div> let whyNot = "this, \</div>
<div> "that, \ <b>// <- Oxford
comma</b></div>
<div> "and stuff"</div>
<div> assert(whyNot == "this, that, and stuff")</div>
<div> </div>
<div> let list = """</div>
<div> - this,</div>
<div> - that,\n\<b>// comment using
"Adrian's \n\"</b></div>
<div> - and stuff</div>
<div> """</div>
<div> assert(list == "- this,\n- that,\n- and
stuff")</div>
<div><br></div>
<div>[Nit: If comments after the backslash were allowed, we'd need
to <b>either</b> require a space after the backslash (e.g. `\ //`),
<b>or else</b> accept <span style="background-color: rgba(255, 255, 255, 0);">as string continuation
/ comment start markers</span> both `\//` (until newline) and `\/*`
(until `*/`), as seen in the latter example above.]</div>
<div><br></div>
<div>I find this design — with or without comments — would
naturally allow the programmer to choose between precision (singly
quoted) and convenience/legibility (triply quoted). And of course
it would allow breaking long string literals to multiple lines in a
consistent way, which, for triply quoted strings, is also lighter
than just concatenating with `+`.</div>
<div><br></div>
<div>— Pyry</div>
<div><br></div>
<div><span style="background-color: rgba(255, 255, 255, 0);">PS. I
also slightly regret that SE-0168 ended up stripping the trailing
newline, because multiline strings seem to compose (concatenate)
better with a trailing newline there by default. But I understand
if the inconvenience of `print(str, terminator: "")` weighed more
than the other option.</span></div>
</div>
_______________________________________________<br>
swift-evolution mailing list<br>
swift-evolution@swift.org<br>
https://lists.swift.org/mailman/listinfo/swift-evolution<br></div>
</div>
</blockquote>
</div>
<div class="bloop_markdown"></div>
</div></div></span></blockquote></div><div class="bloop_markdown"><p></p></div></body></html>