mirror of
https://github.com/transmission/transmission
synced 2025-03-04 10:38:13 +00:00
roll my own method to separate a string into components
This commit is contained in:
parent
95126c5505
commit
2389bbd49b
1 changed files with 22 additions and 2 deletions
|
@ -184,8 +184,28 @@
|
|||
|
||||
- (NSArray *) betterComponentsSeparatedByCharactersInSet: (NSCharacterSet *) separator
|
||||
{
|
||||
NSMutableArray * components = [NSMutableArray arrayWithArray: [self componentsSeparatedByCharactersInSet: separator]];
|
||||
[components removeObject: @""];
|
||||
NSMutableArray * components = [NSMutableArray array];
|
||||
|
||||
for (NSUInteger i = 0; i < [self length];)
|
||||
{
|
||||
const NSRange range = [self rangeOfCharacterFromSet: separator options: 0 range: NSMakeRange(i, [self length]-i)];
|
||||
|
||||
if (range.location != i)
|
||||
{
|
||||
NSUInteger length;
|
||||
if (range.location == NSNotFound)
|
||||
length = [self length] - i;
|
||||
else
|
||||
length = range.location - i;
|
||||
[components addObject: [self substringWithRange: NSMakeRange(i, length)]];
|
||||
|
||||
if (range.location == NSNotFound)
|
||||
break;
|
||||
i += length + range.length;
|
||||
}
|
||||
}
|
||||
NSLog(@"%@", components);
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue