diff --git a/ChangeLog b/ChangeLog index f73e3d472..d7e247ff4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-12-23 Wolfgang Lux + + * Headers/Foundation/NSTextCheckingResult.h: + * Source/NSTextCheckingResult.m (-resultByAdjustingRangesWithOffset:): + Implement method. + 2011-12-23 Wolfgang Lux * Headers/Foundation/NSTextCheckingResult.h: diff --git a/Headers/Foundation/NSTextCheckingResult.h b/Headers/Foundation/NSTextCheckingResult.h index 80197f280..3ac446d2f 100644 --- a/Headers/Foundation/NSTextCheckingResult.h +++ b/Headers/Foundation/NSTextCheckingResult.h @@ -72,4 +72,6 @@ static const NSTextCheckingType NSTextCheckingTypeRegularExpression = 1ULL<<10; + (NSTextCheckingResult*)regularExpressionCheckingResultWithRanges: (NSRangePointer)ranges count: (NSUInteger)count regularExpression: (NSRegularExpression*)regularExpression; + - (NSRange)rangeAtIndex: (NSUInteger)idx; +- (NSTextCheckingResult *)resultByAdjustingRangesWithOffset: (NSInteger)offset; @end diff --git a/Source/NSTextCheckingResult.m b/Source/NSTextCheckingResult.m index 07a1742d5..3f4c74ca7 100644 --- a/Source/NSTextCheckingResult.m +++ b/Source/NSTextCheckingResult.m @@ -87,6 +87,12 @@ } return [self range]; } + +- (NSTextCheckingResult *)resultByAdjustingRangesWithOffset: (NSInteger)offset +{ + [self subclassResponsibility: _cmd]; + return nil; +} @end @@ -130,5 +136,29 @@ return NSTextCheckingTypeRegularExpression; } -@end +- (NSTextCheckingResult *)resultByAdjustingRangesWithOffset: (NSInteger)offset +{ + NSUInteger i; + GSRegularExpressionCheckingResult *result = + [[GSRegularExpressionCheckingResult new] autorelease]; + result->rangeCount = rangeCount; + result->ranges = calloc(sizeof(NSRange), rangeCount); + for (i = 0; i < rangeCount; i++) + { + NSRange r = ranges[i]; + if ((offset > 0 && NSNotFound - r.location <= offset) || + (offset < 0 && r.location < -offset)) + { + [NSException raise: NSInvalidArgumentException + format: @"Invalid offset %ld for range: %@", + (long)offset, NSStringFromRange(r)]; + } + r.location += offset; + result->ranges[i] = r; + } + ASSIGN(result->regularExpression, regularExpression); + return result; +} + +@end