NSRegularExpression.escapedPatternForString() unimplemented on Linux


(Pushkar N Kulkarni) #1

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


(Philippe Hausler) #2

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@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Philippe Hausler) #3

_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@in.ibm.com> wrote:

Thank you for the response, Phillippe.

I was wondering if the implementation would be exactly like NSRegularExpression.escapedTemplateForString(_:slight_smile: 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(_:slight_smile: class method?

Regards,
Pushkar N Kulkarni,
IBM Runtimes

"Any sufficiently advanced technology is indistinguishable from magic." - Arthur Clarke

-----phausler@apple.com <mailto:-----phausler@apple.com> wrote: -----
To: Pushkar N Kulkarni/India/IBM@IBMIN
From: Philippe Hausler
Sent by: phausler@apple.com <mailto:phausler@apple.com>
Date: 02/26/2016 08:47PM
Cc: swift-corelibs-dev@swift.org <mailto:swift-corelibs-dev@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@swift.org <mailto:swift-corelibs-dev@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@swift.org <mailto:swift-corelibs-dev@swift.org>
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Pushkar N Kulkarni) #4

Thank you for the response, Phillippe.

I was wondering if the implementation would be exactly like NSRegularExpression.escapedTemplateForString(_:slight_smile: 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(_:slight_smile: class method?

Regards,

Pushkar N Kulkarni,

IBM Runtimes

“Any sufficiently advanced technology is indistinguishable from magic.” - Arthur Clarke

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@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

To: Pushkar N Kulkarni/India/IBM@IBMIN
From: Philippe Hausler
Sent by: phausler@apple.com
Date: 02/26/2016 08:47PM
Cc: swift-corelibs-dev@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.

-----phausler@apple.com wrote: -----


(Pushkar N Kulkarni) #5

Thanks Philippe.

Pushkar N Kulkarni,

IBM Runtimes

“Any sufficiently advanced technology is indistinguishable from magic.” - Arthur Clarke

I have created a pull request - https://github.com/apple/swift-corelibs-foundation/pull/273

_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@in.ibm.com wrote:

Thank you for the response, Phillippe.

I was wondering if the implementation would be exactly like NSRegularExpression.escapedTemplateForString(_:slight_smile: 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(_:slight_smile: class method?

Regards,

Pushkar N Kulkarni,

IBM Runtimes

“Any sufficiently advanced technology is indistinguishable from magic.” - Arthur Clarke

To: Pushkar N Kulkarni/India/IBM@IBMIN
From: Philippe Hausler
Sent by: phausler@apple.com
Date: 02/26/2016 08:47PM
Cc: swift-corelibs-dev@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@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

-----phausler@apple.com wrote: -----

To: Pushkar N Kulkarni/India/IBM@IBMIN
From: Philippe Hausler
Sent by: phausler@apple.com
Date: 02/29/2016 10:40PM
Cc: swift-corelibs-dev@swift.org
Subject: Re: [swift-corelibs-dev] NSRegularExpression.escapedPatternForString() unimplemented on Linux

-----phausler@apple.com wrote: -----