diff options
Diffstat (limited to 'Source/SPStringAdditions.m')
-rw-r--r-- | Source/SPStringAdditions.m | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index fdad0cff..573c9c73 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -255,4 +255,40 @@ } #endif + +- (NSString *) stringByRemovingCharactersInSet:(NSCharacterSet*) charSet options:(unsigned) mask +{ + NSRange range; + NSMutableString* newString = [NSMutableString string]; + unsigned len = [self length]; + + mask &= ~NSBackwardsSearch; + range = NSMakeRange (0, len); + + while (range.length) + { + NSRange substringRange; + unsigned pos = range.location; + + range = [self rangeOfCharacterFromSet:charSet options:mask range:range]; + if (range.location == NSNotFound) + range = NSMakeRange (len, 0); + + substringRange = NSMakeRange (pos, range.location - pos); + [newString appendString:[self + substringWithRange:substringRange]]; + + range.location += range.length; + range.length = len - range.location; + } + + return newString; +} + + +- (NSString *) stringByRemovingCharactersInSet:(NSCharacterSet*) charSet +{ + return [self stringByRemovingCharactersInSet:charSet options:0]; +} + @end |