[swift-evolution] Strings in Swift 4
jhull at gbis.com
Fri Jan 20 17:19:06 CST 2017
Perhaps we could separate the proposal from the manifesto, and then use the manifesto to collect future plans as well in all of the areas around string processing (which could later be broken off into smaller proposals), similar to how the Generics manifesto has been working?
My main concern with the Swift 4 process is that there are so many good ideas being thrown about, which are then deferred, but not really captured in a central/organized place… so we keep having the same discussion over and over. Ultimately, I am convinced we need a separate facility/process for brainstorming about future proposals, but in the mean-time having a few manifestos capturing future ideas that we then use as guide posts that we are headed towards is a good step.
> On Jan 20, 2017, at 2:20 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
> on Fri Jan 20 2017, Gwendal Roué <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> One ask - make string interpolation great again?
>> I have a dream, that ExpressibleByStringInterpolation would allow to distinguish literal segments
>> and embedded inputs.
>> Today, the documentation of this protocol  says:
>> "One cookie: $\(price), \(number) cookies: $\(price * number)."
>> // <=>
>> let message = String(stringInterpolation:
>> String(stringInterpolationSegment: "One cookie: $"),
>> String(stringInterpolationSegment: price),
>> String(stringInterpolationSegment: ", "),
>> String(stringInterpolationSegment: number),
>> String(stringInterpolationSegment: " cookies: $"),
>> String(stringInterpolationSegment: price * number),
>> String(stringInterpolationSegment: "."))
>> This means that ExpressibleByStringInterpolation can't distinguish "foo" from `bar` in "foo\(bar)".
>> If this distinction were possible, some nice features could emerge, such as context-sensitive
>> // func render(_ html: HTML)
>> let title = "<script>boom();</script>"
>> render("<h1>\(title)</h1>") // escapes input
>> // func query(_ sql: SQL)
>> let name = "Robert'); DROP TABLE students; --"
>> query("SELECT * FROM students WHERE name = \(name)") // avoids SQL injection
>> Ideally, a solution for multi-line literals (for strings and interpolated strings) would be found,
>> I wish the manifesto would address these topics as well :-)
> This is totally something we want to fix, but as part of a wholesale
> reform of the ExpressibleByXXX protocols. It's outside the scope of the
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution