# HG changeset patch # User Jens Alfke # Date 1246482296 25200 # Node ID d52f6b0d94beb3829007ef8a1ee59c39d3986a8a # Parent 222393534845c890b5f99c08ea750816edb0d479 Added NSData categories for GZip and Mnemonicode. Minor tweaks elsewhere. diff -r 222393534845 -r d52f6b0d94be CollectionUtils.h --- a/CollectionUtils.h Wed May 20 08:34:04 2009 -0700 +++ b/CollectionUtils.h Wed Jul 01 14:04:56 2009 -0700 @@ -44,8 +44,11 @@ void setObj( id *var, id value ); BOOL ifSetObj( id *var, id value ); -void setString( NSString **var, NSString *value ); -BOOL ifSetString( NSString **var, NSString *value ); +void setObjCopy( id *var, id valueToCopy ); +BOOL ifSetObjCopy( id *var, id value ); + +static inline void setString( NSString **var, NSString *value ) {setObjCopy(var,value);} +static inline BOOL ifSetString( NSString **var, NSString *value ) {return ifSetObjCopy(var,value);} BOOL kvSetSet( id owner, NSString *property, NSMutableSet *set, NSSet *newSet ); BOOL kvAddToSet( id owner, NSString *property, NSMutableSet *set, id objToAdd ); diff -r 222393534845 -r d52f6b0d94be CollectionUtils.m --- a/CollectionUtils.m Wed May 20 08:34:04 2009 -0700 +++ b/CollectionUtils.m Wed Jul 01 14:04:56 2009 -0700 @@ -149,19 +149,16 @@ } } - -void setString( NSString **var, NSString *value ) -{ - if( value != *var ) { +void setObjCopy( id *var, id valueToCopy ) { + if( valueToCopy != *var ) { [*var release]; - *var = [value copy]; + *var = [valueToCopy copy]; } } - -BOOL ifSetString( NSString **var, NSString *value ) +BOOL ifSetObjCopy( id *var, id value ) { - if( value != *var && ![value isEqualToString: *var] ) { + if( value != *var && ![value isEqual: *var] ) { [*var release]; *var = [value copy]; return YES; diff -r 222393534845 -r d52f6b0d94be ExceptionUtils.m --- a/ExceptionUtils.m Wed May 20 08:34:04 2009 -0700 +++ b/ExceptionUtils.m Wed Jul 01 14:04:56 2009 -0700 @@ -34,11 +34,9 @@ va_start(args,where); where = [[NSString alloc] initWithFormat: where arguments: args]; va_end(args); - if( sExceptionReporter ) { - Warn(@"Exception caught in %@:\n\t%@",where,x); + Warn(@"Exception caught in %@:\n\t%@\n%@",where,x,x.my_callStack); + if( sExceptionReporter ) sExceptionReporter(x); - }else - Warn(@"Exception caught in %@:\n\t%@\n%@",where,x,x.my_callStack); [where release]; } diff -r 222393534845 -r d52f6b0d94be NSData+Mnemonic.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NSData+Mnemonic.h Wed Jul 01 14:04:56 2009 -0700 @@ -0,0 +1,16 @@ +// +// NSData+Mnemonic.h +// Cloudy +// +// Created by Jens Alfke on 6/24/09. +// Copyright 2009 Jens Alfke. All rights reserved. +// + +#import + + +@interface NSData (MYMnemonic) + +- (NSString*) my_mnemonic; + +@end diff -r 222393534845 -r d52f6b0d94be NSData+Mnemonic.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NSData+Mnemonic.m Wed Jul 01 14:04:56 2009 -0700 @@ -0,0 +1,29 @@ +// +// NSData+Mnemonic.m +// Cloudy +// +// Created by Jens Alfke on 6/24/09. +// Copyright 2009 Jens Alfke. All rights reserved. +// + +#import "NSData+Mnemonic.h" +#import "mnemonic.h" + + +@implementation NSData (Mnemonic) + +- (NSString*) my_mnemonic { + NSMutableData *chars = [NSMutableData dataWithLength: 10*mn_words_required(self.length)]; + if (!chars) + return nil; + int result = mn_encode((void*)self.bytes, self.length, + chars.mutableBytes, chars.length, + MN_FDEFAULT); + if (result != 0) { + Warn(@"Mnemonic encoder failed: err=%i",result); + return nil; + } + return [[[NSString alloc] initWithUTF8String: chars.mutableBytes] autorelease]; +} + +@end diff -r 222393534845 -r d52f6b0d94be NSData+gzip.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NSData+gzip.h Wed Jul 01 14:04:56 2009 -0700 @@ -0,0 +1,17 @@ +// +// NSData+gzip.h +// Cloudy +// +// Created by Jens Alfke on 6/27/09. +// Copyright 2009 Jens Alfke. All rights reserved. +// + +#import + + +@interface NSData (GZip) + +- (NSData*) my_gzippedWithCompression: (int)compression; +- (NSData*) my_gunzipped; + +@end diff -r 222393534845 -r d52f6b0d94be NSData+gzip.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NSData+gzip.m Wed Jul 01 14:04:56 2009 -0700 @@ -0,0 +1,24 @@ +// +// NSData+gzip.m +// Cloudy +// +// Created by Jens Alfke on 6/27/09. +// Copyright 2009 Jens Alfke. All rights reserved. +// + +#import "NSData+gzip.h" +#import "GTMNSData+zlib.h" + +@implementation NSData (gzip) + +- (NSData*) my_gzippedWithCompression: (int)compression { + return [NSData gtm_dataByGzippingBytes: self.bytes + length: self.length + compressionLevel: compression]; +} + +- (NSData*) my_gunzipped { + return [NSData gtm_dataByInflatingBytes: self.bytes length: self.length]; +} + +@end diff -r 222393534845 -r d52f6b0d94be Test.h --- a/Test.h Wed May 20 08:34:04 2009 -0700 +++ b/Test.h Wed Jul 01 14:04:56 2009 -0700 @@ -82,6 +82,9 @@ CAssert(_val==_expected, @"Unexpected value for %s: %@ (expected %@)", #VAL,$object(_val),$object(_expected)); \ }while(0) +#define AssertNil(VAL) AssertEq((VAL),nil) +#define CAssertNil(VAL) CAssertEq((VAL),nil) + #define AssertAbstractMethod() _AssertAbstractMethodFailed(self,_cmd); // Nasty internals ...