From 2c8e10b58c81bf1170d3ed8df82b606f0815285f Mon Sep 17 00:00:00 2001 From: Joseph Spiros Date: Mon, 4 Apr 2005 20:38:10 +0000 Subject: [PATCH] Adding category to NSString that provides the functionality previously provided by ITCarbonSupport functions. Those functions now call through to the new methods on NSString. I also fixed a few coding errors in ITCategory-NSBundle, and removed ITCategory-NSArray. --- ITCarbonSupport.h | 4 +- ITCarbonSupport.m | 12 ++--- ITCategory-NSArray.h | 19 -------- ITCategory-NSArray.m | 39 ----------------- ITCategory-NSBundle.m | 6 +-- ITCategory-NSString.h | 21 +++++++++ ITCategory-NSString.m | 24 ++++++++++ ITFoundation.h | 2 +- ITFoundation.xcode/project.pbxproj | 70 +++++++++++++++--------------- 9 files changed, 90 insertions(+), 107 deletions(-) delete mode 100644 ITCategory-NSArray.h delete mode 100644 ITCategory-NSArray.m create mode 100644 ITCategory-NSString.h create mode 100644 ITCategory-NSString.m diff --git a/ITCarbonSupport.h b/ITCarbonSupport.h index 7f0442a..04df507 100644 --- a/ITCarbonSupport.h +++ b/ITCarbonSupport.h @@ -3,7 +3,9 @@ * ITCarbonSupport.h * * Utility functions to convert between FourCharCodes/OSTypes/ResTypes and - * NSStrings. + * NSStrings. These only call through to the methods implemented by + * the ITFoundationCategory on NSString, and those methods are recommended + * for all new projects needing this functionality. * * Copyright (c) 2005 by iThink Software. * All Rights Reserved. diff --git a/ITCarbonSupport.m b/ITCarbonSupport.m index 31d25cd..23b6f69 100644 --- a/ITCarbonSupport.m +++ b/ITCarbonSupport.m @@ -1,16 +1,10 @@ #import "ITCarbonSupport.h" +#import "ITCategory-NSString.h" NSString *NSStringFromFourCharCode(unsigned long code) { - return [NSString stringWithFormat:@"%.4s", &code]; + return [NSString stringWithFourCharCode:code]; } unsigned long FourCharCodeFromNSString(NSString *string) { - const unsigned char *c_s = [string UTF8String]; - unsigned long tmp = *c_s++; - tmp <<= 8; - tmp |= *c_s++; - tmp <<= 8; - tmp |= *c_s++; - tmp <<= 8; - return tmp |= *c_s++; + return [string fourCharCode]; } \ No newline at end of file diff --git a/ITCategory-NSArray.h b/ITCategory-NSArray.h deleted file mode 100644 index ae0f053..0000000 --- a/ITCategory-NSArray.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * ITFoundation - * ITCategory-NSArray.h - * - * Copyright (c) 2005 by iThink Software. - * All Rights Reserved. - * - * $Id$ - * - */ - -#import - -@interface NSArray (ITFoundationCategory) - -- (NSArray *)objectsForKey:(NSString *)key; -- (BOOL)containsString:(NSString *)string; - -@end \ No newline at end of file diff --git a/ITCategory-NSArray.m b/ITCategory-NSArray.m deleted file mode 100644 index 13aeb0c..0000000 --- a/ITCategory-NSArray.m +++ /dev/null @@ -1,39 +0,0 @@ -#import "ITCategory-NSArray.h" - -@implementation NSArray (ITFoundationCategory) - -- (NSArray *)objectsForKey:(NSString *)key { - NSMutableArray *array = [[[NSMutableArray alloc] initWithCapacity:[self count]] autorelease]; - NSEnumerator *enumerator = [self objectEnumerator]; - id anItem; - - while ( (anItem = [enumerator nextObject]) ) { - - id itemObject = [anItem objectForKey:key]; - - if ( itemObject ) { - [array addObject:itemObject]; - } else { - [array addObject:[NSNull null]]; - } - } - - return array; -} - -- (BOOL)containsString:(NSString *)string { - NSEnumerator *enumerator = [self objectEnumerator]; - id anItem; - BOOL result = NO; - - while ( (anItem = [enumerator nextObject]) ) { - - if ( [anItem isEqual:string] ) { - result = YES; - } - } - - return result; -} - -@end \ No newline at end of file diff --git a/ITCategory-NSBundle.m b/ITCategory-NSBundle.m index 28f587f..fdc2151 100644 --- a/ITCategory-NSBundle.m +++ b/ITCategory-NSBundle.m @@ -11,7 +11,7 @@ [frameworksPaths addObject:[[self mainBundle] privateFrameworksPath]]; [frameworksPaths addObject:[[self mainBundle] sharedFrameworksPath]]; - while (libraryPath = [libraryEnumerator nextObject]) { + while ((libraryPath = [libraryEnumerator nextObject])) { [frameworksPaths addObject:[libraryPath stringByAppendingPathComponent:@"Frameworks"]]; [frameworksPaths addObject:[libraryPath stringByAppendingPathComponent:@"PrivateFrameworks"]]; } @@ -19,12 +19,12 @@ NSEnumerator *frameworksEnumerator = [frameworksPaths objectEnumerator]; NSString *frameworksPath; - while (frameworksPath = [frameworksEnumerator nextObject]) { + while ((frameworksPath = [frameworksEnumerator nextObject])) { NSArray *frameworkPaths = [NSBundle pathsForResourcesOfType:@"framework" inDirectory:frameworksPath]; NSEnumerator *frameworkEnumerator = [frameworkPaths objectEnumerator]; NSString *frameworkPath; - while (frameworkPath = [frameworkEnumerator nextObject]) { + while ((frameworkPath = [frameworkEnumerator nextObject])) { NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkPath]; if (frameworkBundle && [[frameworkBundle bundleIdentifier] isEqualToString:frameworkIdentifier]) { return frameworkBundle; diff --git a/ITCategory-NSString.h b/ITCategory-NSString.h new file mode 100644 index 0000000..a0429f0 --- /dev/null +++ b/ITCategory-NSString.h @@ -0,0 +1,21 @@ +/* + * ITFoundation + * ITCategory-NSString.h + * + * Copyright (c) 2005 by iThink Software. + * All Rights Reserved. + * + * $Id$ + * + */ + +#import + +@interface NSString (ITFoundationCategory) + ++ (id)stringWithFourCharCode:(unsigned long)fourCharCode; + +- (id)initWithFourCharCode:(unsigned long)fourCharCode; +- (unsigned long)fourCharCode; + +@end \ No newline at end of file diff --git a/ITCategory-NSString.m b/ITCategory-NSString.m new file mode 100644 index 0000000..fd036ae --- /dev/null +++ b/ITCategory-NSString.m @@ -0,0 +1,24 @@ +#import "ITCategory-NSString.h" + +@implementation NSString (ITFoundationCategory) + ++ (id)stringWithFourCharCode:(unsigned long)fourCharCode { + return [[[self alloc] initWithFourCharCode:fourCharCode] autorelease]; +} + +- (id)initWithFourCharCode:(unsigned long)fourCharCode { + return [self initWithFormat:@"%.4s", &fourCharCode]; +} + +- (unsigned long)fourCharCode { + const unsigned char *c_s = [self UTF8String]; + unsigned long tmp = *c_s++; + tmp <<= 8; + tmp |= *c_s++; + tmp <<= 8; + tmp |= *c_s++; + tmp <<= 8; + return tmp |= *c_s++; +} + +@end \ No newline at end of file diff --git a/ITFoundation.h b/ITFoundation.h index f5f7529..d7f63ab 100644 --- a/ITFoundation.h +++ b/ITFoundation.h @@ -19,5 +19,5 @@ #import #import -#import +#import #import \ No newline at end of file diff --git a/ITFoundation.xcode/project.pbxproj b/ITFoundation.xcode/project.pbxproj index 299d9fb..3bf9213 100644 --- a/ITFoundation.xcode/project.pbxproj +++ b/ITFoundation.xcode/project.pbxproj @@ -161,8 +161,8 @@ 7C058DF8072F10530082E1E9, 7CB02EB407D049BB00959EA0, 7CB02EB507D049BB00959EA0, - 2AB93A3005705A0C007E748F, - 2AB93A3105705A0C007E748F, + 7C0462070801DC3700433407, + 7C0462080801DC3700433407, 7C2D93BD07C2FD6700A487A9, 7C2D93BE07C2FD6700A487A9, ); @@ -171,37 +171,6 @@ refType = 4; sourceTree = ""; }; - 2AB93A3005705A0C007E748F = { - fileEncoding = 4; - isa = PBXFileReference; - lastKnownFileType = sourcecode.c.h; - path = "ITCategory-NSArray.h"; - refType = 4; - sourceTree = ""; - }; - 2AB93A3105705A0C007E748F = { - fileEncoding = 4; - isa = PBXFileReference; - lastKnownFileType = sourcecode.c.objc; - path = "ITCategory-NSArray.m"; - refType = 4; - sourceTree = ""; - }; - 2AB93A3205705A0C007E748F = { - fileRef = 2AB93A3005705A0C007E748F; - isa = PBXBuildFile; - settings = { - ATTRIBUTES = ( - Public, - ); - }; - }; - 2AB93A3305705A0C007E748F = { - fileRef = 2AB93A3105705A0C007E748F; - isa = PBXBuildFile; - settings = { - }; - }; //2A0 //2A1 //2A2 @@ -379,6 +348,37 @@ //7C2 //7C3 //7C4 + 7C0462070801DC3700433407 = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = "ITCategory-NSString.h"; + refType = 4; + sourceTree = ""; + }; + 7C0462080801DC3700433407 = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = "ITCategory-NSString.m"; + refType = 4; + sourceTree = ""; + }; + 7C0462090801DC3700433407 = { + fileRef = 7C0462070801DC3700433407; + isa = PBXBuildFile; + settings = { + ATTRIBUTES = ( + Public, + ); + }; + }; + 7C04620A0801DC3700433407 = { + fileRef = 7C0462080801DC3700433407; + isa = PBXBuildFile; + settings = { + }; + }; 7C058DF7072F10530082E1E9 = { fileEncoding = 4; isa = PBXFileReference; @@ -639,12 +639,12 @@ 8DC2EF510486A6940098B216, 7CA50D7E054E7C600074E1D9, 7CA50B31054E77A00074E1D9, - 2AB93A3205705A0C007E748F, 7C97DC2E05B614300013E85F, 3D97137F05D9FBF40033607F, 7C058DF9072F10530082E1E9, 7C2D93BF07C2FD6700A487A9, 7CB02EB607D049BB00959EA0, + 7C0462090801DC3700433407, ); isa = PBXHeadersBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -673,12 +673,12 @@ buildActionMask = 2147483647; files = ( 7CA50B32054E77A00074E1D9, - 2AB93A3305705A0C007E748F, 7C97DC2F05B614300013E85F, 3D97138105D9FBFA0033607F, 7C058DFA072F10530082E1E9, 7C2D93C007C2FD6700A487A9, 7CB02EB707D049BB00959EA0, + 7C04620A0801DC3700433407, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; -- 2.20.1