[swift-corelibs-dev] NSRegularExpression.firstMatchInString() fails on Linux

Mamatha Busi mamabusi at in.ibm.com
Wed Mar 2 05:57:07 CST 2016


Hello

The following test case, that currently fails on Linux,  is extracted from 
some of the excluded tests inside TestFoundation/TestNSRegularExpression. 

import Foundation

let searchStr = "123"
let testRegex = try NSRegularExpression.init(pattern: 
"a(b|c|d)(x|y|z)*|123", options: [])
let firstMatch = testRegex.firstMatchInString(searchStr, options: [], 
range: NSMakeRange(0,3))

if NSEqualRanges((firstMatch!.rangeAtIndex(1), NSMakeRange(NSNotFound,0)) 
{
    print("Test passed")
} else {
    print("First match first capture range = 
\(NSStringFromRange(firstMatch!.rangeAtIndex(1)))")
    print("Test failed")
}



In the above scenario, no capture group participates in the match. So, 
firstMatch.rangeAtIndex(1) should ideally return range {NSNotFound, 0} but 
the actual returned value is range {-1, 0}. Hence the failure.

Debugging on the CoreFoundation, it is observed that the value -1 is 
coming from 'kCFNotFound' which is defined as -1. On the Foundation side, 
'NSNotFound' is defined with the value of ‘Int.max’ (which must be 
Int32.max and Int64.max on 32 and 64 bit platforms respectively).

There are a couple of queries that I have:

-> Is 'NSNotFound' in Foundation mapped  to 'kCFNotFound'  in 
CoreFoundation?

-> If so, then why do 'NSNotFound' and 'kCFNotFound' have different values 
on the Foundation and CoreFoundation respectively?

Also, I tested by modifying the 'kCFNotFound' value in 
CoreFoundation/Base.subproj/CFBase.h  (See below code snippet):

#if TARGET_RT_64_BIT
static const CFIndex kCFNotFound = LONG_MAX;
#else
static const CFIndex kCFNotFound = INT_MAX;
#endif


With this change the above mentioned test-case passes but a lot of other 
TestFoundation tests seem to fail.

Please provide your comments on the appropriate change that is needed 
here. 

Thank you.

Regards
Mamatha



Mamatha Busi


Java L3 Support

IBM Software Group
 
India Software Labs
 



 



 

e-mail:
mamabusi at in.ibm.com
 

Java Technology India Group
 





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20160302/36a45f91/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 360 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20160302/36a45f91/attachment.gif>


More information about the swift-corelibs-dev mailing list