Last active
February 17, 2016 16:15
-
-
Save magneticrob/39fdc2aa212a6595f0a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSArray *)inbetweenRangesForArrayOfRanges:(NSArray *)arrayOfRanges forString:(NSString *)string | |
{ | |
NSMutableArray *ranges = @[].mutableCopy; | |
for (int i = 0; i < arrayOfRanges.count; i++) | |
{ | |
// grab the first range | |
NSRange currentRange = [arrayOfRanges[i] rangeValue]; | |
// add it to our return object | |
[ranges addObject:[NSValue valueWithRange:currentRange]]; | |
// if the first range starts at 0, or if the length of the range is the entire string, bail out | |
if (currentRange.location != 0 || currentRange.length == string.length) | |
{ | |
if (i == 0) // first URL starts later in the string | |
{ | |
// Make the range up in between loc 0 and the start of the first range | |
NSRange newRange = NSMakeRange(0, currentRange.location - 1); | |
[ranges addObject:[NSValue valueWithRange:newRange]]; | |
} | |
else // otherwise lets get going | |
{ | |
NSRange previousRange = [arrayOfRanges[i - 1] rangeValue]; | |
NSUInteger index = (previousRange.location + 1) + previousRange.length; | |
NSUInteger length = currentRange.location - (previousRange.length + 1); | |
NSRange newRange = NSMakeRange(index, length); | |
[ranges addObject:[NSValue valueWithRange:newRange]]; | |
} | |
} | |
} | |
return ranges; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment