Swift.org blog: Behind the Proposal — SE-0200 Enhancing String Literals Delimiters to Support Raw Text

swiftorg-blog

(Ted Kremenek) #1

There is a new Swift.org blog post titled "Behind the Proposal — SE-0200 Enhancing String Literals Delimiters to Support Raw Text", authored by @Erica_Sadun, that is available to read!

Please feel free to use this thread to post questions/comments!


#2

Direct link to the blog post:

Behind the Proposal — SE-0200 Enhancing String Literals Delimiters to Support Raw Text


#3

@Erica_Sadun, that was a beautiful write-up! The background information is comprehensive, without being too dense, and the examples demonstrate the feature perfectly.

Thank you very much for the perfect primer on Swift's medium-rare string implementation :slight_smile:


#4

Very nice post!

Are "`…`" and "any number of `" in Syntax - Language(s) table new esoteric programming languages, or just leftover comments not cleaned up in the editing process? :P


(Adrian Zubarev) #5

The blog post shows examples such as

let z = """ // Multiline
    Hello
    """
let a = #""" // Multiline with pound
    Hello
    """#

The first one is ill-formed in Swift 4.2 and the compiler emits an error Multi-line string literal content must begin on a new line. Has this changed in Swift 5 or is this a small mistake? cc @Erica_Sadun


(Erica Sadun) #6

Just delete or move the comments and they'll work. I'll ask @tkremenek if he can place the comments before each example instead of to the side.

Thank you for this catch.


(Erica Sadun) #7

These differentiate the Go and D approach from the Java one:

Go:

Raw string literals are character sequences between back quotes, as in foo. Within the quotes, any character may appear except back quote. The value of a raw string literal is the string composed of the uninterpreted (implicitly UTF-8-encoded) characters between the quotes; in particular, backslashes have no special meaning and the string may contain newlines. Carriage return characters ('\r') inside raw string literals are discarded from the raw string value.

Dlang:

It is also possible to use raw strings to minimize laborious escaping of reserved symbols. Raw strings can be declared using either backticks ( ... ) or the r(aw)-prefix (r" ... ").

In Java, you can use any number of backticks:

A raw string literal consists of one or more characters enclosed in sequences of backticks ` (\u0060) (backquote, accent grave). A raw string literal opens with a sequence of one or more backticks. The raw string literal closes when a backtick sequence is encountered of equal length as opened the raw string literal. Any other sequence of backticks is treated as part of the string body.