diff --git a/Foundation/CPArray.j b/Foundation/CPArray.j index 14e387f3f..ab149a6fb 100755 --- a/Foundation/CPArray.j +++ b/Foundation/CPArray.j @@ -37,7 +37,7 @@ - (id)initWithArray:(CPArray)anArray { self = [super init]; - + if (self) { _array = anArray; @@ -67,13 +67,13 @@ - (id)initWithArray:(CPArray)anArray { self = [super init]; - + if (self) { _array = anArray; _index = [_array count]; } - + return self; } @@ -87,7 +87,7 @@ @end -/*! +/*! @class CPArray @brief A mutable array backed by a JavaScript Array. @ingroup foundation @@ -147,7 +147,7 @@ array = [[self alloc] init], argument; - for(; i < arguments.length && (argument = arguments[i]) != nil; ++i) + for (; i < arguments.length && (argument = arguments[i]) != nil; ++i) array.push(argument); return array; @@ -182,10 +182,10 @@ - (id)initWithArray:(CPArray)anArray { self = [super init]; - + if (self) [self setArray:anArray]; - + return self; } @@ -203,13 +203,13 @@ return [self initWithArray:anArray]; self = [super init]; - + if (self) { var index = 0, count = [anArray count]; - - for(; index < count; ++index) + + for (; index < count; ++index) { if (anArray[index].isa) self[index] = [anArray[index] copy]; @@ -218,7 +218,7 @@ self[index] = anArray[index]; } } - + return self; } @@ -230,11 +230,11 @@ // The arguments array contains self and _cmd, so the first object is at position 2. var i = 2, argument; - - for(; i < arguments.length && (argument = arguments[i]) != nil; ++i) + + for (; i < arguments.length && (argument = arguments[i]) != nil; ++i) push(argument); - return self; + return self; } /*! @@ -246,12 +246,12 @@ - (id)initWithObjects:(id)objects count:(unsigned)aCount { self = [super init]; - + if (self) { var index = 0; - - for(; index < aCount; ++index) + + for (; index < aCount; ++index) push(objects[index]); } @@ -287,27 +287,27 @@ { if (anObject === nil) return CPNotFound; - - var i = 0, + + var i = 0, count = length; // Only use -isEqual: if our object is a CPObject. if (anObject.isa) { - for(; i < count; ++i) - if([self[i] isEqual:anObject]) + for (; i < count; ++i) + if ([self[i] isEqual:anObject]) return i; } - // If indexOf exists, use it since it's probably + // If indexOf exists, use it since it's probably // faster than anything we can implement. else if (self.indexOf) return indexOf(anObject); // Last resort, do a straight forward linear O(N) search. else - for(; i < count; ++i) - if(self[i] == anObject) + for (; i < count; ++i) + if (self[i] == anObject) return i; - + return CPNotFound; } @@ -323,23 +323,23 @@ { if (anObject === nil) return CPNotFound; - - var i = aRange.location, + + var i = aRange.location, count = MIN(CPMaxRange(aRange), length); - + // Only use isEqual: if our object is a CPObject. if (anObject.isa) { - for(; i < count; ++i) - if([self[i] isEqual:anObject]) + for (; i < count; ++i) + if ([self[i] isEqual:anObject]) return i; } // Last resort, do a straight forward linear O(N) search. else - for(; i < count; ++i) - if(self[i] == anObject) + for (; i < count; ++i) + if (self[i] == anObject) return i; - + return CPNotFound; } @@ -352,23 +352,23 @@ { if (anObject === nil) return CPNotFound; - - // If indexOf exists, use it since it's probably + + // If indexOf exists, use it since it's probably // faster than anything we can implement. if (self.indexOf) return indexOf(anObject); - + // Last resort, do a straight forward linear O(N) search. else { - var index = 0, + var index = 0, count = length; - - for(; index < count; ++index) - if(self[index] === anObject) + + for (; index < count; ++index) + if (self[index] === anObject) return index; } - + return CPNotFound; } @@ -384,34 +384,34 @@ { if (anObject === nil) return CPNotFound; - - // If indexOf exists, use it since it's probably + + // If indexOf exists, use it since it's probably // faster than anything we can implement. if (self.indexOf) { var index = indexOf(anObject, aRange.location); - + if (CPLocationInRange(index, aRange)) return index; } - + // Last resort, do a straight forward linear O(N) search. else { - var index = aRange.location, + var index = aRange.location, count = MIN(CPMaxRange(aRange), length); - - for(; index < count; ++index) - if(self[index] == anObject) + + for (; index < count; ++index) + if (self[index] == anObject) return index; } - + return CPNotFound; } /*! Returns the index of \c anObject in the array, which must be sorted in the same order as - calling sortUsingSelector: with the selector passed to this method would result in. + calling sortUsingSelector: with the selector passed to this method would result in. @param anObject the object to search for @param aSelector the comparison selector to call on each item in the list, the same selector should have been used to sort the array (or to maintain its sorted order). @@ -419,12 +419,12 @@ */ - (unsigned)indexOfObject:(id)anObject sortedBySelector:(SEL)aSelector { - return [self indexOfObject:anObject sortedByFunction: function(lhs, rhs) { objj_msgSend(lhs, aSelector, rhs); }]; + return [self indexOfObject:anObject sortedByFunction:function(lhs, rhs) { objj_msgSend(lhs, aSelector, rhs); }]; } /*! Returns the index of \c anObject in the array, which must be sorted in the same order as - calling sortUsingFunction: with the selector passed to this method would result in. + calling sortUsingFunction: with the selector passed to this method would result in. The function will be called like so:
     aFunction(anObject, currentObjectInArrayForComparison)
@@ -441,7 +441,7 @@
 
 /*!
     Returns the index of \c anObject in the array, which must be sorted in the same order as
-    calling sortUsingFunction: with the selector passed to this method would result in. 
+    calling sortUsingFunction: with the selector passed to this method would result in.
     The function will be called like so:
     
     aFunction(anObject, currentObjectInArrayForComparison, context)
@@ -466,7 +466,11 @@
     if (length === 0)
         return -1;
 
-    var mid, c, first = 0, last = length - 1;
+    var mid,
+        c,
+        first = 0,
+        last = length - 1;
+
     while (first <= last)
     {
         mid = FLOOR((first + last) / 2);
@@ -485,12 +489,12 @@
         }
     }
 
-    return -first-1;
+    return -first - 1;
 }
 
 /*!
     Returns the index of \c anObject in the array, which must be sorted in the same order as
-    calling sortUsingDescriptors: with the descriptors passed to this method would result in. 
+    calling sortUsingDescriptors: with the descriptors passed to this method would result in.
     @param anObject the object to search for
     @param descriptors the array of descriptors to use to compare each item in the array that we search. the same
     descriptors should have been used to sort the array (or to maintain its sorted order).
@@ -505,7 +509,7 @@
             result = CPOrderedSame;
 
         while (i < count)
-            if((result = [descriptors[i++] compareObject:lhs withObject:rhs]) != CPOrderedSame)
+            if ((result = [descriptors[i++] compareObject:lhs withObject:rhs]) != CPOrderedSame)
                 return result;
 
         return result;
@@ -518,9 +522,9 @@
 - (id)lastObject
 {
     var count = [self count];
-    
+
     if (!count) return nil;
-    
+
     return self[count - 1];
 }
 
@@ -546,7 +550,7 @@
     var index = CPNotFound,
         objects = [];
 
-    while((index = [indexes indexGreaterThanIndex:index]) !== CPNotFound)
+    while ((index = [indexes indexGreaterThanIndex:index]) !== CPNotFound)
         [objects addObject:[self objectAtIndex:index]];
 
     return objects;
@@ -582,11 +586,11 @@
 {
     if (!aSelector)
         [CPException raise:CPInvalidArgumentException reason:"makeObjectsPerformSelector: 'aSelector' can't be nil"];
-    
-    var index = 0, 
+
+    var index = 0,
         count = length;
-        
-    for(; index < count; ++index)
+
+    for (; index < count; ++index)
         objj_msgSend(self[index], aSelector);
 }
 
@@ -601,10 +605,10 @@
     if (!aSelector)
         [CPException raise:CPInvalidArgumentException reason:"makeObjectsPerformSelector:withObject 'aSelector' can't be nil"];
 
-    var index = 0, 
+    var index = 0,
         count = length;
-        
-    for(; index < count; ++index) 
+
+    for (; index < count; ++index)
         objj_msgSend(self[index], aSelector, anObject);
 }
 
@@ -617,7 +621,7 @@
         count = length,
         argumentsArray = [nil, aSelector].concat(objects || []);
 
-    for(; index < count; ++index)
+    for (; index < count; ++index)
     {
         argumentsArray[0] = self[index];
         objj_msgSend.apply(this, argumentsArray);
@@ -635,12 +639,12 @@
 {
     if (![anArray count] || ![self count])
         return nil;
-    
+
     var i = 0,
         count = [self count];
 
-    for(; i < count; ++i)
-        if([anArray containsObject:self[i]])
+    for (; i < count; ++i)
+        if ([anArray containsObject:self[i]])
             return self[i];
 
     return nil;
@@ -656,20 +660,20 @@
 
     if (anArray === nil || length !== anArray.length)
         return NO;
-    
+
     var index = 0,
         count = [self count];
-    
-    for(; index < count; ++index)
+
+    for (; index < count; ++index)
     {
         var lhs = self[index],
             rhs = anArray[index];
-        
+
         // If they're not equal, and either doesn't have an isa, or they're !isEqual (not isEqual)
         if (lhs !== rhs && (lhs && !lhs.isa || rhs && !rhs.isa || ![lhs isEqual:rhs]))
             return NO;
     }
-        
+
     return YES;
 }
 
@@ -677,8 +681,8 @@
 {
     if (self === anObject)
         return YES;
-    
-    if(![anObject isKindOfClass:[CPArray class]])
+
+    if (![anObject isKindOfClass:[CPArray class]])
         return NO;
 
     return [self isEqualToArray:anObject];
@@ -698,9 +702,9 @@
                     reason:"arrayByAddingObject: object can't be nil"];
 
     var array = [self copy];
-    
+
     array.push(anObject);
-    
+
     return array;
 }
 
@@ -713,17 +717,17 @@
     return slice(0).concat(anArray);
 }
 
-/*  
+/*
 - (CPArray)filteredArrayUsingPredicate:(CPPredicate)aPredicate
 {
-    var i= 0, 
+    var i= 0,
         count = [self count],
         array = [CPArray array];
-    
-    for(; i= [self count] + indexesCount)
-        [CPException raise:CPRangeException reason:"the last index (" + lastIndex + ") must be less than the sum of the original count (" + [self count] + ") and the insertion count (" + indexesCount + ")."];    
-    
+
+    if (lastIndex >= [self count] + indexesCount)
+        [CPException raise:CPRangeException reason:"the last index (" + lastIndex + ") must be less than the sum of the original count (" + [self count] + ") and the insertion count (" + indexesCount + ")."];
+
     var index = 0,
         currentIndex = [indexes firstIndex];
- 
+
     for (; index < objectsCount; ++index, currentIndex = [indexes indexGreaterThanIndex:currentIndex])
         [self insertObject:objects[index] atIndex:currentIndex];
 }
@@ -990,14 +994,14 @@
             result = CPOrderedSame;
 
         while (i < count)
-            if((result = [descriptors[i++] compareObject:lhs withObject:rhs]) != CPOrderedSame)
+            if ((result = [descriptors[i++] compareObject:lhs withObject:rhs]) != CPOrderedSame)
                 return result;
 
         return result;
     } context:nil];
 
     if (index < 0)
-        index = -index-1;
+        index = -index - 1;
 
     [self insertObject:anObject atIndex:index];
     return index;
@@ -1021,10 +1025,10 @@
 */
 - (void)replaceObjectsAtIndexes:(CPIndexSet)anIndexSet withObjects:(CPArray)objects
 {
-    var i = 0, 
+    var i = 0,
         index = [anIndexSet firstIndex];
-   
-    while(index != CPNotFound)
+
+    while (index != CPNotFound)
     {
         [self replaceObjectAtIndex:index withObject:objects[i++]];
         index = [anIndexSet indexGreaterThanIndex:index];
@@ -1065,8 +1069,9 @@
 */
 - (void)setArray:(CPArray)anArray
 {
-    if(self == anArray) return;
-    
+    if (self == anArray)
+        return;
+
     splice.apply(self, [0, length].concat(anArray));
 }
 
@@ -1104,7 +1109,7 @@
 - (void)removeObject:(id)anObject inRange:(CPRange)aRange
 {
     var index;
-    
+
     while ((index = [self indexOfObject:anObject inRange:aRange]) != CPNotFound)
     {
         [self removeObjectAtIndex:index];
@@ -1128,7 +1133,7 @@
 - (void)removeObjectsAtIndexes:(CPIndexSet)anIndexSet
 {
     var index = [anIndexSet lastIndex];
-   
+
     while (index != CPNotFound)
     {
         [self removeObjectAtIndex:index];
@@ -1157,7 +1162,7 @@
 {
     var index,
         count = [self count];
-    
+
     while ((index = [self indexOfObjectIdenticalTo:anObject inRange:aRange]) !== CPNotFound)
     {
         [self removeObjectAtIndex:index];
@@ -1173,7 +1178,7 @@
 {
     var index = 0,
         count = [anArray count];
-        
+
     for (; index < count; ++index)
         [self removeObject:anArray[index]];
 }
@@ -1207,11 +1212,11 @@
         var i = 0,
             count = [descriptors count],
             result = CPOrderedSame;
-        
-        while(i < count)
-            if((result = [descriptors[i++] compareObject:lhs withObject:rhs]) != CPOrderedSame)
+
+        while (i < count)
+            if ((result = [descriptors[i++] compareObject:lhs withObject:rhs]) != CPOrderedSame)
                 return result;
-        
+
         return result;
     });
 }