mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Implement NSTextCheckingResult -resultByAdjustingRangesWithOffset:
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34350 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4e79a89139
commit
3b65abba77
3 changed files with 39 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
2011-12-23 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||
|
||||
* Headers/Foundation/NSTextCheckingResult.h:
|
||||
* Source/NSTextCheckingResult.m (-resultByAdjustingRangesWithOffset:):
|
||||
Implement method.
|
||||
|
||||
2011-12-23 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||
|
||||
* 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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue