Added Some Helpers
This commit is contained in:
@@ -116,6 +116,20 @@
|
|||||||
return [self.location isEqual:aRangePath.location] && self.length == aRangePath.length;
|
return [self.location isEqual:aRangePath.location] && self.length == aRangePath.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *)description
|
||||||
|
{
|
||||||
|
NSMutableString *description = [[NSMutableString alloc] initWithString:@"MPRangePath<location="];
|
||||||
|
if (self.location.length > 0) {
|
||||||
|
[description appendFormat:@"%ld", [self.location indexAtPosition:0]];
|
||||||
|
}
|
||||||
|
for (NSUInteger position = 1; position < self.location.length; position ++) {
|
||||||
|
[description appendFormat:@",%ld", [self.location indexAtPosition:position]];
|
||||||
|
}
|
||||||
|
[description appendFormat:@" length=%ld", self.length];
|
||||||
|
[description appendString:@">"];
|
||||||
|
return description.copy;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - NSCopying
|
#pragma mark - NSCopying
|
||||||
|
|
||||||
- (id)copyWithZone:(NSZone *)zone
|
- (id)copyWithZone:(NSZone *)zone
|
||||||
|
|||||||
@@ -58,4 +58,29 @@
|
|||||||
return [[self indexPathByRemovingLastIndex] indexPathByAddingIndex:lastIndex];
|
return [[self indexPathByRemovingLastIndex] indexPathByAddingIndex:lastIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSIndexPath *)indexPathWithLength:(NSUInteger)length
|
||||||
|
{
|
||||||
|
NSIndexPath *indexPath = [[NSIndexPath alloc] init];
|
||||||
|
for (NSUInteger position = 0; position < length; position++) {
|
||||||
|
indexPath = [indexPath indexPathByAddingIndex:[self indexAtPosition:position]];
|
||||||
|
}
|
||||||
|
return indexPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSIndexPath *)commonIndexPathWith:(NSIndexPath *)indexPath
|
||||||
|
{
|
||||||
|
NSIndexPath *commonPath = [[NSIndexPath alloc] init];
|
||||||
|
NSUInteger length = MIN(self.length, indexPath.length);
|
||||||
|
for (NSUInteger position = 0; position < length; position++) {
|
||||||
|
NSUInteger selfIndex = [self indexAtPosition:position];
|
||||||
|
NSUInteger otherIndex = [indexPath indexAtPosition:position];
|
||||||
|
if (selfIndex == otherIndex) {
|
||||||
|
commonPath = [commonPath indexPathByAddingIndex:selfIndex];
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commonPath;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user