mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +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
be918f5589
commit
5ccc63c882
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>
|
2011-12-23 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||||
|
|
||||||
* Headers/Foundation/NSTextCheckingResult.h:
|
* Headers/Foundation/NSTextCheckingResult.h:
|
||||||
|
|
|
@ -72,4 +72,6 @@ static const NSTextCheckingType NSTextCheckingTypeRegularExpression = 1ULL<<10;
|
||||||
+ (NSTextCheckingResult*)regularExpressionCheckingResultWithRanges: (NSRangePointer)ranges
|
+ (NSTextCheckingResult*)regularExpressionCheckingResultWithRanges: (NSRangePointer)ranges
|
||||||
count: (NSUInteger)count
|
count: (NSUInteger)count
|
||||||
regularExpression: (NSRegularExpression*)regularExpression;
|
regularExpression: (NSRegularExpression*)regularExpression;
|
||||||
|
- (NSRange)rangeAtIndex: (NSUInteger)idx;
|
||||||
|
- (NSTextCheckingResult *)resultByAdjustingRangesWithOffset: (NSInteger)offset;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -87,6 +87,12 @@
|
||||||
}
|
}
|
||||||
return [self range];
|
return [self range];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSTextCheckingResult *)resultByAdjustingRangesWithOffset: (NSInteger)offset
|
||||||
|
{
|
||||||
|
[self subclassResponsibility: _cmd];
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,5 +136,29 @@
|
||||||
return NSTextCheckingTypeRegularExpression;
|
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…
Add table
Add a link
Reference in a new issue