[swift-evolution] multi-line string literals

Paul Cantrell cantrell at pobox.com
Thu Dec 10 23:50:38 CST 2015


The <<- only does that for the EOS terminator, not for every line of the string:

$ irb
2.2.0 :001 >     string = <<-EOS
2.2.0 :002">       gone is music
2.2.0 :003">       yet you sing
2.2.0 :004">     EOS
 => "      gone is music\n      yet you sing\n" 

(Ruby 2.2)

> On Dec 10, 2015, at 11:45 PM, Travis Tilley <ttilley at gmail.com> wrote:
> 
> The ruby <<- heredoc syntax, unlike the << heredoc syntax, will strip indentation if necessary. Technically, it searches for the "least indented line" in the whole string, and removes exactly that amount from each line. So yes, the indentation problem -is- solved in ruby (though it might break entirely if you have empty lines, since the least indented line has no indentation).
> 
> 
> On Fri, Dec 11, 2015 at 12:36 AM, Paul Cantrell <cantrell at pobox.com <mailto:cantrell at pobox.com>> wrote:
> In Ruby in the wild, off the top of my head and totally unscientifically, the most widely-used flavors I’ve seen are the heredoc with interpolation and terminator indentation:
> 
>     string = <<-EOS
>       gone is music
>       yet you sing
>     EOS
>  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151210/5d967228/attachment.html>


More information about the swift-evolution mailing list