<div dir="ltr">Hi,<div><br></div><div>I am new to swift-evolution list, here is my draft proposal for the multi-line string literal problem.</div><div>The idea had been discussed in the list before, but it seems there are no real solution to many of the string literal problem.</div><div>Let&#39;s first define what are the problem with string literal:</div><div><br></div><div>1. should be able to disable escape char</div><div><br></div><div>2. or better, able to replace escape char with user defined char</div><div><br></div><div>3. should be able to write multi-line string literal, and is copy-paste friendly</div><div><br></div><div>4. for multi-line string, should be  able to remove first and last newline char, so user can write string in block</div><div><br></div><div>5. for multi-line string, should be  able to remove leading indent, or remove all indent</div><div><br></div><div>6. for multi-line string, should be  able to replace newline with user defined string (&quot;\r\n&quot;, &quot;\r&quot;, &quot;\r&quot;, or simply &quot; &quot;)</div><div><br></div><div>7. should be able to add feature over time, without breaking existing code</div><div><br></div><div>My proposal to the above problem is to introduce new &#39;process instruction&#39; (not sure how to call it), in the following form:</div><div><br></div><div>#string(options) &quot;text&quot;</div><div><br></div><div>for example:</div><div><br></div><div>#string(escape: nil) &quot;^\d+&quot;</div><div><br></div><div>#string(escape: &quot;$&quot;, end: &quot;&lt;<span class="" id=":1th.1" tabindex="-1" style="background:yellow"><span class="" id=":1th.15" tabindex="-1">EOF</span></span>&gt;&quot;) &quot;</div><div>   $(<span class="" id=":1th.2" tabindex="-1" style="background:yellow"><span class="" id=":1th.16" tabindex="-1">username</span></span>),</div><div>   Is it 1358 yet?</div><div>&lt;<span class="" id=":1th.3" tabindex="-1" style="background:yellow"><span class="" id=":1th.17" tabindex="-1">EOF</span></span>&gt;&quot;</div><div><br></div><div>It is possible to add many options list above, and you can add more options over time without breaking code.</div><div><br></div><div>#string(</div><div>    escape: Character? = &quot;\\&quot;,    </div><div>    end: String? = nil,   </div><div>    <span class="" id=":1th.18" tabindex="-1">skipEnclosureNewline</span>: <span class="" id=":1th.19" tabindex="-1">Bool</span> = true,    </div><div>    <span class="" id=":1th.20" tabindex="-1">skipLeadingIndent</span>: <span class="" id=":1th.21" tabindex="-1">Bool</span> = true, </div><div>    <span class="" id=":1th.22" tabindex="-1">skipAllIndent</span>: <span class="" id=":1th.23" tabindex="-1">Bool</span> = false,</div><div>    newline: String? = nil</div><div>)</div><div><br></div><div>for 1. &amp; 2., escape option to replace escape char, pass nil will disable escape.</div><div><br></div><div>for 3., end option for end-of-string mark, pass nil will disable multi-line processing.</div><div><br></div><div>for 4., <span class="" id=":1th.24" tabindex="-1">skipEnclosureNewline</span> will skip newline if it is the first or last char of the string.<br></div><div><br></div><div>for 5., <span class="" id=":1th.25" tabindex="-1">skipLeadingIndent</span> will skip leading indent, leading indent is the leading white-spaces of first line of multi-line string.<br></div><div><br></div><div>for 5., <span class="" id=":1th.26" tabindex="-1">skipAllIndent</span> will skip all indent, this will override <span class="" id=":1th.27" tabindex="-1">skipLeadingIndent</span>.<br></div><div><br></div><div>for 6., newline option to replace newline char in multi-line string, pass nil will disable the replacement (as-is in the source).</div><div><br></div><div>But there are one problem remain, as you can see, the #string with options will become very long; I don&#39;t think it is a pleasure to use such expression except for one time literal. To fix the problem, I propose yet another process instruction:</div><div><br></div><div>#let #<span class="" id=":1th.4" tabindex="-1" style="background:yellow"><span class="" id=":1th.28" tabindex="-1">rex</span></span> = #string(escape: nil)</div><div>#let #mail = #string(escape: &quot;$&quot;, end: &quot;&lt;<span class="" id=":1th.5" tabindex="-1" style="background:yellow"><span class="" id=":1th.29" tabindex="-1">EOF</span></span>&gt;&quot;)</div><div><br></div><div>Now you can write the string as:</div><div><br></div><div>#<span class="" id=":1th.6" tabindex="-1" style="background:yellow"><span class="" id=":1th.30" tabindex="-1">rex</span></span> &quot;^\d+&quot;</div><div><br></div><div>#mail &quot;</div><div>   $(<span class="" id=":1th.7" tabindex="-1" style="background:yellow"><span class="" id=":1th.31" tabindex="-1">username</span></span>),</div><div>   Is it 1358 yet?</div><div>&lt;<span class="" id=":1th.8" tabindex="-1" style="background:yellow"><span class="" id=":1th.32" tabindex="-1">EOF</span></span>&gt;&quot;</div><div><br></div><div>#let should be <span class="" id=":1th.9" tabindex="-1">able</span> to be used with other # process instruction as well, for example, #available, among other things.</div><div><br></div><div>What do you think?</div><div><br></div><div><br></div></div>