diff options
author | avenjamin <avenjamin@gmail.com> | 2009-02-28 20:25:08 +0000 |
---|---|---|
committer | avenjamin <avenjamin@gmail.com> | 2009-02-28 20:25:08 +0000 |
commit | afc8240d2b27fe2d26fb821bdc6ac6dce0b901d9 (patch) | |
tree | bfc7c6437fc55344134224b8d2981e61157072a8 /Source | |
parent | ce5a6e4f3d90dcc775f4d81f19e20c412eb5af23 (diff) | |
download | sequelpro-afc8240d2b27fe2d26fb821bdc6ac6dce0b901d9.tar.gz sequelpro-afc8240d2b27fe2d26fb821bdc6ac6dce0b901d9.tar.bz2 sequelpro-afc8240d2b27fe2d26fb821bdc6ac6dce0b901d9.zip |
Implemented method: componentsSeparatedByCharactersInSet. to be compatible with 10.4+
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMTextView.m | 1 | ||||
-rw-r--r-- | Source/SPStringAdditions.h | 4 | ||||
-rw-r--r-- | Source/SPStringAdditions.m | 33 |
3 files changed, 38 insertions, 0 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 369e9a43..bce2bd4a 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -22,6 +22,7 @@ // Or mail to <lorenz@textor.ch> #import "CMTextView.h" +#import "SPStringAdditions.h" @implementation CMTextView diff --git a/Source/SPStringAdditions.h b/Source/SPStringAdditions.h index d2ac5d4b..4acd748c 100644 --- a/Source/SPStringAdditions.h +++ b/Source/SPStringAdditions.h @@ -26,4 +26,8 @@ + (NSString *)stringForByteSize:(int)byteSize; +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 + - (NSArray *)componentsSeparatedByCharactersInSet:(NSCharacterSet *)set; +#endif + @end diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index a51df693..2916611d 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -66,4 +66,37 @@ return [numberFormatter stringFromNumber:[NSNumber numberWithFloat:size]]; } +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 + // ------------------------------------------------------------------------------- + // componentsSeparatedByCharactersInSet: + // Credit - Greg Hulands <ghulands@mac.com> + // Needed for 10.4+ compatibility + // ------------------------------------------------------------------------------- + - (NSArray *)componentsSeparatedByCharactersInSet:(NSCharacterSet *)set // 10.5 adds this to NSString, but we are 10.4+ + { + NSMutableArray *result = [NSMutableArray array]; + NSScanner *scanner = [NSScanner scannerWithString:self]; + NSString *chunk = nil; + + [scanner setCharactersToBeSkipped:nil]; + BOOL sepFound = [scanner scanCharactersFromSet:set intoString:(NSString **)nil]; // skip any preceding separators + + if (sepFound) { // if initial separator, start with empty component + [result addObject:@""]; + } + + while ([scanner scanUpToCharactersFromSet:set intoString:&chunk]) { + [result addObject:chunk]; + sepFound = [scanner scanCharactersFromSet: set intoString: (NSString **) nil]; + } + + if (sepFound) { // if final separator, end with empty component + [result addObject: @""]; + } + + result = [result copy]; + return [result autorelease]; + } +#endif + @end |