Added NSData categories for GZip and Mnemonicode.
Minor tweaks elsewhere.
1.1 --- a/CollectionUtils.h Wed May 20 08:34:04 2009 -0700
1.2 +++ b/CollectionUtils.h Wed Jul 01 14:04:56 2009 -0700
1.3 @@ -44,8 +44,11 @@
1.4
1.5 void setObj( id *var, id value );
1.6 BOOL ifSetObj( id *var, id value );
1.7 -void setString( NSString **var, NSString *value );
1.8 -BOOL ifSetString( NSString **var, NSString *value );
1.9 +void setObjCopy( id *var, id valueToCopy );
1.10 +BOOL ifSetObjCopy( id *var, id value );
1.11 +
1.12 +static inline void setString( NSString **var, NSString *value ) {setObjCopy(var,value);}
1.13 +static inline BOOL ifSetString( NSString **var, NSString *value ) {return ifSetObjCopy(var,value);}
1.14
1.15 BOOL kvSetSet( id owner, NSString *property, NSMutableSet *set, NSSet *newSet );
1.16 BOOL kvAddToSet( id owner, NSString *property, NSMutableSet *set, id objToAdd );
2.1 --- a/CollectionUtils.m Wed May 20 08:34:04 2009 -0700
2.2 +++ b/CollectionUtils.m Wed Jul 01 14:04:56 2009 -0700
2.3 @@ -149,19 +149,16 @@
2.4 }
2.5 }
2.6
2.7 -
2.8 -void setString( NSString **var, NSString *value )
2.9 -{
2.10 - if( value != *var ) {
2.11 +void setObjCopy( id *var, id valueToCopy ) {
2.12 + if( valueToCopy != *var ) {
2.13 [*var release];
2.14 - *var = [value copy];
2.15 + *var = [valueToCopy copy];
2.16 }
2.17 }
2.18
2.19 -
2.20 -BOOL ifSetString( NSString **var, NSString *value )
2.21 +BOOL ifSetObjCopy( id *var, id value )
2.22 {
2.23 - if( value != *var && ![value isEqualToString: *var] ) {
2.24 + if( value != *var && ![value isEqual: *var] ) {
2.25 [*var release];
2.26 *var = [value copy];
2.27 return YES;
3.1 --- a/ExceptionUtils.m Wed May 20 08:34:04 2009 -0700
3.2 +++ b/ExceptionUtils.m Wed Jul 01 14:04:56 2009 -0700
3.3 @@ -34,11 +34,9 @@
3.4 va_start(args,where);
3.5 where = [[NSString alloc] initWithFormat: where arguments: args];
3.6 va_end(args);
3.7 - if( sExceptionReporter ) {
3.8 - Warn(@"Exception caught in %@:\n\t%@",where,x);
3.9 + Warn(@"Exception caught in %@:\n\t%@\n%@",where,x,x.my_callStack);
3.10 + if( sExceptionReporter )
3.11 sExceptionReporter(x);
3.12 - }else
3.13 - Warn(@"Exception caught in %@:\n\t%@\n%@",where,x,x.my_callStack);
3.14 [where release];
3.15 }
3.16
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/NSData+Mnemonic.h Wed Jul 01 14:04:56 2009 -0700
4.3 @@ -0,0 +1,16 @@
4.4 +//
4.5 +// NSData+Mnemonic.h
4.6 +// Cloudy
4.7 +//
4.8 +// Created by Jens Alfke on 6/24/09.
4.9 +// Copyright 2009 Jens Alfke. All rights reserved.
4.10 +//
4.11 +
4.12 +#import <Foundation/NSData.h>
4.13 +
4.14 +
4.15 +@interface NSData (MYMnemonic)
4.16 +
4.17 +- (NSString*) my_mnemonic;
4.18 +
4.19 +@end
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/NSData+Mnemonic.m Wed Jul 01 14:04:56 2009 -0700
5.3 @@ -0,0 +1,29 @@
5.4 +//
5.5 +// NSData+Mnemonic.m
5.6 +// Cloudy
5.7 +//
5.8 +// Created by Jens Alfke on 6/24/09.
5.9 +// Copyright 2009 Jens Alfke. All rights reserved.
5.10 +//
5.11 +
5.12 +#import "NSData+Mnemonic.h"
5.13 +#import "mnemonic.h"
5.14 +
5.15 +
5.16 +@implementation NSData (Mnemonic)
5.17 +
5.18 +- (NSString*) my_mnemonic {
5.19 + NSMutableData *chars = [NSMutableData dataWithLength: 10*mn_words_required(self.length)];
5.20 + if (!chars)
5.21 + return nil;
5.22 + int result = mn_encode((void*)self.bytes, self.length,
5.23 + chars.mutableBytes, chars.length,
5.24 + MN_FDEFAULT);
5.25 + if (result != 0) {
5.26 + Warn(@"Mnemonic encoder failed: err=%i",result);
5.27 + return nil;
5.28 + }
5.29 + return [[[NSString alloc] initWithUTF8String: chars.mutableBytes] autorelease];
5.30 +}
5.31 +
5.32 +@end
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/NSData+gzip.h Wed Jul 01 14:04:56 2009 -0700
6.3 @@ -0,0 +1,17 @@
6.4 +//
6.5 +// NSData+gzip.h
6.6 +// Cloudy
6.7 +//
6.8 +// Created by Jens Alfke on 6/27/09.
6.9 +// Copyright 2009 Jens Alfke. All rights reserved.
6.10 +//
6.11 +
6.12 +#import <Cocoa/Cocoa.h>
6.13 +
6.14 +
6.15 +@interface NSData (GZip)
6.16 +
6.17 +- (NSData*) my_gzippedWithCompression: (int)compression;
6.18 +- (NSData*) my_gunzipped;
6.19 +
6.20 +@end
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/NSData+gzip.m Wed Jul 01 14:04:56 2009 -0700
7.3 @@ -0,0 +1,24 @@
7.4 +//
7.5 +// NSData+gzip.m
7.6 +// Cloudy
7.7 +//
7.8 +// Created by Jens Alfke on 6/27/09.
7.9 +// Copyright 2009 Jens Alfke. All rights reserved.
7.10 +//
7.11 +
7.12 +#import "NSData+gzip.h"
7.13 +#import "GTMNSData+zlib.h"
7.14 +
7.15 +@implementation NSData (gzip)
7.16 +
7.17 +- (NSData*) my_gzippedWithCompression: (int)compression {
7.18 + return [NSData gtm_dataByGzippingBytes: self.bytes
7.19 + length: self.length
7.20 + compressionLevel: compression];
7.21 +}
7.22 +
7.23 +- (NSData*) my_gunzipped {
7.24 + return [NSData gtm_dataByInflatingBytes: self.bytes length: self.length];
7.25 +}
7.26 +
7.27 +@end
8.1 --- a/Test.h Wed May 20 08:34:04 2009 -0700
8.2 +++ b/Test.h Wed Jul 01 14:04:56 2009 -0700
8.3 @@ -82,6 +82,9 @@
8.4 CAssert(_val==_expected, @"Unexpected value for %s: %@ (expected %@)", #VAL,$object(_val),$object(_expected)); \
8.5 }while(0)
8.6
8.7 +#define AssertNil(VAL) AssertEq((VAL),nil)
8.8 +#define CAssertNil(VAL) CAssertEq((VAL),nil)
8.9 +
8.10 #define AssertAbstractMethod() _AssertAbstractMethodFailed(self,_cmd);
8.11
8.12 // Nasty internals ...