[swift-evolution] Strings in Swift 4
Dave Abrahams
dabrahams at apple.com
Fri Jan 20 18:56:28 CST 2017
on Fri Jan 20 2017, Jonathan Hull <swift-evolution at swift.org> wrote:
> 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?
Yes, that's the idea. I guess my point is that while we want to flesh
these areas out, and they should go in the manifesto, I think now is the
wrong time to dive into the details. We should leave the necessary
notes and placeholders in the manifesto so that we'll be able to come
back later and fill them in.
> 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.
>
> Thanks,
> Jon
>
>> 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 [1] 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
>>> escaping:
>>>
>>> // 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,
>>> too.
>>>
>>> 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
>> manifesto.
>>
>> --
>> -Dave
>>
>> _______________________________________________
>> 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>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
--
-Dave
More information about the swift-evolution
mailing list