diff --git a/Cocoa/Categories/NSNumber-Range.h b/Cocoa/Categories/NSNumber-Range.h new file mode 100644 index 0000000..ade3a12 --- /dev/null +++ b/Cocoa/Categories/NSNumber-Range.h @@ -0,0 +1,9 @@ +#import + +@interface NSNumber (ResKnifeRangeExtensions) + +- (BOOL)isWithinRange:(NSRange)range; // location <= self <= location+length +- (BOOL)isExclusivelyWithinRange:(NSRange)range; // location < self < location+length +- (BOOL)isBoundedByRange:(NSRange)range; // location <= self < location+length + +@end diff --git a/Cocoa/Categories/NSNumber-Range.m b/Cocoa/Categories/NSNumber-Range.m new file mode 100644 index 0000000..f62a57c --- /dev/null +++ b/Cocoa/Categories/NSNumber-Range.m @@ -0,0 +1,23 @@ +#import "NSNumber-Range.h" + +@implementation NSNumber (ResKnifeRangeExtensions) + +- (BOOL)isWithinRange:(NSRange)range // location <= self <= location+length +{ + // e.g. for {6,1} a value of 6.000 will return true, as will 7.000 + return [self compare:[NSNumber numberWithInt:range.location]] != NSOrderedAscending && [self compare:[NSNumber numberWithInt:range.location+range.length]] != NSOrderedDescending; +} + +- (BOOL)isExclusivelyWithinRange:(NSRange)range // location < self < location+length +{ + // e.g. for {6,1} a value of 6.000 will return false, 6.001 will return true, 6.999 will return true, 7.000 false + return [self compare:[NSNumber numberWithInt:range.location]] == NSOrderedDescending && [self compare:[NSNumber numberWithInt:range.location+range.length]] == NSOrderedAscending; +} + +- (BOOL)isBoundedByRange:(NSRange)range // location <= self < location+length +{ + // e.g. for {6,1} a value of 6.000 will return true, 6.999 will return true, 7.000 will not + return [self compare:[NSNumber numberWithInt:range.location]] != NSOrderedAscending && [self compare:[NSNumber numberWithInt:range.location+range.length]] == NSOrderedAscending; +} + +@end diff --git a/Cocoa/Categories/NSString-FSSpec.h b/Cocoa/Categories/NSString-FSSpec.h new file mode 100644 index 0000000..1d9bf7f --- /dev/null +++ b/Cocoa/Categories/NSString-FSSpec.h @@ -0,0 +1,8 @@ +#import + +@interface NSString (ResKnifeFSSpecExtensions) + +- (FSRef *)createFSRef; +- (FSSpec *)createFSSpec; + +@end diff --git a/Cocoa/Categories/NSString-FSSpec.m b/Cocoa/Categories/NSString-FSSpec.m new file mode 100644 index 0000000..d3193e8 --- /dev/null +++ b/Cocoa/Categories/NSString-FSSpec.m @@ -0,0 +1,28 @@ +#import "NSString-FSSpec.h" + +@implementation NSString (ResKnifeFSSpecExtensions) + +- (FSRef *)createFSRef +{ + FSRef *fsRef = NULL; + OSStatus error = FSPathMakeRef( [self fileSystemRepresentation], &fsRef, NULL ); + if( error == noErr ) + return fsRef; + return NULL; +} + +- (FSSpec *)createFSSpec +{ + FSRef *fsRef = NULL; + FSSpec *fsSpec = NULL; + OSStatus error = FSPathMakeRef( [self fileSystemRepresentation], &fsRef, NULL ); + if( error == noErr ) + { + error = FSGetCatalogInfo( &fsRef, kFSCatInfoNone, NULL, NULL, fsSpec, NULL ); + if( error == noErr ) + return fsSpec; + } + return NULL; +} + +@end