<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>This is all runtime processing. I think the indentation stripping is better done at compile time.&nbsp;</div><div><br></div><div>You should be able to select the multi-line string constants in your array of stories example and indent them to look good in your code. Then just use the closing delimiter to tell the compiler how much indentation to strip.&nbsp;<br></div><div><br></div><div>Here is Brent's excellent proposal in case you have not seen it:</div><div><br></div><div><a href="https://github.com/johnno1962a/swift-evolution/blob/master/proposals/0168-multi-line-string-literals.md">https://github.com/johnno1962a/swift-evolution/blob/master/proposals/0168-multi-line-string-literals.md</a></div><div><br><div><br></div>On Apr 14, 2017, at 11:12 PM, Muse M &lt;<a href="mailto:james.lei65@gmail.com">james.lei65@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">This would be prefer to follow Scala multiline string which look<div><br></div><div>1) //Default&nbsp;</div><div><font face="monospace, monospace">var code = <font color="#ff0000">"""</font></font><span style="font-family:monospace,monospace">header</span></div><div><font face="monospace, monospace">paragraph1</font><span style="color:rgb(255,0,0);font-family:monospace,monospace">"""</span></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><b>Output:</b></font></div><div><div><font face="monospace, monospace">&gt;header</font></div><div><font face="monospace, monospace">&gt;paragraph1</font></div></div><div><br></div><div><font face="monospace, monospace">2)</font></div><div><div><font face="monospace, monospace">var code = <font color="#ff0000">"""</font></font></div><div><font face="monospace, monospace">...header...</font></div><div><font face="monospace, monospace">...paragraph1...</font></div><div><font face="monospace, monospace"><font color="#ff0000">"""</font></font><span style="font-family:monospace,monospace">.replace("...")</span></div></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace"><b>Output:</b></font></div><div><div><font face="monospace, monospace">&gt;header</font></div><div><font face="monospace, monospace">&gt;paragraph1</font></div></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">3)</font></div><div><div><font face="monospace, monospace">var code = <font color="#ff0000">"""</font></font></div><div><font face="monospace, monospace">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|..header...</font></div><div><font face="monospace, monospace">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|..paragraph1...</font></div><div><font color="#ff0000" style="font-family:monospace,monospace">"""</font><span style="font-family:monospace,monospace">.stripLeadingSpace()</span></div></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace"><b>Output:</b></font></div><div><div><font face="monospace, monospace">&gt;header...</font></div><div><font face="monospace, monospace">&gt;paragraph1...</font></div></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">4)</font></div><div><div><font face="monospace, monospace">var code = <font color="#ff0000">"""</font></font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">import Foundation</font></div><div><font face="monospace, monospace">print("Hello World!")</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><font color="#ff0000">"""</font>.code()</font></div></div><div><br></div><div><div><font face="monospace, monospace"><b>Output:</b></font></div><div><div><font face="monospace, monospace">&gt;</font></div><div><font face="monospace, monospace">&gt;</font><span style="font-family:monospace,monospace">import Foundation</span></div><div><font face="monospace, monospace">&gt;print("Hello World!")</font></div></div></div><div><font face="monospace, monospace">&gt;</font></div><div><br></div><div>5)</div><div>//To remove all new lines</div><div><div><font face="monospace, monospace">var code = <font color="#ff0000">"""</font></font></div><div><font face="monospace, monospace">import Foundation</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">import Cocoa</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">....print("Hello World!")</font></div><div><font face="monospace, monospace"><font color="#ff0000">"""</font>.compactLine()</font></div></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace"><b>Output:</b></font></div><div></div><div><font face="monospace, monospace">&gt;import Foundation</font></div><div><font face="monospace, monospace">&gt;</font><span style="font-family:monospace,monospace">import Cocoa</span></div><div><font face="monospace, monospace">&gt;....print("Hello World!")</font></div></div><div><br></div><div><br></div><div><br></div><div>On Multiline String collection</div><div><br></div><div><div>6) If we are importing many sources from 3rd parties API, we won't know if their code is properly indent, some use tab and some use 2 or 4-space. This would look better on Swift Playground app.</div><div><br></div><div><font face="monospace, monospace"><font color="#ff0000">var </font><b>stories</b>&nbsp;= {</font></div><div><font face="monospace, monospace" color="#ff0000">"""</font></div><div><font face="monospace, monospace">Chapter1</font></div>第1章</div><div><br></div><div>Introduction to A<br><div><font face="monospace, monospace"><font color="#ff0000">"""</font>,</font></div><div><div><font face="monospace, monospace" color="#ff0000">"""</font></div><div><font face="monospace, monospace">Chapter2</font></div><div>第2章<br></div><div><br></div><div>Introduction to B<br></div><div><font face="monospace, monospace" color="#ff0000">"""</font><span style="font-family:monospace,monospace">,</span></div></div><div><div><font face="monospace, monospace" color="#ff0000">"""</font></div><div><font face="monospace, monospace">//Code Example</font></div><div>&nbsp; &nbsp; import Foundation<br></div><div><font face="monospace, monospace" color="#ff0000">"""</font></div></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace"><br></font></div>We can loop or apply to certain collection<div><font face="monospace, monospace">stories(3).code()</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><br></font></div><div><br></div></div><div>On Saturday, April 15, 2017, Ricardo Parada via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>I agree that it is not obvious.&nbsp;</div><div><br></div><div>At one point I argued that the trailing newline on the last line should be stripped. But for this reason and others I am now in the camp that thinks we should leave the trailing newline alone.&nbsp;</div><div><br></div><div>If we don't want to include the trailing newline we can always do this:<br></div><div><br></div><div>let str = """</div><div>&nbsp; &nbsp;Line 1</div><div>&nbsp; &nbsp;Line 2\</div><div>&nbsp; &nbsp;"""</div><div><br></div><div>This is were it's difficult to get consensus.&nbsp;</div><div><br></div><div>Regards,</div><div>Ricardo&nbsp;</div><div><br></div><div><br></div><div>On Apr 14, 2017, at 5:54 PM, BJ Homer via swift-evolution &lt;<a>swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div>I’m not saying that the + operator should automatically add a newline. I’m saying that both strings should contain a trailing newline, such that the visible result is the same.<div><br></div><div>By contrast, this would feel really strange:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><span style="font-family:menlo">let a = """<br></span><span style="font-family:menlo">This is line one<br></span><span style="font-family:menlo">This is line two</span></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><span style="font-family:menlo"><br></span><span style="font-family:menlo">"</span><font face="Menlo">""</font></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="Menlo"><br></font><span style="font-family:menlo">let b = """<br></span><span style="font-family:menlo">This is line three<br></span><span style="font-family:menlo">This is line four</span></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><span style="font-family:menlo">"</span><font face="Menlo">""</font></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="Menlo"><br></font><span style="font-family:menlo">(a + b) ==&nbsp;"""<br></span><span style="font-family:menlo">This is line one<br></span><span style="font-family:menlo">This is line two<br></span><span style="font-family:menlo">This is line three<br></span><span style="font-family:menlo">This is line four</span><div><div class="gmail_quote"><div style="word-wrap:break-word"><div><font face="Menlo">"""</font></div></div></div></div></blockquote><div><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"></blockquote></div></blockquote></div></blockquote><div><br></div><div>On initial intuition, it seems strange that ‘a’ has a blatantly visible blank line at the end which seemingly “disappears” when the strings are concatenated. If I think about it for a bit, I can understand why that would be the case, but I think it’s non-obvious.</div><div><br></div><div>-BJ</div><div><br><div><blockquote type="cite"><div>On Apr 14, 2017, at 3:49 PM, Xiaodi Wu &lt;<a>xiaodi.wu@gmail.com</a>&gt; wrote:</div><br><div>I disagree. I expect the last result to be from `a + "\n" + b`, for the reasons I outlined earlier.<br><br>The concatenation operator + does not introduce implied separators when joining strings. There is no reason to think that it should for multi-line strings specifically.<br><div class="gmail_quote"><div dir="ltr">On Fri, Apr 14, 2017 at 16:35 BJ Homer via swift-evolution &lt;<a>swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div style="margin:15px 0px;font-family:helvetica,arial;font-size:13px"><br></div><blockquote type="cite"><p style="margin:15px 0px;font-family:helvetica,arial;font-size:13px">Consider these two examples:</p><pre style="margin-top:15px;margin-bottom:15px;font-family:menlo,consolas,&quot;liberation mono&quot;,courier,monospace;font-size:10pt;border-radius:3px;background-color:rgb(248,248,248);border:1px solid rgb(204,204,204);overflow:auto;padding:4px 8px;word-break:normal;word-wrap:normal"><code style="font-family:menlo,consolas,&quot;liberation mono&quot;,courier,monospace;font-size:10pt;border-radius:3px;color:inherit;border:0px;margin:0px;padding:0px;word-break:normal;word-wrap:normal">let string_1 = """foo"""


let string_2 = """
    foo
    """
</code></pre><p style="margin:15px 0px;font-family:helvetica,arial;font-size:13px">What’s the intuitive result you’d expect without taking all the long talk from the list into account?</p><p style="margin:15px 0px;font-family:helvetica,arial;font-size:13px">Personally, I’d say&nbsp;<code style="font-family:menlo,consolas,&quot;liberation mono&quot;,courier,monospace;font-size:10pt;border-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">string_1 == string_2</code>&nbsp;is true.</p></blockquote><div><br></div></div><div style="word-wrap:break-word"><div>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:</div><div><font face="Menlo"><br></font></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="Menlo"><span><div>let a = """</div></span></font><font face="Menlo"><span><div>This is line one</div></span></font><font face="Menlo"><span><div>This is line two"</div></span></font><font face="Menlo"><span><div>"""</div></span></font><font face="Menlo"><span><div><br></div></span></font><font face="Menlo"><span><div>let b = """</div></span></font><font face="Menlo"><span><div>This is line three</div></span></font><font face="Menlo"><span><div>This is line four</div></span></font><font face="Menlo"><span><div>"""</div></span></font><span><br></span><div><font face="Menlo">(a + b) ==&nbsp;"""</font></div><div><font face="Menlo">This is line one</font></div><div><font face="Menlo">This is line two</font></div><div><font face="Menlo">This is line three</font></div><div><font face="Menlo">This is line four</font></div><div><font face="Menlo">"""</font></div></blockquote><div><br></div><div>That seems like a reasonable model to work with multi-line strings.</div></div><div style="word-wrap:break-word"><div><br></div><div>-BJ</div></div>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a>swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br>
</blockquote></div>
</div></blockquote></div><br></div></div></div></blockquote><blockquote type="cite"><div><span>______________________________<wbr>_________________</span><br><span>swift-evolution mailing list</span><br><span><a>swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a></span><br></div></blockquote></div></blockquote>
</div></div>
</div></blockquote></body></html>