Menu

#27 rangesForCharacters: return wrong ranges

open
5
2009-03-10
2009-03-10
Anonymous
No

Using RegexKit_0.6.0...

The rangesForCharacters:length:inRange:options: method given the first string should return 1 capture. When given the 2nd string it should return 2 unique. In both cases it returns 2 identical ranges.

const char subjectCString[] = "int\n"; // this returns 2 dublicate ranges
//const char subjectCString[] = "int x;\nfloat z;\n"; // this also returns 2 dublicate ranges
RKRegex *regexObject = [RKRegex regexWithRegexString:@"\\b(int|float)\\b" options:RKCompileNoOptions];
NSRange *captureRanges = NULL;

captureRanges = [regexObject rangesForCharacters:subjectCString length:strlen(subjectCString) inRange:NSMakeRange(0, strlen(subjectCString)) options:RKMatchNoOptions];

if(captureRanges != NULL) {
NSLog(@"Capture count %i",[regexObject captureCount]);
int x;
for(x = 0; x < [regexObject captureCount]; x++) {
NSLog(@"Capture index %d location %u, length %u", x, captureRanges[x].location, captureRanges[x].length);
NSLog(@"NSRange string %@",NSStringFromRange(captureRanges[x]));
}
}

// output of the above test
Capture count 2
Capture index 0 location 0, length 3
NSRange string {0, 3}
Capture index 1 location 0, length 3
NSRange string {0, 3}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.