From 1e2fdc3e1bd024e34dd93390809d009c8585b936 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Wed, 8 Dec 2010 15:44:28 -0800 Subject: [PATCH] Remove tabs; Update some of the toll free bridging code. --- Foundation/CPArray.j | 4 ++-- Foundation/CPDecimalNumber.j | 2 +- Foundation/CPException.j | 26 +++++++++++++++++--------- Foundation/CPNumber.j | 4 ++-- Foundation/CPString.j | 16 +++++++++------- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Foundation/CPArray.j b/Foundation/CPArray.j index 4134df19f..629a69fd7 100755 --- a/Foundation/CPArray.j +++ b/Foundation/CPArray.j @@ -108,8 +108,8 @@ CPEnumerationReverse = 1 << 1; */ + (id)alloc { - var result = []; - result.isa = [self class]; + var result = []; + result.isa = [self class]; return result; } diff --git a/Foundation/CPDecimalNumber.j b/Foundation/CPDecimalNumber.j index 19f6f0b67..cadb5297c 100644 --- a/Foundation/CPDecimalNumber.j +++ b/Foundation/CPDecimalNumber.j @@ -444,7 +444,7 @@ _cappdefaultDcmHandler = [CPDecimalNumberHandler decimalNumberHandlerWithRoundin */ - (CPString)hash { - objj_exception_throw("hash: NOT YET IMPLEMENTED"); + [CPException raise:CPUnsupportedMethodException reason:"hash: NOT YET IMPLEMENTED"]; } /*! diff --git a/Foundation/CPException.j b/Foundation/CPException.j index 7a9c8c959..feac9eb6d 100755 --- a/Foundation/CPException.j +++ b/Foundation/CPException.j @@ -54,8 +54,9 @@ if (input == nil) */ + (id)alloc { - if ([self class] !== CPException) return [super alloc]; - return new Error(); + var result = new Error(); + result.isa = [self class]; + return result; } /*! @@ -89,9 +90,7 @@ if (input == nil) */ - (id)initWithName:(CPString)aName reason:(CPString)aReason userInfo:(CPDictionary)aUserInfo { - self = [super init]; - - if (self) + if (self = [super init]) { name = aName; message = aReason; @@ -141,6 +140,17 @@ if (input == nil) throw self; } +- (BOOL)isEqual:(id)anObject +{ + if (!anObject || !anObject.isa) + return NO; + + return [anObject isKindOfClass:CPException] && + name === [anObject name] && + message === [anObject message] && + (_userInfo === [anObject userInfo] || ([_userInfo isEqual:[anObject userInfo]])); +} + @end @implementation CPException (CPCopying) @@ -165,9 +175,7 @@ var CPExceptionNameKey = "CPExceptionNameKey", */ - (id)initWithCoder:(CPCoder)aCoder { - self = [super init]; - - if (self) + if (self = [super init]) { name = [aCoder decodeObjectForKey:CPExceptionNameKey]; message = [aCoder decodeObjectForKey:CPExceptionReasonKey]; @@ -193,7 +201,7 @@ var CPExceptionNameKey = "CPExceptionNameKey", // toll-free bridge Error to CPException // [CPException alloc] uses an objj_exception, which is a subclass of Error Error.prototype.isa = CPException; -Error.prototype._userInfo = NULL; +Error.prototype._userInfo = null; [CPException initialize]; diff --git a/Foundation/CPNumber.j b/Foundation/CPNumber.j index a65949a88..ff916f616 100644 --- a/Foundation/CPNumber.j +++ b/Foundation/CPNumber.j @@ -43,8 +43,8 @@ var __placeholder = new Number(), + (id)alloc { - var result = new Number(); - result.isa = [self class]; + var result = new Number(); + result.isa = [self class]; return result; } diff --git a/Foundation/CPString.j b/Foundation/CPString.j index c6a0d29d3..cf2942de2 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -91,7 +91,9 @@ var CPStringRegexSpecialCharacters = [ */ + (id)alloc { - if ([self class] !== CPString) return [super alloc]; + if ([self class] !== CPString) + return [super alloc]; + return new String; } @@ -433,7 +435,7 @@ var CPStringRegexSpecialCharacters = [ - (CPString)stringByReplacingCharactersInRange:(CPRange)range withString:(CPString)replacement { - return '' + substring(0, range.location) + replacement + substring(range.location + range.length, self.length); + return '' + substring(0, range.location) + replacement + substring(range.location + range.length, self.length); } /*! @@ -485,8 +487,8 @@ var CPStringRegexSpecialCharacters = [ if(aMask & CPDiacriticInsensitiveSearch) { - lhs = lhs.stripDiacritics(); - rhs = rhs.stripDiacritics(); + lhs = lhs.stripDiacritics(); + rhs = rhs.stripDiacritics(); } if (lhs < rhs) @@ -715,9 +717,9 @@ var CPStringRegexSpecialCharacters = [ } /*! - Deletes the last path component of a string. - This method assumes that the string's content is a '/' - separated file system path. + Deletes the last path component of a string. + This method assumes that the string's content is a '/' + separated file system path. */ - (CPString)stringByDeletingLastPathComponent {