[swift-corelibs-dev] NSRegularExpression.escapedPatternForString() unimplemented on Linux

Philippe Hausler phausler at apple.com
Mon Feb 29 11:09:48 CST 2016


_CFRegularExpressionCreateEscapedPattern is exactly the same logic (except it is using CF types instead of NS types) so you can just implement that as a funnel to the CF call and it should do the right thing. The pattern metacharacters are already handled as they are in the objective-c version. The only behavioral differential that I can think of would be in the case of subclassing where a subclass of NSRE would actually call that subclass’s escape method instead of the base implementation; but if someone is brave enough to subclass NSRegularExpression I am certain they can probably work around that differential.

tl;dr just have that class method call _CFRegularExpressionCreateEscapedPattern and it should do what you want.

> On Feb 29, 2016, at 4:07 AM, Pushkar N Kulkarni <pushkar.nk at in.ibm.com> wrote:
> 
> Thank you for the response,  Phillippe.
> 
> I was wondering if the implementation would be exactly like NSRegularExpression.escapedTemplateForString(_:) which simply invokes _CFRegularExpressionCreateEscapedPattern(CFStringRef pattern). Alternatively, is it right to say that "template metacharacters" are a subset of "pattern metacharacters" ?
> 
> If the above isn't right, could you please describe the logic of the objective-C version of the escapedPatternForString(_:) class method?
> 
> Regards,
> Pushkar N Kulkarni,
> IBM Runtimes
>  
> "Any sufficiently advanced technology is indistinguishable from magic." - Arthur Clarke
> 
> 
> -----phausler at apple.com <mailto:-----phausler at apple.com> wrote: -----
> To: Pushkar N Kulkarni/India/IBM at IBMIN
> From: Philippe Hausler 
> Sent by: phausler at apple.com <mailto:phausler at apple.com>
> Date: 02/26/2016 08:47PM
> Cc: swift-corelibs-dev at swift.org <mailto:swift-corelibs-dev at swift.org>
> Subject: Re: [swift-corelibs-dev] NSRegularExpression.escapedPatternForString() unimplemented on Linux
> 
> To be honest I just didn’t get around to implementing that specific method in my initial implementation. There is a CF function that does that which could be wired up to provide a nearly identical backing to it. 
> 
> CFStringRef _CFRegularExpressionCreateEscapedPattern(CFStringRef pattern)
> 
> should give you a good starting point to implement the NSRegularExpression side that should follow the same logic as the objective-c version.
> 
>> On Feb 26, 2016, at 3:28 AM, Pushkar N Kulkarni via swift-corelibs-dev <swift-corelibs-dev at swift.org <mailto:swift-corelibs-dev at swift.org>> wrote:
>> 
>> Hello, 
>> 
>> I have a query regarding NSRegularExpression. I can see that the class method escapedPatternForString(),  that escapes all characters in a string which could be treated as metacharacters, is unimplemented as per the latest dev snapshot for Linux.
>> 
>> Welcome to Swift version 3.0-dev (LLVM f95d47afa7, Clang f66c5bb67b, Swift b745691a38). Type :help for assistance.
>> 
>>   1> import Foundation
>> 
>>   2> NSRegularExpression.escapedPatternForString("a+b")
>> 
>> fatal error: escapedPatternForString is not yet implemented: file Foundation/NSRegularExpression.swift, line 84
>> 
>> 
>> However, I see that this method is available on Swift 2.2-dev for OS X. 
>> 
>> Could someone please tell me the rationale behind having it unimplemented for Linux? Were there any Linux-specific obstacles implementing it? We would be glad to contribute here.
>> 
>> Thanks in advance.
>> 
>> Pushkar N Kulkarni
>> IBM Runtimes
>>  
>>  
>> "Any sufficiently advanced technology is indistinguishable from magic." - Arthur Clarke
>> 
>> _______________________________________________
>> swift-corelibs-dev mailing list
>> swift-corelibs-dev at swift.org <mailto:swift-corelibs-dev at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-corelibs-dev <https://lists.swift.org/mailman/listinfo/swift-corelibs-dev>
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20160229/49f643db/attachment.html>


More information about the swift-corelibs-dev mailing list