[swift-evolution] Empower String type with regular expression
davesweeris at mac.com
davesweeris at mac.com
Mon Feb 1 11:10:36 CST 2016
Yeah… that verbal expressions thing looks really cool, but it’s not a substitute for the “real thing”. If we put the testing bit in a protocol, anything that validates text could conform to it and automatically be usable with switches and such:
protocol RegExValidator {
func validateRegEx(_: String) -> Bool
}
func ~= (lhs: String, rhs: RegExValidator) -> Bool {
return rhs.validateRegEx(lhs)
}
func ~= (lhs: RegExValidator, rhs: String) -> Bool {
return lhs.validateRegEx(rhs)
}
- Dave Sweeris
> On Feb 1, 2016, at 02:02, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
>
>
>> On 1 Feb 2016, at 03:48, John Randolph via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>> Perl 6’s regex implementation looks like a logical progression of the grep style as we’ve come to know it over the years, but I’d really like to see Swift go with something like the Verbal Expressions approach.
>>
>> https://github.com/VerbalExpressions/SwiftVerbalExpressions <https://github.com/VerbalExpressions/SwiftVerbalExpressions>
>>
>> All the power is there, but it’s far more readable.
>
> I like the verbal expressions syntax, could we do both? i.e- instead of mapping straight onto NSRegularExpression, could we have a Swift RegularExpression struct that can either take a traditional regular expression, or be constructed via verbal expressions? It might be mapped onto NSRegularExpression behind the scenes, but could let us use both forms easily.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160201/436b08d0/attachment.html>
More information about the swift-evolution
mailing list