<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 3, 2016, at 10:22 AM, Tony Parker via swift-corelibs-dev <<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Hi Mamatha,</span><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Mar 2, 2016, at 3:57 AM, Mamatha Busi via swift-corelibs-dev <<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><font size="2" face="sans-serif" class="">Hello</font><br class=""><br class=""><font size="2" face="sans-serif" class="">The following test case, that currently fails on Linux, is extracted from some of the excluded tests inside TestFoundation/TestNSRegularExpression.<span class="Apple-converted-space"> </span></font><br class=""><br class=""><font size="2" face="sans-serif" class="">import Foundation</font><br class=""><br class=""><font size="2" face="sans-serif" class="">let searchStr = "123"</font><br class=""><font size="2" face="sans-serif" class="">let testRegex = try NSRegularExpression.init(pattern: "a(b|c|d)(x|y|z)*|123", options: [])</font><br class=""><font size="2" face="sans-serif" class="">let firstMatch = testRegex.firstMatchInString(searchStr, options: [], range: NSMakeRange(0,3))</font><br class=""><br class=""><font size="2" face="sans-serif" class="">if NSEqualRanges((firstMatch!.rangeAtIndex(1), NSMakeRange(NSNotFound,0)) {</font><br class=""><font size="2" face="sans-serif" class=""> print("Test passed")</font><br class=""><font size="2" face="sans-serif" class="">} else {</font><br class=""><font size="2" face="sans-serif" class=""> print("First match first capture range = \(NSStringFromRange(firstMatch!.rangeAtIndex(1)))")</font><br class=""><font size="2" face="sans-serif" class=""> print("Test failed")</font><br class=""><font size="2" face="sans-serif" class="">}</font><br class=""><br class=""><br class=""><br class=""><font size="2" face="sans-serif" class="">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.</font><br class=""><br class=""><font size="2" face="sans-serif" class="">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).</font><br class=""><br class=""><font size="2" face="sans-serif" class="">There are a couple of queries that I have:</font><br class=""><br class=""><font size="2" face="sans-serif" class="">-> Is 'NSNotFound' in Foundation mapped to 'kCFNotFound' in CoreFoundation?</font><br class=""><br class=""></div></blockquote><blockquote type="cite" class=""><div class=""><font size="2" face="sans-serif" class="">-> If so, then why do 'NSNotFound' and 'kCFNotFound' have different values on the Foundation and CoreFoundation respectively?</font><br class=""><br class=""></div></blockquote><div class=""><br class=""></div>They don’t have the same value; we translate it manually in most places.</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><font size="2" face="sans-serif" class="">Also, I tested by modifying the 'kCFNotFound' value in CoreFoundation/Base.subproj/CFBase.h (See below code snippet):</font><br class=""><br class=""><font size="2" face="sans-serif" class="">#if TARGET_RT_64_BIT</font><br class=""><font size="2" face="sans-serif" class="">static const CFIndex kCFNotFound = LONG_MAX;</font><br class=""><font size="2" face="sans-serif" class="">#else</font><br class=""><font size="2" face="sans-serif" class="">static const CFIndex kCFNotFound = INT_MAX;</font><br class=""><font size="2" face="sans-serif" class="">#endif</font><br class=""><br class=""><br class=""><font size="2" face="sans-serif" class="">With this change the above mentioned test-case passes but a lot of other TestFoundation tests seem to fail.</font><br class=""><br class=""><font size="2" face="sans-serif" class="">Please provide your comments on the appropriate change that is needed here.<span class="Apple-converted-space"> </span></font><br class=""><br class=""><font size="2" face="sans-serif" class="">Thank you.</font><br class=""></div></blockquote><div class=""><br class=""></div>I think we probably just need to check the result from the CF function and translate it into an NSNotFound in this one particular case.</div></div></div></blockquote><div><br class=""></div><div>I think the problem in this case is that we fetch a buffer of CFRanges and pass that to the result creation.</div><div><br class=""></div><div>ranges: UnsafeMutablePointer<CFRange></div><div>...</div><div>let result = NSTextCheckingResult.regularExpressionCheckingResultWithRanges(NSRangePointer(ranges), count: count, regularExpression: matcher.regex)</div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><br class=""></div><div class="">Thanks,</div><div class="">- Tony</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><br class=""><font size="2" face="sans-serif" class="">Regards</font><br class=""><font size="2" face="sans-serif" class="">Mamatha</font><br class=""><table width="600" class="" style="border-collapse: collapse;"><tbody class=""><tr height="8" class=""><td width="600" colspan="4" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><hr class=""></td></tr><tr height="8" class=""><td width="600" colspan="4" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"></td></tr><tr height="8" class=""><td width="350" colspan="2" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><font size="2" face="Arial" class=""><b class="">Mamatha Busi</b></font></td><td width="129" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"></td><td width="119" rowspan="3" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><div align="right" class=""><span id="cid:_1_10971D9C109719C80041A24165257F6A" class=""><Mail Attachment.gif></span></div></td></tr><tr height="8" class=""><td width="350" colspan="2" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><font size="1" color="#5f5f5f" face="Arial" class="">Java L3 Support</font></td><td width="129" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"></td></tr><tr height="8" class=""><td width="350" colspan="2" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><font size="1" color="#5f5f5f" face="Arial" class="">IBM Software Group</font></td><td width="129" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><font size="1" color="#5f5f5f" face="Arial" class=""> </font></td></tr><tr height="8" class=""><td width="350" colspan="2" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><font size="1" color="#5f5f5f" face="Arial" class="">India Software Labs</font></td><td width="129" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><font size="1" color="#5f5f5f" face="Arial" class=""> </font></td><td width="119" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"></td></tr><tr height="8" class=""><td width="75" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"></td><td width="275" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"></td><td width="129" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><font size="1" color="#5f5f5f" face="Arial" class=""> </font></td><td width="119" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"></td></tr><tr height="8" class=""><td width="75" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"></td><td width="275" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"></td><td width="129" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><font size="1" color="#5f5f5f" face="Arial" class=""> </font></td><td width="119" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"></td></tr><tr height="8" class=""><td width="75" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><font size="1" color="#5f5f5f" face="Arial" class="">e-mail:</font></td><td width="275" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><font size="1" color="#5f5f5f" face="Arial" class=""><a href="mailto:mamabusi@in.ibm.com" class="">mamabusi@in.ibm.com</a></font></td><td width="129" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><font size="1" color="#5f5f5f" face="Arial" class=""> </font></td><td width="119" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"></td></tr><tr height="8" class=""><td width="350" colspan="2" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><a href="http://bit.ly/a7KpQj" class=""><font size="1" color="blue" face="Arial" class=""><u class="">Java Technology India Group</u></font></a></td><td width="129" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><font size="1" color="#5f5f5f" face="Arial" class=""> </font></td><td width="119" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"></td></tr><tr height="8" class=""><td width="600" colspan="4" class="" style="border: 0px none rgb(0, 0, 0); padding: 0px;"><hr class=""></td></tr></tbody></table><br class=""><font size="2" face="sans-serif" class=""><br class=""></font><br class="">_______________________________________________<br class="">swift-corelibs-dev mailing list<br class=""><a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-corelibs-dev" class="">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev</a><br class=""></div></blockquote></div><br class=""></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-corelibs-dev mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-corelibs-dev@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-corelibs-dev@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-corelibs-dev" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev</a></div></blockquote></div><br class=""></body></html>