Skip to content

Proposal for multi-line string literal syntax. #631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 6, 2017

Conversation

johnno1962
Copy link
Contributor

@johnno1962 johnno1962 commented Mar 7, 2017

Originally discussed in pull request #322 and on Swift evolution this PR puts forward a single proposal as suggested by coments on the previous PR for multi-line string literals now it is in scope for Swift 4 stage 2. The implementation has been explored in a previous pull request swiftlang/swift#2275 and is a relatively minor change if agreement on the approach to take could be reached.

@DevAndArtist
Copy link
Contributor

DevAndArtist commented Mar 8, 2017

+1 for Continuation quotes, because it's more precise and solves issues with the indention for both the literal and its multiline content.

I also wanted to add a note that one could possibly use use strings in general like this:

let multilineString: String = "123""__456__" // Multiline literal in a single line (fixit?)
     "__789__" // replace any underscore with space characters
     "_____0_" // precise control about pre- and post-space-characters

// Multiline literal in a single line allows comments in between
let otherString = "\(someInstance)" /* comment */ "text \(someOtherInstance) text"

@DevAndArtist
Copy link
Contributor

DevAndArtist commented Mar 28, 2017

Or using the escaping character, similar to Javascript:

let multilineString: String = "123__456__\ // indicates there is another part of the string on the next line
                              "__789_____\ // aways starts with `"` and ends with either `\` or `"`
                              "_____0_" // precise control about pre- and post-space-characters

let otherString = "\(someInstance)\ /* only comments are allowed in between */ "text \(someOtherInstance) text"

@jckarter jckarter merged commit d2949e6 into swiftlang:master Apr 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants