From b70018bd80ccccf855a33a189dcb325ad173b4aa Mon Sep 17 00:00:00 2001 From: Stephen Ierodiaconou Date: Sat, 25 Dec 2010 18:22:47 +0200 Subject: [PATCH 1/6] Import fixes and lint --- Foundation/CPAttributedString.j | 3 +- Foundation/CPBundle.j | 5 +- Foundation/CPCoder.j | 1 - Foundation/CPCountedSet.j | 2 +- Foundation/CPData.j | 1 - Foundation/CPDate.j | 2 +- Foundation/CPDecimalNumber.j | 2 +- Foundation/CPDictionary.j | 2 +- Foundation/CPEnumerator.j | 1 - Foundation/CPException.j | 19 +++--- Foundation/CPFormatter.j | 5 -- Foundation/CPFunctionOperation.j | 9 +-- Foundation/CPIndexPath.j | 25 +++++++- Foundation/CPIndexSet.j | 2 +- Foundation/CPInvocation.j | 2 - Foundation/CPInvocationOperation.j | 1 - Foundation/CPKeyValueCoding.j | 2 +- Foundation/CPKeyValueObserving.j | 18 +++--- Foundation/CPKeyedArchiver.j | 1 - Foundation/CPKeyedUnarchiver.j | 4 +- Foundation/CPNotification.j | 1 - Foundation/CPNotificationCenter.j | 1 - Foundation/CPNull.j | 1 - Foundation/CPNumber.j | 1 - Foundation/CPObject.j | 2 - Foundation/CPOperation.j | 16 ++--- Foundation/CPOperationQueue.j | 6 +- Foundation/CPPropertyListSerialization.j | 1 - Foundation/CPProxy.j | 2 +- Foundation/CPRunLoop.j | 1 + Foundation/CPScanner.j | 77 ++++++++++++++++-------- 31 files changed, 123 insertions(+), 93 deletions(-) diff --git a/Foundation/CPAttributedString.j b/Foundation/CPAttributedString.j index bcbd9a732..1ea754af7 100644 --- a/Foundation/CPAttributedString.j +++ b/Foundation/CPAttributedString.j @@ -20,12 +20,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +@import "CPArray.j" @import "CPDictionary.j" +@import "CPException.j" @import "CPObject.j" @import "CPRange.j" @import "CPString.j" - /*! @class CPAttributedString @ingroup foundation diff --git a/Foundation/CPBundle.j b/Foundation/CPBundle.j index 8c8f54bbe..7c4fedf4a 100644 --- a/Foundation/CPBundle.j +++ b/Foundation/CPBundle.j @@ -21,12 +21,11 @@ */ @import "CPDictionary.j" -@import "CPObject.j" @import "CPNotification.j" @import "CPNotificationCenter.j" +@import "CPObject.j" - -CPBundleDidLoadNotification = "CPBundleDidLoadNotification"; +CPBundleDidLoadNotification = @"CPBundleDidLoadNotification"; /*! @class CPBundle diff --git a/Foundation/CPCoder.j b/Foundation/CPCoder.j index 50fe4f8a2..62ee9cea2 100644 --- a/Foundation/CPCoder.j +++ b/Foundation/CPCoder.j @@ -23,7 +23,6 @@ @import "CPException.j" @import "CPObject.j" - /*! @class CPCoder @ingroup foundation diff --git a/Foundation/CPCountedSet.j b/Foundation/CPCountedSet.j index 8a540b317..cb5c13953 100644 --- a/Foundation/CPCountedSet.j +++ b/Foundation/CPCountedSet.j @@ -20,9 +20,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +@import "CPObject.j" @import "CPSet.j" - /*! @class CPCountedSet @ingroup foundation diff --git a/Foundation/CPData.j b/Foundation/CPData.j index 69b37d490..fa32c65e7 100644 --- a/Foundation/CPData.j +++ b/Foundation/CPData.j @@ -23,7 +23,6 @@ @import "CPObject.j" @import "CPString.j" - /*! @class CPData @ingroup foundation diff --git a/Foundation/CPDate.j b/Foundation/CPDate.j index a46a44c3e..8aab2db72 100644 --- a/Foundation/CPDate.j +++ b/Foundation/CPDate.j @@ -22,7 +22,7 @@ @import "CPObject.j" @import "CPString.j" - +@import "CPException.j" var CPDateReferenceDate = new Date(Date.UTC(2001, 1, 1, 0, 0, 0, 0)); diff --git a/Foundation/CPDecimalNumber.j b/Foundation/CPDecimalNumber.j index 3c09dee7d..59c9701bd 100644 --- a/Foundation/CPDecimalNumber.j +++ b/Foundation/CPDecimalNumber.j @@ -19,9 +19,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "CPObject.j" @import "CPDecimal.j" @import "CPException.j" +@import "CPObject.j" /* The protocol is defined as : Make sure CPDecimalNumberHandler implements these methods @protocol CPDecimalNumberBehaviors diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index 6288e688b..69882448e 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -23,9 +23,9 @@ @import "CPArray.j" @import "CPEnumerator.j" @import "CPException.j" +@import "CPNull.j" @import "CPObject.j" - /* @ignore */ @implementation _CPDictionaryValueEnumerator : CPEnumerator { diff --git a/Foundation/CPEnumerator.j b/Foundation/CPEnumerator.j index 50efcb571..ff605a0a5 100755 --- a/Foundation/CPEnumerator.j +++ b/Foundation/CPEnumerator.j @@ -22,7 +22,6 @@ @import "CPObject.j" - /*! @class CPEnumerator @ingroup foundation diff --git a/Foundation/CPException.j b/Foundation/CPException.j index 68b0d4279..7788e2392 100755 --- a/Foundation/CPException.j +++ b/Foundation/CPException.j @@ -24,11 +24,10 @@ @import "CPObject.j" @import "CPString.j" - -CPInvalidArgumentException = "CPInvalidArgumentException"; -CPUnsupportedMethodException = "CPUnsupportedMethodException"; -CPRangeException = "CPRangeException"; -CPInternalInconsistencyException = "CPInternalInconsistencyException"; +CPInvalidArgumentException = @"CPInvalidArgumentException"; +CPUnsupportedMethodException = @"CPUnsupportedMethodException"; +CPRangeException = @"CPRangeException"; +CPInternalInconsistencyException = @"CPInternalInconsistencyException"; /*! @class CPException @@ -90,7 +89,9 @@ if (input == nil) */ - (id)initWithName:(CPString)aName reason:(CPString)aReason userInfo:(CPDictionary)aUserInfo { - if (self = [super init]) + self = [super init]; + + if (self) { name = aName; message = aReason; @@ -162,9 +163,9 @@ if (input == nil) @end -var CPExceptionNameKey = "CPExceptionNameKey", - CPExceptionReasonKey = "CPExceptionReasonKey", - CPExceptionUserInfoKey = "CPExceptionUserInfoKey"; +var CPExceptionNameKey = @"CPExceptionNameKey", + CPExceptionReasonKey = @"CPExceptionReasonKey", + CPExceptionUserInfoKey = @"CPExceptionUserInfoKey"; @implementation CPException (CPCoding) diff --git a/Foundation/CPFormatter.j b/Foundation/CPFormatter.j index e09219db7..459ebc220 100644 --- a/Foundation/CPFormatter.j +++ b/Foundation/CPFormatter.j @@ -36,7 +36,6 @@ @import "CPException.j" @import "CPObject.j" - @implementation CPFormatter : CPObject /*! @@ -57,13 +56,11 @@ return nil; } - /*- (CPAttributedString)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(CPDictionary)attributes { }*/ - /*! The default implementation of this method invokes stringForObjectValue:. @@ -80,7 +77,6 @@ return [self stringForObjectValue:anObject]; } - /*! The default implementation of this method raises an exception. @@ -102,7 +98,6 @@ return NO; } - /*! Returns a Boolean value that indicates whether a partial string is valid. diff --git a/Foundation/CPFunctionOperation.j b/Foundation/CPFunctionOperation.j index 7fb44ed74..34784374f 100644 --- a/Foundation/CPFunctionOperation.j +++ b/Foundation/CPFunctionOperation.j @@ -19,10 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import "CPArray.j" +@import "CPObject.j" @import "CPOperation.j" - /*! @class CPFunctionOperation @brief Represents an operation using a JavaScript function that can be run in an CPOperationQueue @@ -32,7 +32,6 @@ CPArray _functions; } - - (void)main { if (_functions && [_functions count] > 0) @@ -50,7 +49,9 @@ - (id)init { - if (self = [super init]) + self = [super init]; + + if (self) { _functions = []; } diff --git a/Foundation/CPIndexPath.j b/Foundation/CPIndexPath.j index d01a9abcd..d1413a2c0 100644 --- a/Foundation/CPIndexPath.j +++ b/Foundation/CPIndexPath.j @@ -1,10 +1,29 @@ +/* + * CPIndexPath.j + * Foundation + * + * Copyright 2008, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ -@import "CPObject.j" @import "CPArray.j" +@import "CPException.j" +@import "CPObject.j" @import "CPRange.j" @import "CPSortDescriptor.j" -@import "CPException.j" - @implementation CPIndexPath : CPObject { diff --git a/Foundation/CPIndexSet.j b/Foundation/CPIndexSet.j index 26442d4d5..cd00998fb 100644 --- a/Foundation/CPIndexSet.j +++ b/Foundation/CPIndexSet.j @@ -20,10 +20,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +@import "CPArray.j" @import "CPObject.j" @import "CPRange.j" - #define _CPMaxRange(aRange) ((aRange).location + (aRange).length) #define _CPMakeRange(aLocation, aLength) { location:(aLocation), length:aLength } #define _CPMakeRangeCopy(aRange) { location:(aRange).location, length:(aRange).length } diff --git a/Foundation/CPInvocation.j b/Foundation/CPInvocation.j index da66a2a68..7cc5fbe32 100644 --- a/Foundation/CPInvocation.j +++ b/Foundation/CPInvocation.j @@ -20,10 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "CPException.j" @import "CPObject.j" - /*! @class CPInvocation @ingroup foundation diff --git a/Foundation/CPInvocationOperation.j b/Foundation/CPInvocationOperation.j index b897ec161..f0409a4ea 100644 --- a/Foundation/CPInvocationOperation.j +++ b/Foundation/CPInvocationOperation.j @@ -23,7 +23,6 @@ @import "CPObject.j" @import "CPOperation.j" - /*! @class CPInvocationOperation @brief Represents an operation using an invocation that can be run in an CPOperationQueue diff --git a/Foundation/CPKeyValueCoding.j b/Foundation/CPKeyValueCoding.j index b6012e75b..a87f702c9 100644 --- a/Foundation/CPKeyValueCoding.j +++ b/Foundation/CPKeyValueCoding.j @@ -22,11 +22,11 @@ @import "CPArray.j" @import "CPDictionary.j" +@import "CPException.j" @import "CPNull.j" @import "CPObject.j" @import "CPSet.j" - CPUndefinedKeyException = @"CPUndefinedKeyException"; CPTargetObjectUserInfoKey = @"CPTargetObjectUserInfoKey"; CPUnknownUserInfoKey = @"CPUnknownUserInfoKey"; diff --git a/Foundation/CPKeyValueObserving.j b/Foundation/CPKeyValueObserving.j index a83bf8bd5..ca7fc12e6 100644 --- a/Foundation/CPKeyValueObserving.j +++ b/Foundation/CPKeyValueObserving.j @@ -207,20 +207,16 @@ var _changeKindForSetMutationKind = function(mutationKind) { switch (mutationKind) { - case CPKeyValueUnionSetMutation: - return CPKeyValueChangeInsertion; - case CPKeyValueMinusSetMutation: - return CPKeyValueChangeRemoval; - case CPKeyValueIntersectSetMutation: - return CPKeyValueChangeRemoval; - case CPKeyValueSetSetMutation: - return CPKeyValueChangeReplacement; + case CPKeyValueUnionSetMutation: return CPKeyValueChangeInsertion; + case CPKeyValueMinusSetMutation: return CPKeyValueChangeRemoval; + case CPKeyValueIntersectSetMutation: return CPKeyValueChangeRemoval; + case CPKeyValueSetSetMutation: return CPKeyValueChangeReplacement; } } -var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOptionOld, - DependentKeysKey = "$KVODEPENDENT", - KVOProxyKey = "$KVOPROXY"; +var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOptionOld, + DependentKeysKey = "$KVODEPENDENT", + KVOProxyKey = "$KVOPROXY"; //rule of thumb: _ methods are called on the real proxy object, others are called on the "fake" proxy object (aka the real object) diff --git a/Foundation/CPKeyedArchiver.j b/Foundation/CPKeyedArchiver.j index d933458a7..c35b0ee4d 100644 --- a/Foundation/CPKeyedArchiver.j +++ b/Foundation/CPKeyedArchiver.j @@ -28,7 +28,6 @@ @import "CPString.j" @import "CPValue.j" - var CPArchiverReplacementClassNames = nil; var _CPKeyedArchiverDidEncodeObjectSelector = 1, diff --git a/Foundation/CPKeyedUnarchiver.j b/Foundation/CPKeyedUnarchiver.j index a98853038..73014e46c 100644 --- a/Foundation/CPKeyedUnarchiver.j +++ b/Foundation/CPKeyedUnarchiver.j @@ -21,15 +21,15 @@ */ @import "CPArray.j" +@import "CPCoder.j" @import "CPData.j" @import "CPDictionary.j" -@import "CPCoder.j" +@import "CPException.j" @import "CPKeyedArchiver.j" @import "CPNull.j" @import "CPNumber.j" @import "CPString.j" - CPInvalidUnarchiveOperationException = @"CPInvalidUnarchiveOperationException"; var _CPKeyedUnarchiverCannotDecodeObjectOfClassNameOriginalClassesSelector = 1 << 0, diff --git a/Foundation/CPNotification.j b/Foundation/CPNotification.j index 60df53e9d..5b9e8d51b 100644 --- a/Foundation/CPNotification.j +++ b/Foundation/CPNotification.j @@ -23,7 +23,6 @@ @import "CPException.j" @import "CPObject.j" - /*! @class CPNotification @ingroup foundation diff --git a/Foundation/CPNotificationCenter.j b/Foundation/CPNotificationCenter.j index b6c9b5e96..c38d7283f 100644 --- a/Foundation/CPNotificationCenter.j +++ b/Foundation/CPNotificationCenter.j @@ -26,7 +26,6 @@ @import "CPNotification.j" @import "CPNull.j" - var CPNotificationDefaultCenter = nil; /*! diff --git a/Foundation/CPNull.j b/Foundation/CPNull.j index 2c267dcb8..af98391f3 100644 --- a/Foundation/CPNull.j +++ b/Foundation/CPNull.j @@ -22,7 +22,6 @@ @import "CPObject.j" - var CPNullSharedNull = nil; /*! diff --git a/Foundation/CPNumber.j b/Foundation/CPNumber.j index 3b503fd0b..37d1b805d 100644 --- a/Foundation/CPNumber.j +++ b/Foundation/CPNumber.j @@ -23,7 +23,6 @@ @import "CPObject.j" @import "CPObjJRuntime.j" - var CPNumberUIDs = new CFMutableDictionary(); /*! diff --git a/Foundation/CPObject.j b/Foundation/CPObject.j index cd8ff3994..a22bbe3d3 100644 --- a/Foundation/CPObject.j +++ b/Foundation/CPObject.j @@ -61,8 +61,6 @@ CPLog(@"Got some class: %@", inst); @todo document KVC usage. */ - - @implementation CPObject { Class isa; diff --git a/Foundation/CPOperation.j b/Foundation/CPOperation.j index 1bf66426c..efe2e5d25 100644 --- a/Foundation/CPOperation.j +++ b/Foundation/CPOperation.j @@ -19,43 +19,43 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "CPObject.j" @import "CPArray.j" +@import "CPObject.j" /*! Operations receive very low priority for execution. @global @group CPOperationQueuePriority */ -CPOperationQueuePriorityVeryLow = -8; +CPOperationQueuePriorityVeryLow = -8; /*! Operations receive low priority for execution. @global @group CPOperationQueuePriority */ -CPOperationQueuePriorityLow = -4; +CPOperationQueuePriorityLow = -4; /*! Operations receive normal priority for execution. @global @group CPOperationQueuePriority */ -CPOperationQueuePriorityNormal = 0; +CPOperationQueuePriorityNormal = 0; /*! Operations receive high priority for execution. @global @group CPOperationQueuePriority */ -CPOperationQueuePriorityHigh = 4; +CPOperationQueuePriorityHigh = 4; /*! Operations receive very high priority for execution. @global @group CPOperationQueuePriority */ -CPOperationQueuePriorityVeryHigh = 8; +CPOperationQueuePriorityVeryHigh = 8; /*! @@ -83,7 +83,9 @@ CPOperationQueuePriorityVeryHigh = 8; - (id)init { - if (self = [super init]) + self = [super init]; + + if (self) { _cancelled = NO; _executing = NO; diff --git a/Foundation/CPOperationQueue.j b/Foundation/CPOperationQueue.j index f0991b248..16eb27b7d 100644 --- a/Foundation/CPOperationQueue.j +++ b/Foundation/CPOperationQueue.j @@ -19,10 +19,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +@import "CPArray.j" @import "CPFunctionOperation.j" @import "CPInvocationOperation.j" @import "CPObject.j" @import "CPOperation.j" +@import "CPString.j" @import "CPTimer.j" // the global queue (mainQueue) @@ -42,7 +44,9 @@ var cpOperationMainQueue = nil; - (id)init { - if (self = [super init]) + self = [super init]; + + if (self) { _operations = [[CPArray alloc] init]; _suspended = NO; diff --git a/Foundation/CPPropertyListSerialization.j b/Foundation/CPPropertyListSerialization.j index 4f37b3179..d3db01600 100644 --- a/Foundation/CPPropertyListSerialization.j +++ b/Foundation/CPPropertyListSerialization.j @@ -22,7 +22,6 @@ @import "CPObject.j" - CPPropertyListUnknownFormat = 0; CPPropertyListOpenStepFormat = kCFPropertyListOpenStepFormat; CPPropertyListXMLFormat_v1_0 = kCFPropertyListXMLFormat_v1_0; diff --git a/Foundation/CPProxy.j b/Foundation/CPProxy.j index cbb8f0f2f..e935ad344 100644 --- a/Foundation/CPProxy.j +++ b/Foundation/CPProxy.j @@ -22,9 +22,9 @@ @import "CPException.j" @import "CPInvocation.j" +@import "CPObject.j" @import "CPString.j" - @implementation CPProxy { } diff --git a/Foundation/CPRunLoop.j b/Foundation/CPRunLoop.j index 89ad9337a..af897360d 100644 --- a/Foundation/CPRunLoop.j +++ b/Foundation/CPRunLoop.j @@ -21,6 +21,7 @@ */ @import "CPArray.j" +@import "CPDate.j" @import "CPObject.j" @import "CPString.j" diff --git a/Foundation/CPScanner.j b/Foundation/CPScanner.j index 89c6e14bf..a1976ae7c 100644 --- a/Foundation/CPScanner.j +++ b/Foundation/CPScanner.j @@ -1,11 +1,27 @@ -// CPScanner.j -// © Emanuele Vulcano, 2008. -// -// Licensed under the terms of Cappuccino's license -// (the GNU Lesser General Public License, version 2.1). -// Please see Cappuccino's LICENSE file for details. +/* + * CPScanner.j + * Foundation + * + * © Emanuele Vulcano, 2008. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ -@import +@import "CPCharacterSet.j" +@import "CPDictionary.j" +@import "CPString.j" @implementation CPScanner : CPObject { @@ -180,8 +196,8 @@ if ([self isAtEnd]) return nil; - var current = [self scanLocation]; - var str = nil; + var current = [self scanLocation], + str = nil; while (current < _string.length) { @@ -212,9 +228,9 @@ - (void)_movePastCharactersToBeSkipped { - var current = [self scanLocation]; - var string = [self string]; - var toSkip = [self charactersToBeSkipped]; + var current = [self scanLocation], + string = [self string], + toSkip = [self charactersToBeSkipped]; while (current < string.length) { @@ -258,8 +274,10 @@ - (CPString)scanUpToString:(CPString)s { - var current = [self scanLocation], str = [self string]; - var captured = nil; + var current = [self scanLocation], + str = [self string], + captured = nil; + while (current < str.length) { var currentStr = str.substr(current, s.length); @@ -291,16 +309,19 @@ - (float)scanFloat { [self _movePastCharactersToBeSkipped]; - var str = [self string], current = [self scanLocation]; + var str = [self string], + current = [self scanLocation]; if ([self isAtEnd]) return 0; - var s = str.substring(current, str.length); - var f = parseFloat(s); // wont work with non . decimal separator !! + var s = str.substring(current, str.length), + f = parseFloat(s); // wont work with non . decimal separator !! + if (f) { - var pos, foundDash = NO; + var pos = current, + foundDash = NO; /* var decimalSeparatorString; if (_locale != nil) @@ -312,7 +333,7 @@ */ var separatorCode = 45; - for (pos = current; pos < current + str.length; pos++) + for (; pos < current + str.length; pos++) { var charCode = str.charCodeAt(pos); if (charCode == separatorCode) @@ -335,17 +356,21 @@ - (int)scanInt { [self _movePastCharactersToBeSkipped]; - var str = [self string], current = [self scanLocation]; + var str = [self string], + current = [self scanLocation]; if ([self isAtEnd]) return 0; - var s = str.substring(current, str.length); - var i = parseInt(s); + var s = str.substring(current, str.length), + i = parseInt(s); + if (i) { - var pos, foundDash = NO; - for (pos = current; pos < current + str.length; pos++) + var pos = current, + foundDash = NO; + + for (; pos < current + str.length; pos++) { var charCode = str.charCodeAt(pos); if (charCode == 46) @@ -384,9 +409,9 @@ /* = Debug = */ /* ========= */ -- (void) description +- (void)description { return [super description] + " {" + CPStringFromClass([self class]) + ", state = '" + ([self string].substr(0, _scanLocation) + "{{ SCAN LOCATION ->}}" + [self string].substr(_scanLocation)) + "'; }"; } -@end \ No newline at end of file +@end From 66b6b44f8674de1d2670f642fa6f7927efc4777f Mon Sep 17 00:00:00 2001 From: Stephen Ierodiaconou Date: Sat, 25 Dec 2010 18:28:40 +0200 Subject: [PATCH 2/6] CPPredicate lint, import fixes, and some bug fixes --- .../CPPredicate/CPComparisonPredicate.j | 340 +++++++++--------- Foundation/CPPredicate/CPCompoundPredicate.j | 100 ++++-- Foundation/CPPredicate/CPExpression.j | 43 ++- .../CPPredicate/CPExpression_aggregate.j | 36 +- .../CPPredicate/CPExpression_constant.j | 28 +- .../CPPredicate/CPExpression_function.j | 62 +++- Foundation/CPPredicate/CPExpression_keypath.j | 22 +- Foundation/CPPredicate/CPExpression_self.j | 25 +- Foundation/CPPredicate/CPExpression_set.j | 54 ++- .../CPPredicate/CPExpression_subquery.j | 47 ++- .../CPPredicate/CPExpression_variable.j | 30 +- Foundation/CPPredicate/CPPredicate.j | 47 ++- Foundation/CPScanner.j | 4 +- 13 files changed, 547 insertions(+), 291 deletions(-) diff --git a/Foundation/CPPredicate/CPComparisonPredicate.j b/Foundation/CPPredicate/CPComparisonPredicate.j index 9af047dc2..9764b079b 100644 --- a/Foundation/CPPredicate/CPComparisonPredicate.j +++ b/Foundation/CPPredicate/CPComparisonPredicate.j @@ -1,17 +1,37 @@ +/* + * CPComparisonPredicate.j + * Foundation + * + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ @import "CPArray.j" -@import "CPNull.j" -@import "CPString.j" @import "CPEnumerator.j" -@import "CPPredicate.j" @import "CPExpression.j" +@import "CPNull.j" +@import "CPPredicate.j" +@import "CPString.j" /*! A predicate to directly compare the left and right hand sides. @global @class CPComparisonPredicate */ -CPDirectPredicateModifier = 0; +CPDirectPredicateModifier = 0; /*! A predicate to compare all entries in the destination of a to-many relationship. @@ -19,7 +39,7 @@ CPDirectPredicateModifier = 0; @global @class CPComparisonPredicate */ -CPAllPredicateModifier = 1; +CPAllPredicateModifier = 1; /*! A predicate to match with any entry in the destination of a to-many relationship. @@ -27,28 +47,28 @@ CPAllPredicateModifier = 1; @global @class CPComparisonPredicate */ -CPAnyPredicateModifier = 2; +CPAnyPredicateModifier = 2; /*! A case-insensitive predicate. @global @class CPComparisonPredicate */ -CPCaseInsensitivePredicateOption = 1; +CPCaseInsensitivePredicateOption = 1; /*! A diacritic-insensitive predicate. @global @class CPComparisonPredicate */ -CPDiacriticInsensitivePredicateOption = 2; -CPDiacriticInsensitiveSearch = 128; +CPDiacriticInsensitivePredicateOption = 2; +CPDiacriticInsensitiveSearch = 128; /*! A less-than predicate. @global @class CPComparisonPredicate */ -CPLessThanPredicateOperatorType = 0; +CPLessThanPredicateOperatorType = 0; /*! A less-than-or-equal-to predicate. @global @@ -60,7 +80,7 @@ CPLessThanOrEqualToPredicateOperatorType = 1; @global @class CPComparisonPredicate */ -CPGreaterThanPredicateOperatorType = 2; +CPGreaterThanPredicateOperatorType = 2; /*! A greater-than-or-equal-to predicate. @global @@ -72,37 +92,37 @@ CPGreaterThanOrEqualToPredicateOperatorType = 3; @global @class CPComparisonPredicate */ -CPEqualToPredicateOperatorType = 4; +CPEqualToPredicateOperatorType = 4; /*! A not-equal-to predicate. @global @class CPComparisonPredicate */ -CPNotEqualToPredicateOperatorType = 5; +CPNotEqualToPredicateOperatorType = 5; /*! A full regular expression matching predicate. @global @class CPComparisonPredicate */ -CPMatchesPredicateOperatorType = 6; +CPMatchesPredicateOperatorType = 6; /*! A simple subset of the matches predicate, similar in behavior to SQL LIKE. @global @class CPComparisonPredicate */ -CPLikePredicateOperatorType = 7; +CPLikePredicateOperatorType = 7; /*! A begins-with predicate. @global @class CPComparisonPredicate */ -CPBeginsWithPredicateOperatorType = 8; +CPBeginsWithPredicateOperatorType = 8; /*! An ends-with predicate. @global @class CPComparisonPredicate */ -CPEndsWithPredicateOperatorType = 9; +CPEndsWithPredicateOperatorType = 9; /*! A predicate to determine if the left hand side is in the right hand side. @@ -110,7 +130,7 @@ CPEndsWithPredicateOperatorType = 9; @global @class CPComparisonPredicate */ -CPInPredicateOperatorType = 10; +CPInPredicateOperatorType = 10; /*! Predicate that uses a custom selector that takes a single argument and returns a BOOL value. @@ -118,7 +138,7 @@ CPInPredicateOperatorType = 10; @global @class CPComparisonPredicate */ -CPCustomSelectorPredicateOperatorType = 11; +CPCustomSelectorPredicateOperatorType = 11; /*! A predicate to determine if the left hand side contains the right hand side. @@ -126,7 +146,7 @@ CPCustomSelectorPredicateOperatorType = 11; @global @class CPComparisonPredicate */ -CPContainsPredicateOperatorType = 99; +CPContainsPredicateOperatorType = 99; /*! A predicate to determine if the right hand side lies between bounds specified by the left hand side. @@ -134,7 +154,7 @@ CPContainsPredicateOperatorType = 99; @global @class CPComparisonPredicate */ -CPBetweenPredicateOperatorType = 100; +CPBetweenPredicateOperatorType = 100; var CPComparisonPredicateModifier, CPPredicateOperatorType; @@ -193,12 +213,17 @@ var CPComparisonPredicateModifier, */ - (id)initWithLeftExpression:(CPExpression)left rightExpression:(CPExpression)right customSelector:(SEL)selector { - _left = left; - _right = right; - _modifier = CPDirectPredicateModifier; - _type = CPCustomSelectorPredicateOperatorType; - _options = 0; - _customSelector = selector; + self = [super init]; + + if (self) + { + _left = left; + _right = right; + _modifier = CPDirectPredicateModifier; + _type = CPCustomSelectorPredicateOperatorType; + _options = 0; + _customSelector = selector; + } return self; } @@ -214,18 +239,23 @@ var CPComparisonPredicateModifier, */ - (id)initWithLeftExpression:(CPExpression)left rightExpression:(CPExpression)right modifier:(CPComparisonPredicateModifier)modifier type:(CPPredicateOperatorType)type options:(unsigned)options { - _left = left; - _right = right; - _modifier = modifier; - _type = type; - _options = (type != CPMatchesPredicateOperatorType && - type != CPLikePredicateOperatorType && - type != CPBeginsWithPredicateOperatorType && - type != CPEndsWithPredicateOperatorType && - type != CPInPredicateOperatorType && - type != CPContainsPredicateOperatorType) ? 0 : options; + self = [super init]; - _customSelector = NULL; + if (self) + { + _left = left; + _right = right; + _modifier = modifier; + _type = type; + _options = (type != CPMatchesPredicateOperatorType && + type != CPLikePredicateOperatorType && + type != CPBeginsWithPredicateOperatorType && + type != CPEndsWithPredicateOperatorType && + type != CPInPredicateOperatorType && + type != CPContainsPredicateOperatorType) ? 0 : options; + + _customSelector = NULL; + } return self; } @@ -292,81 +322,63 @@ var CPComparisonPredicateModifier, switch (_modifier) { - case CPDirectPredicateModifier: - modifier = ""; - break; - case CPAllPredicateModifier: - modifier = "ALL "; - break; - case CPAnyPredicateModifier: - modifier = "ANY "; - break; - default: - modifier = ""; - break; + case CPDirectPredicateModifier: modifier = ""; + break; + case CPAllPredicateModifier: modifier = "ALL "; + break; + case CPAnyPredicateModifier: modifier = "ANY "; + break; + + default: modifier = ""; + break; } var options; switch (_options) { - case CPCaseInsensitivePredicateOption: - options = "[c]"; - break; - case CPDiacriticInsensitivePredicateOption: - options = "[d]"; - break; + case CPCaseInsensitivePredicateOption: options = "[c]"; + break; + case CPDiacriticInsensitivePredicateOption: options = "[d]"; + break; case CPCaseInsensitivePredicateOption | CPDiacriticInsensitivePredicateOption: - options = "[cd]"; - break; - default: - options = ""; - break; + options = "[cd]"; + break; + + default: options = ""; + break; } var operator; switch (_type) { - case CPLessThanPredicateOperatorType: - operator = "<"; - break; - case CPLessThanOrEqualToPredicateOperatorType: - operator = "<="; - break; - case CPGreaterThanPredicateOperatorType: - operator = ">"; - break; - case CPGreaterThanOrEqualToPredicateOperatorType: - operator = ">="; - break; - case CPEqualToPredicateOperatorType: - operator = "=="; - break; - case CPNotEqualToPredicateOperatorType: - operator = "!="; - break; - case CPMatchesPredicateOperatorType: - operator = "MATCHES"; - break; - case CPLikePredicateOperatorType: - operator = "LIKE"; - break; - case CPBeginsWithPredicateOperatorType: - operator = "BEGINSWITH"; - break; - case CPEndsWithPredicateOperatorType: - operator = "ENDSWITH"; - break; - case CPInPredicateOperatorType: - operator = "IN"; - break; - case CPContainsPredicateOperatorType: - operator = "CONTAINS"; - break; - case CPCustomSelectorPredicateOperatorType: - operator = CPStringFromSelector(_customSelector); - break; + case CPLessThanPredicateOperatorType: operator = "<"; + break; + case CPLessThanOrEqualToPredicateOperatorType: operator = "<="; + break; + case CPGreaterThanPredicateOperatorType: operator = ">"; + break; + case CPGreaterThanOrEqualToPredicateOperatorType: operator = ">="; + break; + case CPEqualToPredicateOperatorType: operator = "=="; + break; + case CPNotEqualToPredicateOperatorType: operator = "!="; + break; + case CPMatchesPredicateOperatorType: operator = "MATCHES"; + break; + case CPLikePredicateOperatorType: operator = "LIKE"; + break; + case CPBeginsWithPredicateOperatorType: operator = "BEGINSWITH"; + break; + case CPEndsWithPredicateOperatorType: operator = "ENDSWITH"; + break; + case CPInPredicateOperatorType: operator = "IN"; + break; + case CPContainsPredicateOperatorType: operator = "CONTAINS"; + break; + case CPCustomSelectorPredicateOperatorType: operator = CPStringFromSelector(_customSelector); + break; } return [CPString stringWithFormat:@"%s%s %s%s %s",modifier,[_left description],operator,options,[_right description]]; @@ -399,76 +411,66 @@ var CPComparisonPredicateModifier, // left and right should be casted first [CAST()] following 10.5 rules. switch (_type) { - case CPLessThanPredicateOperatorType: - return ([lhs compare:rhs] == CPOrderedAscending); - case CPLessThanOrEqualToPredicateOperatorType: - return ([lhs compare:rhs] != CPOrderedDescending); - case CPGreaterThanPredicateOperatorType: - return ([lhs compare:rhs] == CPOrderedDescending); - case CPGreaterThanOrEqualToPredicateOperatorType: - return ([lhs compare:rhs] != CPOrderedAscending); - case CPEqualToPredicateOperatorType: - return [lhs isEqual:rhs]; - case CPNotEqualToPredicateOperatorType: - return (![lhs isEqual:rhs]); - case CPMatchesPredicateOperatorType: - var commut = (_options & CPCaseInsensitivePredicateOption) ? "gi":"g"; - if (_options & CPDiacriticInsensitivePredicateOption) - { - lhs = lhs.stripDiacritics(); - rhs = rhs.stripDiacritics(); - } + case CPLessThanPredicateOperatorType: return ([lhs compare:rhs] == CPOrderedAscending); + case CPLessThanOrEqualToPredicateOperatorType: return ([lhs compare:rhs] != CPOrderedDescending); + case CPGreaterThanPredicateOperatorType: return ([lhs compare:rhs] == CPOrderedDescending); + case CPGreaterThanOrEqualToPredicateOperatorType: return ([lhs compare:rhs] != CPOrderedAscending); + case CPEqualToPredicateOperatorType: return [lhs isEqual:rhs]; + case CPNotEqualToPredicateOperatorType: return (![lhs isEqual:rhs]); - return (new RegExp(rhs,commut)).test(lhs); - case CPLikePredicateOperatorType: - if (_options & CPDiacriticInsensitivePredicateOption) - { - lhs = lhs.stripDiacritics(); - rhs = rhs.stripDiacritics(); - } - var commut = (_options & CPCaseInsensitivePredicateOption) ? "gi":"g", - reg = new RegExp(rhs.escapeForRegExp(),commut); - return reg.test(lhs); - case CPBeginsWithPredicateOperatorType: - var range = CPMakeRange(0,[rhs length]); - if (_options & CPCaseInsensitivePredicateOption) string_compare_options |= CPCaseInsensitiveSearch; - if (_options & CPDiacriticInsensitivePredicateOption) string_compare_options |= CPDiacriticInsensitiveSearch; + case CPMatchesPredicateOperatorType: var commut = (_options & CPCaseInsensitivePredicateOption) ? "gi":"g"; + if (_options & CPDiacriticInsensitivePredicateOption) + { + lhs = lhs.stripDiacritics(); + rhs = rhs.stripDiacritics(); + } + return (new RegExp(rhs,commut)).test(lhs); - return ([lhs compare:rhs options:string_compare_options range:range] == CPOrderedSame); - case CPEndsWithPredicateOperatorType: - var range = CPMakeRange([lhs length] - [rhs length],[rhs length]); - if (_options & CPCaseInsensitivePredicateOption) string_compare_options |= CPCaseInsensitiveSearch; - if (_options & CPDiacriticInsensitivePredicateOption) string_compare_options |= CPDiacriticInsensitiveSearch; + case CPLikePredicateOperatorType: if (_options & CPDiacriticInsensitivePredicateOption) + { + lhs = lhs.stripDiacritics(); + rhs = rhs.stripDiacritics(); + } + var commut = (_options & CPCaseInsensitivePredicateOption) ? "gi":"g", + reg = new RegExp(rhs.escapeForRegExp(),commut); + return reg.test(lhs); - return ([lhs compare:rhs options:string_compare_options range:range] == CPOrderedSame); - case CPCustomSelectorPredicateOperatorType: - return [lhs performSelector:_customSelector withObject:rhs]; - case CPInPredicateOperatorType: - var a = lhs; // swap - lhs = rhs; - rhs = a; - case CPContainsPredicateOperatorType: - if (![lhs isKindOfClass:[CPString class]]) - { - if (![lhs respondsToSelector: @selector(objectEnumerator)]) - [CPException raise:CPInvalidArgumentException reason:@"The left/right hand side for a CONTAINS/IN operator must be a collection or a string"]; + case CPBeginsWithPredicateOperatorType: var range = CPMakeRange(0,[rhs length]); + if (_options & CPCaseInsensitivePredicateOption) string_compare_options |= CPCaseInsensitiveSearch; + if (_options & CPDiacriticInsensitivePredicateOption) string_compare_options |= CPDiacriticInsensitiveSearch; + return ([lhs compare:rhs options:string_compare_options range:range] == CPOrderedSame); - return [lhs containsObject:rhs]; - } + case CPEndsWithPredicateOperatorType: var range = CPMakeRange([lhs length] - [rhs length],[rhs length]); + if (_options & CPCaseInsensitivePredicateOption) string_compare_options |= CPCaseInsensitiveSearch; + if (_options & CPDiacriticInsensitivePredicateOption) string_compare_options |= CPDiacriticInsensitiveSearch; + return ([lhs compare:rhs options:string_compare_options range:range] == CPOrderedSame); - if (_options & CPCaseInsensitivePredicateOption) - string_compare_options |= CPCaseInsensitiveSearch; - if (_options & CPDiacriticInsensitivePredicateOption) - string_compare_options |= CPDiacriticInsensitiveSearch; + case CPCustomSelectorPredicateOperatorType: return [lhs performSelector:_customSelector withObject:rhs]; - return ([lhs rangeOfString:rhs options:string_compare_options].location != CPNotFound); - case CPBetweenPredicateOperatorType: - if ([rhs count] < 2) - [CPException raise:CPInvalidArgumentException reason:@"The right hand side for a BETWEEN operator must contain 2 objects"]; + case CPInPredicateOperatorType: var a = lhs; // swap + lhs = rhs; + rhs = a; + case CPContainsPredicateOperatorType: if (![lhs isKindOfClass:[CPString class]]) + { + if (![lhs respondsToSelector: @selector(objectEnumerator)]) + [CPException raise:CPInvalidArgumentException reason:@"The left/right hand side for a CONTAINS/IN operator must be a collection or a string"]; - return ([lhs compare:rhs[0]] == CPOrderedDescending && [lhs compare:rhs[1]] == CPOrderedAscending); - default: - return NO; + return [lhs containsObject:rhs]; + } + + if (_options & CPCaseInsensitivePredicateOption) + string_compare_options |= CPCaseInsensitiveSearch; + if (_options & CPDiacriticInsensitivePredicateOption) + string_compare_options |= CPDiacriticInsensitiveSearch; + + return ([lhs rangeOfString:rhs options:string_compare_options].location != CPNotFound); + + case CPBetweenPredicateOperatorType: if ([rhs count] < 2) + [CPException raise:CPInvalidArgumentException reason:@"The right hand side for a BETWEEN operator must contain 2 objects"]; + + return ([lhs compare:rhs[0]] == CPOrderedDescending && [lhs compare:rhs[1]] == CPOrderedAscending); + + default: return NO; } } @@ -541,8 +543,10 @@ var source = ['*','?','(',')','{','}','.','+','|','/','$','^'], String.prototype.escapeForRegExp = function() { - var foundChar = false; - for (var i = 0; i < source.length; ++i) + var foundChar = false, + i = 0; + + for (; i < source.length; ++i) { if (this.indexOf(source[i]) !== -1) { @@ -554,9 +558,9 @@ String.prototype.escapeForRegExp = function() if (!foundChar) return this; - var result = "", - sourceIndex; - for (var i = 0; i < this.length; ++i) + var result = ""; + + for (i = 0; i < this.length; ++i) { var sourceIndex = source.indexOf(this.charAt(i)); if (sourceIndex !== -1) diff --git a/Foundation/CPPredicate/CPCompoundPredicate.j b/Foundation/CPPredicate/CPCompoundPredicate.j index 5715152d5..e81a865fb 100644 --- a/Foundation/CPPredicate/CPCompoundPredicate.j +++ b/Foundation/CPPredicate/CPCompoundPredicate.j @@ -1,4 +1,25 @@ +/* + * CPCompoundPredicate.j + * Foundation + * + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +@import "CPArray.j" @import "CPPredicate.j" /*! @@ -45,8 +66,13 @@ var CPCompoundPredicateType; */ - (id)initWithType:(CPCompoundPredicateType)type subpredicates:(CPArray)predicates { - _type = type; - _predicates = predicates; + self = [super init]; + + if (self) + { + _type = type; + _predicates = predicates; + } return self; } @@ -103,10 +129,10 @@ var CPCompoundPredicateType; - (CPPredicate)predicateWithSubstitutionVariables:(CPDictionary)variables { var subp = [CPArray array], - count = [subp count]; - i; + count = [subp count], + i = 0; - for (i = 0; i < count; i++) + for (; i < count; i++) { var p = [subp objectAtIndex:i], sp = [p predicateWithSubstitutionVariables:variables]; @@ -122,12 +148,12 @@ var CPCompoundPredicateType; var result = "", args = [CPArray array], count = [_predicates count], - i; + i = 0; if (count == 0) return @"TRUPREDICATE"; - for (i = 0; i < count; i++) + for (; i < count; i++) { var subpredicate = [_predicates objectAtIndex:i], precedence = [subpredicate predicateFormat]; @@ -141,21 +167,20 @@ var CPCompoundPredicateType; switch (_type) { - case CPNotPredicateType: - result += "NOT %s" + [args objectAtIndex:0]; - break; - case CPAndPredicateType: - result += [args objectAtIndex:0]; - var count = [args count]; - for (var j = 1; j < count; j++) - result += " AND " + [args objectAtIndex:j]; - break; - case CPOrPredicateType: - result += [args objectAtIndex:0]; - var count = [args count]; - for (var j = 1; j < count; j++) - result += " OR " + [args objectAtIndex:j]; - break; + case CPNotPredicateType: result += "NOT %s" + [args objectAtIndex:0]; + break; + + case CPAndPredicateType: result += [args objectAtIndex:0]; + var count = [args count]; + for (var j = 1; j < count; j++) + result += " AND " + [args objectAtIndex:j]; + break; + + case CPOrPredicateType: result += [args objectAtIndex:0]; + var count = [args count]; + for (var j = 1; j < count; j++) + result += " OR " + [args objectAtIndex:j]; + break; } return result; @@ -170,31 +195,30 @@ var CPCompoundPredicateType; { var result = NO, count = [_predicates count], - i; + i = 0; if (count == 0) return YES; - for (i = 0; i < count; i++) + for (; i < count; i++) { var predicate = [_predicates objectAtIndex:i]; switch (_type) { - case CPNotPredicateType: - return ![predicate evaluateWithObject:object substitutionVariables:variables]; - case CPAndPredicateType: - if (i == 0) - result = [predicate evaluateWithObject:object substitutionVariables:variables]; - else - result = result && [predicate evaluateWithObject:object substitutionVariables:variables]; - if (!result) - return NO; - break; - case CPOrPredicateType: - if ([predicate evaluateWithObject:object substitutionVariables:variables]) - return YES; - break; + case CPNotPredicateType: return ![predicate evaluateWithObject:object substitutionVariables:variables]; + + case CPAndPredicateType: if (i == 0) + result = [predicate evaluateWithObject:object substitutionVariables:variables]; + else + result = result && [predicate evaluateWithObject:object substitutionVariables:variables]; + if (!result) + return NO; + break; + + case CPOrPredicateType: if ([predicate evaluateWithObject:object substitutionVariables:variables]) + return YES; + break; } } diff --git a/Foundation/CPPredicate/CPExpression.j b/Foundation/CPPredicate/CPExpression.j index 40ac4c695..023f1b612 100644 --- a/Foundation/CPPredicate/CPExpression.j +++ b/Foundation/CPPredicate/CPExpression.j @@ -1,13 +1,34 @@ +/* + * CPExpression.j + * Foundation + * + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ -@import "CPString.j" @import "CPArray.j" -@import "CPKeyValueCoding.j" @import "CPDictionary.j" +@import "CPKeyValueCoding.j" +@import "CPObject.j" +@import "CPString.j" /*! An expression that always returns the same value. */ -CPConstantValueExpressionType = 0; +CPConstantValueExpressionType = 0; /*! An expression that always returns the parameter object itself. */ @@ -15,35 +36,35 @@ CPEvaluatedObjectExpressionType = 1; /*! An expression that always returns whatever value is associated with the key specified by ‘variable’ in the bindings dictionary. */ -CPVariableExpressionType = 2; +CPVariableExpressionType = 2; /*! An expression that returns something that can be used as a key path. */ -CPKeyPathExpressionType = 3; +CPKeyPathExpressionType = 3; /*! An expression that returns the result of evaluating a function. */ -CPFunctionExpressionType = 4; +CPFunctionExpressionType = 4; /*! An expression that defines an aggregate of CPExpression objects. */ -CPAggregateExpressionType = 5; +CPAggregateExpressionType = 5; /*! An expression that filters a collection using a subpredicate. */ -CPSubqueryExpressionType = 6; +CPSubqueryExpressionType = 6; /*! An expression that creates a union of the results of two nested expressions. */ -CPUnionSetExpressionType = 7; +CPUnionSetExpressionType = 7; /*! An expression that creates an intersection of the results of two nested expressions. */ -CPIntersectSetExpressionType = 8; +CPIntersectSetExpressionType = 8; /*! An expression that combines two nested expression results by set subtraction. */ -CPMinusSetExpressionType = 9; +CPMinusSetExpressionType = 9; /*! @ingroup foundation diff --git a/Foundation/CPPredicate/CPExpression_aggregate.j b/Foundation/CPPredicate/CPExpression_aggregate.j index 47be66fc3..0d0578be9 100644 --- a/Foundation/CPPredicate/CPExpression_aggregate.j +++ b/Foundation/CPPredicate/CPExpression_aggregate.j @@ -1,6 +1,26 @@ +/* + * CPExpression_aggregate.j + * Foundation + * + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ -@import "CPExpression.j" @import "CPArray.j" +@import "CPExpression.j" @import "CPString.j" @implementation CPExpression_aggregate : CPExpression @@ -10,8 +30,10 @@ - (id)initWithAggregate:(CPArray)collection { - [super initWithExpressionType:CPAggregateExpressionType]; - _aggregate = collection; + self = [super initWithExpressionType:CPAggregateExpressionType]; + + if (self) + _aggregate = collection; return self; } @@ -48,11 +70,11 @@ - (CPString)description { - var i, + var i = 0, count = [_aggregate count], result = "{"; - for (i = 0; i < count; i++) + for (; i < count; i++) result = result + [CPString stringWithFormat:@"%s%s", [[_aggregate objectAtIndex:i] description], (i + 1 < count) ? @", " : @""]; result = result + "}"; @@ -64,9 +86,9 @@ { var subst_array = [CPArray array], count = [_aggregate count], - i; + i = 0; - for (i = 0; i < count; i++) + for (; i < count; i++) [subst_array addObject:[[_aggregate objectAtIndex:i] _expressionWithSubstitutionVariables:variables]]; return [CPExpression expressionForAggregate:subst_array]; diff --git a/Foundation/CPPredicate/CPExpression_constant.j b/Foundation/CPPredicate/CPExpression_constant.j index 01ca5084b..ec98e72e4 100644 --- a/Foundation/CPPredicate/CPExpression_constant.j +++ b/Foundation/CPPredicate/CPExpression_constant.j @@ -1,6 +1,26 @@ +/* + * CPExpression_constant.j + * Foundation + * + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ -@import "CPExpression.j" @import "CPDictionary.j" +@import "CPExpression.j" @implementation CPExpression_constant : CPExpression { @@ -9,8 +29,10 @@ - (id)initWithValue:(id)value { - [super initWithExpressionType:CPConstantValueExpressionType]; - _value = value; + self = [super initWithExpressionType:CPConstantValueExpressionType]; + + if (self) + _value = value; return self; } diff --git a/Foundation/CPPredicate/CPExpression_function.j b/Foundation/CPPredicate/CPExpression_function.j index 72c8762dd..a1f42a528 100644 --- a/Foundation/CPPredicate/CPExpression_function.j +++ b/Foundation/CPPredicate/CPExpression_function.j @@ -1,8 +1,30 @@ +/* + * CPExpression_function.j + * Foundation + * + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +@import "CPArray.j" +@import "CPDate.j" +@import "CPDictionary.j" +@import "CPException.j" @import "CPExpression.j" @import "CPString.j" -@import "CPArray.j" -@import "CPDictionary.j" @implementation CPExpression_function : CPExpression { @@ -30,16 +52,18 @@ - (id)initWithTarget:(CPExpression)operand selector:(SEL)aSelector arguments:(CPArray)parameters type:(int)type { - [super initWithExpressionType:type]; - -// Cocoa doc: "This method throws an exception immediately if the selector is unknown" -// but operand's value (the target) may be resolved only at runtime. - _selector = aSelector; - _operand = operand; - _arguments = parameters; - _argc = [parameters count]; - _maxargs = [[CPStringFromSelector(_selector) componentsSeparatedByString:@":"] count] - 1; + self = [super initWithExpressionType:type]; + if (self) + { + // Cocoa doc: "This method throws an exception immediately if the selector is unknown" + // but operand's value (the target) may be resolved only at runtime. + _selector = aSelector; + _operand = operand; + _arguments = parameters; + _argc = [parameters count]; + _maxargs = [[CPStringFromSelector(_selector) componentsSeparatedByString:@":"] count] - 1; + } return self; } @@ -78,9 +102,9 @@ { var target = [_operand expressionValueWithObject:object context:context], objj_args = [target, _selector], - i; + i = 0; - for (i = 0; i < _argc; i++) + for (; i < _argc; i++) { var arg = [_arguments[i] expressionValueWithObject:object context:context]; objj_args.push(arg); @@ -119,9 +143,10 @@ - (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables { var operand = [[self operand] _expressionWithSubstitutionVariables:variables], - args = [CPArray array]; + args = [CPArray array], + i = 0; - for (var i = 0; i < _argc; i++) + for (; i < _argc; i++) [args addObject:[_arguments[i] _expressionWithSubstitutionVariables:variables]]; return [CPExpression expressionForFunction:operand selectorName:[self _function] arguments:args]; @@ -129,9 +154,9 @@ @end -var CPSelectorNameKey = @"CPSelectorName", - CPArgumentsKey = @"CPArguments", - CPOperandKey = @"CPOperand", +var CPSelectorNameKey = @"CPSelectorName", + CPArgumentsKey = @"CPArguments", + CPOperandKey = @"CPOperand", CPExpressionTypeKey = @"CPExpressionType"; @implementation CPExpression_function (CPCoding) @@ -283,4 +308,3 @@ var CPSelectorNameKey = @"CPSelectorName", } @end - diff --git a/Foundation/CPPredicate/CPExpression_keypath.j b/Foundation/CPPredicate/CPExpression_keypath.j index 05d52e8cd..31eb27282 100644 --- a/Foundation/CPPredicate/CPExpression_keypath.j +++ b/Foundation/CPPredicate/CPExpression_keypath.j @@ -1,8 +1,28 @@ +/* + * CPExpression_keypath.j + * Foundation + * + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ @import "CPExpression.j" @import "CPExpression_function.j" -@import "CPString.j" @import "CPKeyValueCoding.j" +@import "CPString.j" @implementation CPExpression_keypath : CPExpression_function { diff --git a/Foundation/CPPredicate/CPExpression_self.j b/Foundation/CPPredicate/CPExpression_self.j index a313fe8ba..11db5c919 100644 --- a/Foundation/CPPredicate/CPExpression_self.j +++ b/Foundation/CPPredicate/CPExpression_self.j @@ -1,9 +1,30 @@ +/* + * CPExpression_self.j + * Foundation + * + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +@import "CPDictionary.j" @import "CPExpression.j" @import "CPString.j" -@import "CPDictionary.j" var evaluatedObject = nil; + @implementation CPExpression_self : CPExpression { } @@ -18,7 +39,7 @@ var evaluatedObject = nil; - (id)init { - [super initWithExpressionType:CPEvaluatedObjectExpressionType]; + self = [super initWithExpressionType:CPEvaluatedObjectExpressionType]; return self; } diff --git a/Foundation/CPPredicate/CPExpression_set.j b/Foundation/CPPredicate/CPExpression_set.j index 9be28e076..5d4140e19 100644 --- a/Foundation/CPPredicate/CPExpression_set.j +++ b/Foundation/CPPredicate/CPExpression_set.j @@ -1,5 +1,27 @@ +/* + * CPExpression_set.j + * Foundation + * + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +@import "CPException.j" @import "CPExpression.j" +@import "CPSet.j" @implementation CPExpression_set : CPExpression { @@ -9,9 +31,13 @@ - (id)initWithType:(int)type left:(CPExpression)left right:(CPExpression)right { - [super initWithExpressionType:type]; - _left = left; - _right = right; + self = [super initWithExpressionType:type]; + + if (self) + { + _left = left; + _right = right; + } return self; } @@ -45,11 +71,11 @@ switch (_type) { case CPIntersectSetExpressionType : [result intersectSet:right]; - break; + break; case CPUnionSetExpressionType : [result unionSet:right]; - break; + break; case CPMinusSetExpressionType : [result minusSet:right]; - break; + break; default: } @@ -78,11 +104,11 @@ switch (_type) { case CPIntersectSetExpressionType : desc = @" INTERSECT "; - break; - case CPUnionSetExpressionType : desc = @" UNION "; - break; - case CPMinusSetExpressionType : desc = @" MINUS "; - break; + break; + case CPUnionSetExpressionType : desc = @" UNION "; + break; + case CPMinusSetExpressionType : desc = @" MINUS "; + break; default: } @@ -91,9 +117,9 @@ @end -var CPLeftExpressionKey = @"CPLeftExpression", - CPRightExpressionKey = @"CPRightExpression", - CPExpressionType = @"CPExpressionType"; +var CPLeftExpressionKey = @"CPLeftExpression", + CPRightExpressionKey = @"CPRightExpression", + CPExpressionType = @"CPExpressionType"; @implementation CPExpression_set (CPCoding) diff --git a/Foundation/CPPredicate/CPExpression_subquery.j b/Foundation/CPPredicate/CPExpression_subquery.j index 912f50d8e..38fa287d3 100644 --- a/Foundation/CPPredicate/CPExpression_subquery.j +++ b/Foundation/CPPredicate/CPExpression_subquery.j @@ -1,5 +1,28 @@ +/* + * CPExpression_subquery.j + * Foundation + * + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +@import "CPArray.j" +@import "CPDictionary.j" @import "CPExpression.j" +@import "CPPredicate.j" @implementation CPExpression_subquery : CPExpression { @@ -16,12 +39,14 @@ - (id)initWithExpression:(CPExpression)collection usingIteratorExpression:(CPExpression)variableExpression predicate:(CPPredicate)subpredicate { - [super initWithExpressionType:CPSubqueryExpressionType]; - - _subpredicate = subpredicate; - _collection = collection; - _variableExpression = variableExpression; + self = [super initWithExpressionType:CPSubqueryExpressionType]; + if (self) + { + _subpredicate = subpredicate; + _collection = collection; + _variableExpression = variableExpression; + } return self; } @@ -30,10 +55,10 @@ var collection = [_collection expressionValueWithObject:object context:context], count = [collection count], result = [CPArray array], + bindings = [CPDictionary dictionaryWithObject:[CPExpression expressionForEvaluatedObject] forKey:[self variable]], + i = 0; - bindings = [CPDictionary dictionaryWithObject:[CPExpression expressionForEvaluatedObject] forKey:[self variable]]; - - for (var i = 0; i < count; i++) + for (; i < count; i++) { var item = [collection objectAtIndex:i]; if ([_subpredicate evaluateWithObject:item substitutionVariables:bindings]) @@ -90,9 +115,9 @@ } @end -var CPExpressionKey = @"CPExpression", - CPSubpredicateKey = @"CPSubpredicate", - CPVariableKey = @"CPVariable"; +var CPExpressionKey = @"CPExpression", + CPSubpredicateKey = @"CPSubpredicate", + CPVariableKey = @"CPVariable"; @implementation CPExpression_subquery (CPCoding) diff --git a/Foundation/CPPredicate/CPExpression_variable.j b/Foundation/CPPredicate/CPExpression_variable.j index 340c858b2..b48937aa7 100644 --- a/Foundation/CPPredicate/CPExpression_variable.j +++ b/Foundation/CPPredicate/CPExpression_variable.j @@ -1,7 +1,28 @@ +/* + * CPExpression_variable.j + * Foundation + * + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +@import "CPDictionary.j" +@import "CPException.j" @import "CPExpression.j" @import "CPString.j" -@import "CPDictionary.j" @implementation CPExpression_variable : CPExpression { @@ -10,9 +31,12 @@ - (id)initWithVariable:(CPString)variable { - [super initWithExpressionType:CPVariableExpressionType]; - _variable = [variable copy]; + self = [super initWithExpressionType:CPVariableExpressionType]; + if (self) + { + _variable = [variable copy]; + } return self; } diff --git a/Foundation/CPPredicate/CPPredicate.j b/Foundation/CPPredicate/CPPredicate.j index 7f323b047..8b5e9ff96 100644 --- a/Foundation/CPPredicate/CPPredicate.j +++ b/Foundation/CPPredicate/CPPredicate.j @@ -1,9 +1,32 @@ +/* + * CPPredicate.j + * Foundation + * + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ -@import "CPValue.j" @import "CPArray.j" -@import "CPSet.j" +@import "CPException.j" @import "CPNull.j" +@import "CPObject.j" @import "CPScanner.j" +@import "CPSet.j" +@import "CPValue.j" +@import "CPCharacterSet.j" /*! @ingroup foundation @@ -164,9 +187,9 @@ { var count = [self count], result = [CPArray array], - i; + i = 0; - for (i = 0; i < count; i++) + for (; i < count; i++) { var object = self[i]; if ([predicate evaluateWithObject:object]) @@ -195,9 +218,9 @@ { var count = [self count], result = [CPSet set], - i; + i = 0; - for (i = 0; i < count; i++) + for (; i < count; i++) { var object = [self objectAtIndex:i]; @@ -240,8 +263,9 @@ function(newValue)\ - (id)initWithString:(CPString)format args:(CPArray)args { - self = [super initWithString:format]; - if (self != nil) + self = [super initWithString:format] + + if (self) { _args = [args objectEnumerator]; } @@ -255,8 +279,7 @@ function(newValue)\ - (BOOL)scanPredicateKeyword:(CPString)key { - var loc = [self scanLocation], - c; + var loc = [self scanLocation]; [self setCaseSensitive:NO]; if (![self scanString:key intoString:NULL]) @@ -265,7 +288,7 @@ function(newValue)\ if ([self isAtEnd]) return YES; - c = [[self string] characterAtIndex:[self scanLocation]]; + var c = [[self string] characterAtIndex:[self scanLocation]]; if (![[CPCharacterSet alphanumericCharacterSet] characterIsMember:c]) return YES; @@ -285,7 +308,7 @@ function(newValue)\ } catch(error) { - CPLogConsole(@"Unable to parse predicate '"+[self string]+"' with " + error); + CPLogConsole(@"Unable to parse predicate '" + [self string] + "' with " + error); } finally { diff --git a/Foundation/CPScanner.j b/Foundation/CPScanner.j index a1976ae7c..f83ddebf1 100644 --- a/Foundation/CPScanner.j +++ b/Foundation/CPScanner.j @@ -320,7 +320,7 @@ if (f) { - var pos = current, + var pos = current, foundDash = NO; /* var decimalSeparatorString; @@ -367,7 +367,7 @@ if (i) { - var pos = current, + var pos = current, foundDash = NO; for (; pos < current + str.length; pos++) From bfe03a8874c2ab89852c3121f11ce2b74c1b057d Mon Sep 17 00:00:00 2001 From: Stephen Ierodiaconou Date: Sun, 26 Dec 2010 01:05:40 +0200 Subject: [PATCH 3/6] CPJSONPConnection Missing imports and self check --- Foundation/CPJSONPConnection.j | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Foundation/CPJSONPConnection.j b/Foundation/CPJSONPConnection.j index f69a5c954..62ba4c536 100644 --- a/Foundation/CPJSONPConnection.j +++ b/Foundation/CPJSONPConnection.j @@ -20,8 +20,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +@import "CPException.j" @import "CPObject.j" - +@import "CPRunLoop.j" CPJSONPConnectionCallbacks = {}; @@ -68,16 +69,19 @@ CPJSONPCallbackReplacementString = @"${JSONP_CALLBACK}"; { self = [super init]; - _request = aRequest; - _delegate = aDelegate; + if (self) + { + _request = aRequest; + _delegate = aDelegate; - _callbackParameter = aString; + _callbackParameter = aString; - if (!_callbackParameter && [[_request URL] absoluteString].indexOf(CPJSONPCallbackReplacementString) < 0) - [CPException raise:CPInvalidArgumentException reason:@"JSONP source specified without callback parameter or CPJSONPCallbackReplacementString in URL."]; + if (!_callbackParameter && [[_request URL] absoluteString].indexOf(CPJSONPCallbackReplacementString) < 0) + [CPException raise:CPInvalidArgumentException reason:@"JSONP source specified without callback parameter or CPJSONPCallbackReplacementString in URL."]; - if (shouldStartImmediately) - [self start]; + if (shouldStartImmediately) + [self start]; + } return self; } From 7ae14e9eb550ab41057e00d89a7f3518f37429c3 Mon Sep 17 00:00:00 2001 From: Stephen Ierodiaconou Date: Sun, 26 Dec 2010 01:29:07 +0200 Subject: [PATCH 4/6] CPCharacterSet lint and fixes --- Foundation/CPCharacterSet.j | 45 +++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/Foundation/CPCharacterSet.j b/Foundation/CPCharacterSet.j index 92600eced..f00f213c9 100644 --- a/Foundation/CPCharacterSet.j +++ b/Foundation/CPCharacterSet.j @@ -19,8 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import -@import +@import "CPArray.j" +@import "CPException.j" +@import "CPObject.j" +@import "CPString.j" // CPCharacterSet is a class cluster. Concrete implementations // follow after the main abstract class. @@ -48,7 +50,9 @@ var _builtInCharacterSets = {}; - (id)init { self = [super init]; - _inverted = NO; + + if (self) + _inverted = NO; return self; } @@ -144,11 +148,11 @@ var _builtInCharacterSets = {}; var cs = _builtInCharacterSets[csname]; if (cs == nil) { - var i, + var i = 0, ranges = [CPArray array], rangeArray = eval(csname); - for (i = 0; i < rangeArray.length; i+= 2) + for (; i < rangeArray.length; i+= 2) { var loc = rangeArray[i], length = rangeArray[i + 1], @@ -185,7 +189,9 @@ var _builtInCharacterSets = {}; // Creates a range character set with multiple ranges. - (id)initWithRanges:(CPArray)ranges { - if (self = [super init]) + self = [super init]; + + if (self) { _ranges = ranges; } @@ -238,9 +244,9 @@ var _builtInCharacterSets = {}; - (void)addCharactersInString:(CPString)aString // Needs _inverted support { - var i; + var i = 0; - for (i = 0; i < aString.length; i++) + for (; i < aString.length; i++) { var code = aString.charCodeAt(i), range = CPMakeRange(code,1); @@ -260,7 +266,9 @@ var _builtInCharacterSets = {}; - (id)initWithString:(CPString)s { - if (self = [super init]) + self = [super init]; + + if (self) { _string = s; } @@ -307,8 +315,10 @@ var _builtInCharacterSets = {}; - (void)addCharactersInRange:(CPRange)aRange // Needs _inverted support { - var i; - for (i = aRange.location; i < aRange.location + aRange.length; i++) + var i = aRange.location, + count = aRange.location + aRange.length; + + for (; i < count; i++) { var s = String.fromCharCode(i); @@ -319,9 +329,9 @@ var _builtInCharacterSets = {}; - (void)addCharactersInString:(CPString)aString // Needs _inverted support { - var i; + var i = 0; - for (i = 0; i < aString.length; i++) + for (; i < aString.length; i++) { var s = aString.charAt(i); @@ -332,8 +342,8 @@ var _builtInCharacterSets = {}; @end -_CPCharacterSetTrimAtBeginning = 1 << 1; -_CPCharacterSetTrimAtEnd = 1 << 2; +_CPCharacterSetTrimAtBeginning = 1 << 1; +_CPCharacterSetTrimAtEnd = 1 << 2; @implementation CPString (CPCharacterSetAdditions) @@ -356,9 +366,10 @@ _CPCharacterSetTrimAtEnd = 1 << 2; reason:"componentsSeparatedByCharactersInSet: the separator can't be 'nil'"]; var components = [CPMutableArray array], - componentRange = CPMakeRange(0, 0); + componentRange = CPMakeRange(0, 0), + i = 0; - for (var i = 0; i < self.length; i++) + for (; i < self.length; i++) { if ([separator characterIsMember:self.charAt(i)]) { From 4aa4f1a62a08f1d827cbb589df3f37268d03efc7 Mon Sep 17 00:00:00 2001 From: Stephen Ierodiaconou Date: Sun, 26 Dec 2010 01:47:26 +0200 Subject: [PATCH 5/6] Some more missing imports --- Foundation/CPCharacterSet.j | 3 ++- Foundation/CPString.j | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Foundation/CPCharacterSet.j b/Foundation/CPCharacterSet.j index f00f213c9..6a0b1d524 100644 --- a/Foundation/CPCharacterSet.j +++ b/Foundation/CPCharacterSet.j @@ -23,6 +23,7 @@ @import "CPException.j" @import "CPObject.j" @import "CPString.j" +@import "CPURL.j" // CPCharacterSet is a class cluster. Concrete implementations // follow after the main abstract class. @@ -232,7 +233,7 @@ var _builtInCharacterSets = {}; { // the highest Unicode plane we reach. // (There are 65536 code points in each plane.) - var maxPlane = Math.floor((range.start + range.length - 1) / 65536); // should iterate _ranges + var maxPlane = Math.floor((range.start + range.length - 1) / 65536); // FIXME: should iterate _ranges return (plane <= maxPlane); } diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 3955ab1c5..6a75bcaff 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -25,6 +25,7 @@ @import "CPObjJRuntime.j" @import "CPRange.j" @import "CPSortDescriptor.j" +@import "CPURL.j" @import "CPValue.j" /*! From 76b568223428f68fd7c47a8b10a2c31ce9946d31 Mon Sep 17 00:00:00 2001 From: Stephen Ierodiaconou Date: Sun, 26 Dec 2010 10:29:46 +0200 Subject: [PATCH 6/6] Missing imports in CPSet+KVO --- Foundation/CPSet+KVO.j | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Foundation/CPSet+KVO.j b/Foundation/CPSet+KVO.j index 7e7fbb611..cf8d693d4 100644 --- a/Foundation/CPSet+KVO.j +++ b/Foundation/CPSet+KVO.j @@ -20,6 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +@import "CPException.j" +@import "CPObject.j" @import "CPSet.j" @implementation CPObject (CPSetKVO)