Adding category to NSString that provides the functionality previously v1.0
authorJoseph Spiros <joseph.spiros@ithinksw.com>
Mon, 4 Apr 2005 20:38:10 +0000 (20:38 +0000)
committerJoseph Spiros <joseph.spiros@ithinksw.com>
Mon, 4 Apr 2005 20:38:10 +0000 (20:38 +0000)
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
ITCarbonSupport.m
ITCategory-NSArray.h [deleted file]
ITCategory-NSArray.m [deleted file]
ITCategory-NSBundle.m
ITCategory-NSString.h [new file with mode: 0644]
ITCategory-NSString.m [new file with mode: 0644]
ITFoundation.h
ITFoundation.xcode/project.pbxproj

index 7f0442a..04df507 100644 (file)
@@ -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.
index 31d25cd..23b6f69 100644 (file)
@@ -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 (file)
index ae0f053..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- *     ITFoundation
- *     ITCategory-NSArray.h
- *
- *     Copyright (c) 2005 by iThink Software.
- *     All Rights Reserved.
- *
- *     $Id$
- *
- */
-
-#import <Foundation/Foundation.h>
-
-@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 (file)
index 13aeb0c..0000000
+++ /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
index 28f587f..fdc2151 100644 (file)
@@ -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"]];
        }
        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 (file)
index 0000000..a0429f0
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ *     ITFoundation
+ *     ITCategory-NSString.h
+ *
+ *     Copyright (c) 2005 by iThink Software.
+ *     All Rights Reserved.
+ *
+ *     $Id$
+ *
+ */
+
+#import <Foundation/Foundation.h>
+
+@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 (file)
index 0000000..fd036ae
--- /dev/null
@@ -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
index f5f7529..d7f63ab 100644 (file)
@@ -19,5 +19,5 @@
 
 #import <ITFoundation/ITCategory-NSObject.h>
 #import <ITFoundation/ITCategory-NSProxy.h>
-#import <ITFoundation/ITCategory-NSArray.h>
+#import <ITFoundation/ITCategory-NSString.h>
 #import <ITFoundation/ITCategory-NSBundle.h>
\ No newline at end of file
index 299d9fb..3bf9213 100644 (file)
                                7C058DF8072F10530082E1E9,
                                7CB02EB407D049BB00959EA0,
                                7CB02EB507D049BB00959EA0,
-                               2AB93A3005705A0C007E748F,
-                               2AB93A3105705A0C007E748F,
+                               7C0462070801DC3700433407,
+                               7C0462080801DC3700433407,
                                7C2D93BD07C2FD6700A487A9,
                                7C2D93BE07C2FD6700A487A9,
                        );
                        refType = 4;
                        sourceTree = "<group>";
                };
-               2AB93A3005705A0C007E748F = {
-                       fileEncoding = 4;
-                       isa = PBXFileReference;
-                       lastKnownFileType = sourcecode.c.h;
-                       path = "ITCategory-NSArray.h";
-                       refType = 4;
-                       sourceTree = "<group>";
-               };
-               2AB93A3105705A0C007E748F = {
-                       fileEncoding = 4;
-                       isa = PBXFileReference;
-                       lastKnownFileType = sourcecode.c.objc;
-                       path = "ITCategory-NSArray.m";
-                       refType = 4;
-                       sourceTree = "<group>";
-               };
-               2AB93A3205705A0C007E748F = {
-                       fileRef = 2AB93A3005705A0C007E748F;
-                       isa = PBXBuildFile;
-                       settings = {
-                               ATTRIBUTES = (
-                                       Public,
-                               );
-                       };
-               };
-               2AB93A3305705A0C007E748F = {
-                       fileRef = 2AB93A3105705A0C007E748F;
-                       isa = PBXBuildFile;
-                       settings = {
-                       };
-               };
 //2A0
 //2A1
 //2A2
 //7C2
 //7C3
 //7C4
+               7C0462070801DC3700433407 = {
+                       fileEncoding = 4;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
+                       path = "ITCategory-NSString.h";
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               7C0462080801DC3700433407 = {
+                       fileEncoding = 4;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = "ITCategory-NSString.m";
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               7C0462090801DC3700433407 = {
+                       fileRef = 7C0462070801DC3700433407;
+                       isa = PBXBuildFile;
+                       settings = {
+                               ATTRIBUTES = (
+                                       Public,
+                               );
+                       };
+               };
+               7C04620A0801DC3700433407 = {
+                       fileRef = 7C0462080801DC3700433407;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
                7C058DF7072F10530082E1E9 = {
                        fileEncoding = 4;
                        isa = PBXFileReference;
                                8DC2EF510486A6940098B216,
                                7CA50D7E054E7C600074E1D9,
                                7CA50B31054E77A00074E1D9,
-                               2AB93A3205705A0C007E748F,
                                7C97DC2E05B614300013E85F,
                                3D97137F05D9FBF40033607F,
                                7C058DF9072F10530082E1E9,
                                7C2D93BF07C2FD6700A487A9,
                                7CB02EB607D049BB00959EA0,
+                               7C0462090801DC3700433407,
                        );
                        isa = PBXHeadersBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;
                        buildActionMask = 2147483647;
                        files = (
                                7CA50B32054E77A00074E1D9,
-                               2AB93A3305705A0C007E748F,
                                7C97DC2F05B614300013E85F,
                                3D97138105D9FBFA0033607F,
                                7C058DFA072F10530082E1E9,
                                7C2D93C007C2FD6700A487A9,
                                7CB02EB707D049BB00959EA0,
+                               7C04620A0801DC3700433407,
                        );
                        isa = PBXSourcesBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;