mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-16 03:30:42 +00:00
Cleanup, fix accidental global in the average operator.
This commit is contained in:
1 parent
92d44b12bd
commit
9e92947b2c
3 files changed
+66
-52
No files matched your search
+17
-15
@@ -180,8 +180,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 +212,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 +258,9 @@
|
||||
|
||||
- (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);
|
||||
@@ -296,11 +297,12 @@
|
||||
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,
|
||||
foundDash = NO;
|
||||
/*
|
||||
var decimalSeparatorString;
|
||||
if (_locale != nil)
|
||||
@@ -339,12 +341,12 @@
|
||||
|
||||
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;
|
||||
var pos,
|
||||
foundDash = NO;
|
||||
for (pos = current; pos < current + str.length; pos++)
|
||||
{
|
||||
var charCode = str.charCodeAt(pos);
|
||||
@@ -384,7 +386,7 @@
|
||||
/* = Debug = */
|
||||
/* ========= */
|
||||
|
||||
- (void) description
|
||||
- (void)description
|
||||
{
|
||||
return [super description] + " {" + CPStringFromClass([self class]) + ", state = '" + ([self string].substr(0, _scanLocation) + "{{ SCAN LOCATION ->}}" + [self string].substr(_scanLocation)) + "'; }";
|
||||
}
|
||||
|
||||
+48
-36
@@ -61,22 +61,22 @@
|
||||
|
||||
SEL _enumeratorSEL;
|
||||
Function _enumerator;
|
||||
|
||||
|
||||
SEL _memberSEL;
|
||||
Function _member;
|
||||
|
||||
|
||||
SEL _addSEL;
|
||||
Function _add;
|
||||
|
||||
|
||||
SEL _addManySEL;
|
||||
Function _addMany;
|
||||
|
||||
|
||||
SEL _removeSEL;
|
||||
Function _remove;
|
||||
|
||||
|
||||
SEL _removeManySEL;
|
||||
Function _removeMany;
|
||||
|
||||
|
||||
SEL _intersectSEL;
|
||||
Function _intersect;
|
||||
}
|
||||
@@ -192,7 +192,7 @@
|
||||
{
|
||||
if (_add)
|
||||
_add(_proxyObject, _addSEL, anObject);
|
||||
else if(_addMany)
|
||||
else if (_addMany)
|
||||
{
|
||||
var objectSet = [CPSet setWithObject: anObject];
|
||||
_addMany(_proxyObject, _addManySEL, objectSet);
|
||||
@@ -207,15 +207,16 @@
|
||||
|
||||
- (void)addObjectsFromArray:(CPArray)objects
|
||||
{
|
||||
if(_addMany)
|
||||
if (_addMany)
|
||||
{
|
||||
var objectSet = [CPSet setWithArray: objects];
|
||||
_addMany(_proxyObject, _addManySEL, objectSet);
|
||||
}
|
||||
else if(_add)
|
||||
else if (_add)
|
||||
{
|
||||
var object, objectEnumerator = [objects objectEnumerator];
|
||||
while(object = [objectEnumerator nextObject])
|
||||
var object,
|
||||
objectEnumerator = [objects objectEnumerator];
|
||||
while (object = [objectEnumerator nextObject])
|
||||
_add(_proxyObject, _addSEL, object);
|
||||
}
|
||||
else
|
||||
@@ -230,10 +231,11 @@
|
||||
{
|
||||
if (_addMany)
|
||||
_addMany(_proxyObject, _addManySEL, aSet);
|
||||
else if(_add)
|
||||
else if (_add)
|
||||
{
|
||||
var object, objectEnumerator = [aSet objectEnumerator];
|
||||
while(object = [objectEnumerator nextObject])
|
||||
var object,
|
||||
objectEnumerator = [aSet objectEnumerator];
|
||||
while (object = [objectEnumerator nextObject])
|
||||
_add(_proxyObject, _addSEL, object);
|
||||
}
|
||||
else
|
||||
@@ -248,7 +250,7 @@
|
||||
{
|
||||
if (_remove)
|
||||
_remove(_proxyObject, _removeSEL, anObject);
|
||||
else if(_removeMany)
|
||||
else if (_removeMany)
|
||||
{
|
||||
var objectSet = [CPSet setWithObject: anObject];
|
||||
_removeMany(_proxyObject, _removeManySEL, objectSet);
|
||||
@@ -263,12 +265,13 @@
|
||||
|
||||
- (void)minusSet:(CPSet)aSet
|
||||
{
|
||||
if(_removeMany)
|
||||
if (_removeMany)
|
||||
_removeMany(_proxyObject, _removeManySEL, aSet);
|
||||
else if(_remove)
|
||||
else if (_remove)
|
||||
{
|
||||
var object, objectEnumerator = [aSet objectEnumerator];
|
||||
while(object = [objectEnumerator nextObject])
|
||||
var object,
|
||||
objectEnumerator = [aSet objectEnumerator];
|
||||
while (object = [objectEnumerator nextObject])
|
||||
_remove(_proxyObject, _removeSEL, object);
|
||||
}
|
||||
else
|
||||
@@ -281,15 +284,16 @@
|
||||
|
||||
- (void)removeObjectsInArray:(CPArray)objects
|
||||
{
|
||||
if(_removeMany)
|
||||
if (_removeMany)
|
||||
{
|
||||
var objectSet = [CPSet setWithArray:objects];
|
||||
_removeMany(_proxyObject, _removeManySEL, objectSet);
|
||||
}
|
||||
else if(_remove)
|
||||
else if (_remove)
|
||||
{
|
||||
var object, objectEnumerator = [objects objectEnumerator];
|
||||
while(object = [objectEnumerator nextObject])
|
||||
var object,
|
||||
objectEnumerator = [objects objectEnumerator];
|
||||
while (object = [objectEnumerator nextObject])
|
||||
_remove(_proxyObject, _removeSEL, object);
|
||||
}
|
||||
else
|
||||
@@ -302,15 +306,16 @@
|
||||
|
||||
- (void)removeAllObjects
|
||||
{
|
||||
if(_removeMany)
|
||||
if (_removeMany)
|
||||
{
|
||||
var allObjectsSet = [[self _representedObject] copy];
|
||||
_removeMany(_proxyObject, _removeManySEL, allObjectsSet);
|
||||
}
|
||||
else if(_remove)
|
||||
else if (_remove)
|
||||
{
|
||||
var object, objectEnumerator = [[[self _representedObject] copy] objectEnumerator];
|
||||
while(object = [objectEnumerator nextObject])
|
||||
var object,
|
||||
objectEnumerator = [[[self _representedObject] copy] objectEnumerator];
|
||||
while (object = [objectEnumerator nextObject])
|
||||
_remove(_proxyObject, _removeSEL, object);
|
||||
}
|
||||
else
|
||||
@@ -323,7 +328,7 @@
|
||||
|
||||
- (void)intersectSet:(CPSet)aSet
|
||||
{
|
||||
if(_intersect)
|
||||
if (_intersect)
|
||||
_intersect(_proxyObject, _intersectSEL, aSet);
|
||||
else
|
||||
{
|
||||
@@ -395,12 +400,14 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
var valuesForKeySet = [CPSet set];
|
||||
var containedObject, containedObjectValue, containedObjectEnumerator = [self objectEnumerator];
|
||||
while(containedObject = [containedObjectEnumerator nextObject])
|
||||
var valuesForKeySet = [CPSet set],
|
||||
containedObject,
|
||||
containedObjectValue,
|
||||
containedObjectEnumerator = [self objectEnumerator];
|
||||
while (containedObject = [containedObjectEnumerator nextObject])
|
||||
{
|
||||
containedObjectValue = [containedObject valueForKeyPath:aKeyPath];
|
||||
if(containedObjectValue)
|
||||
if (containedObjectValue)
|
||||
[valuesForKeySet addObject:containedObjectValue];
|
||||
}
|
||||
return valuesForKeySet;
|
||||
@@ -409,7 +416,8 @@
|
||||
|
||||
- (void)setValue:(id)aValue forKey:(CPString)aKey
|
||||
{
|
||||
var containedObject, containedObjectEnumerator = [self objectEnumerator];
|
||||
var containedObject,
|
||||
containedObjectEnumerator = [self objectEnumerator];
|
||||
while (containedObject = [containedObjectEnumerator nextObject])
|
||||
[containedObject setValue:aValue forKey:aKey];
|
||||
}
|
||||
@@ -420,14 +428,18 @@ var kvoOperators = [];
|
||||
|
||||
// FIXME: this is not DRY because the implementation in CPArray+KVO is merely the same!
|
||||
// HACK: prevent these from becoming globals. workaround for obj-j "function foo(){}" behavior
|
||||
var avgOperator, maxOperator, minOperator, countOperator, sumOperator;
|
||||
var avgOperator,
|
||||
maxOperator,
|
||||
minOperator,
|
||||
countOperator,
|
||||
sumOperator;
|
||||
|
||||
kvoOperators["avg"] = function avgOperator(self, _cmd, param)
|
||||
{
|
||||
//CPSet returns a CPSet - to obtain an array call allObjects
|
||||
var objects = [[self valueForKeyPath:param] allObjects],
|
||||
length = [objects count],
|
||||
index = length;
|
||||
index = length,
|
||||
average = 0.0;
|
||||
|
||||
if (!length)
|
||||
@@ -502,7 +514,7 @@ kvoOperators["sum"] = function sumOperator(self, _cmd, param)
|
||||
[super addObserver:observer forKeyPath:aKeyPath options:options context:context];
|
||||
}
|
||||
|
||||
-(void)removeObserver:(id)observer forKeyPath:(CPString)aKeyPath
|
||||
- (void)removeObserver:(id)observer forKeyPath:(CPString)aKeyPath
|
||||
{
|
||||
if ([isa instanceMethodForSelector:_cmd] === [CPSet instanceMethodForSelector:_cmd])
|
||||
[CPException raise:CPInvalidArgumentException reason:"Unsupported method on CPSet"];
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
}
|
||||
|
||||
/*
|
||||
Removes from the receiver each object that isnÕt a member of another given set.
|
||||
Removes from the receiver each object that isn't a member of another given set.
|
||||
@param set The set with which to perform the intersection.
|
||||
*/
|
||||
- (void)intersectSet:(CPSet)aSet
|
||||
|
||||
Reference in new issue
Block a user