Swift 4 Multiline strings support


Generate Swift 4 tripple quoted multiline strings instead of string concatenation which is currently used.




Ivan Kochurkin
September 5, 2017, 2:15 PM

Incorrect: actually s4 and s5 are not multiline strings. They are the lines with newline escapes.

But in your sample, they have line breaks.

Alex Petuschak
September 9, 2017, 5:08 PM

0. I think s6 should be rather something like this?

2 spaces should be after the line break, rather than before.

1. IsStringEndsWithSingleBackslash() can check for IsNullOrEmpty(line) to avoid checking if line.Length >= 1

2. ElementAtOrDefault(0) can be replaced with FirstOrDefault(). I.e.:

3. It seems like this code will add 2 bank lines for a Windows style line break (\r\n), which is unlikely but still nice to support.
Test that, consider adding a blank line only for `\n`.

4. Use switch (child.Symbol.Type)
(if you can avoid writing a source line, do it).

5. I prefer `var` here (type name appears in the r-value):

6. Use `+=` here:

7. IsStringEndsWithSingleBackslash() -> EndsWithSingleBackslash()
Maybe just use something like


8. Replace this block with lines.RemoveAll(predicate) ?

9. Can this be a "for" loop i.e. for (int i = 0; i < childTextLength; i++) ?

10. singleline -> singleLine (2 words).

11. I want more blank lines as mentioned here (CONTRIBUTING.md):

7. Add an empty line between (`if`, `while`, `do/while`, `fot`, `foreach`, etc) statement / block and other statements.

12. line.Last() == '
' -> EndsWithOrdinal()

12. This comment looks confusing:

/// <param name="convertEscapedToNewlines">Do not convert \n </param>

maybe "Do not convert \n" -> "Replace \n with line breaks",
and rename the parameter to "convertNewlineEscapeCharacters"?

13. Obj-C string literals should begin with @, unless declaring C style strings (char *):
Fix the unit test.

Alex Petuschak
September 18, 2017, 12:14 PM

1. I've committed another sample query into "Swift4" branch.
This seems to have been converted properly after your initial implementation,
but now the conversion of "query" fails: http://take.ms/yw8gw

2. It seems like the indentation of strings is broken if you convert the same sample to Swift 3:
Only if trivial (takes up to 30 minutes), fix this (in the Develop branch) to make the indentation look same as when converting to Swift 2.

Ivan Kochurkin
September 19, 2017, 8:32 AM

1. I've committed another sample query into "Swift4" branch.

I don't see this sample. The last commit is mine. Can you attach an Objective-C string that converted improperly?

Alex Petuschak
September 19, 2017, 9:15 AM

Pull changes to "Swift4" branch.

should convert to:


Ivan Kochurkin


Alex Petuschak



Git Branch Name


GitHub Issue



Fix versions