DIP 1027---String Interpolation---Community Review Round 1

Jacob Carlborg doob at me.com
Tue Dec 17 09:03:31 UTC 2019


On Tuesday, 17 December 2019 at 08:55:36 UTC, Jacob Carlborg 
wrote:

> It doesn't need to go directly to a string. Just the end result 
> needs to be a string. In Swift they achieve this by lowering 
> the string interpolation to a set of method calls:
>
> "The time is \(time)."
>
> Is lowered to something like:
>
> var interpolation = 
> MyString.StringInterpolation(literalCapacity: 13,
>                                                  
> interpolationCount: 1)
>
> interpolation.appendLiteral("The time is ")
> interpolation.appendInterpolation(time)
> interpolation.appendLiteral(".")
>
> MyString(stringInterpolation: interpolation)
>
> These methods are overridable to be able to customize the 
> behavior.

With this implementation SwiftUI supports internationalization of 
string literals with interpolation.

--
/Jacob Carlborg


More information about the Digitalmars-d mailing list