From 5ccc63c882558790e50f8b56e37ac1f96f0252f6 Mon Sep 17 00:00:00 2001 From: wlux Date: Fri, 23 Dec 2011 16:49:23 +0000 Subject: [PATCH] Implement NSTextCheckingResult -resultByAdjustingRangesWithOffset: git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34350 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 6 +++++ Headers/Foundation/NSTextCheckingResult.h | 2 ++ Source/NSTextCheckingResult.m | 32 ++++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) 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