Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:280north/cappuccino
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco Ryan Tolmasky I committed Oct 26, 2008
2 parents 5144a5a + b5ad113 commit 12b58cd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Foundation/CPArray.j
Expand Up @@ -696,10 +696,10 @@
*/
- (CPArray)subarrayWithRange:(CPRange)aRange
{
if (aRange.location < 0 || (aRange.location + CPMaxRange(aRange)) > length)
if (aRange.location < 0 || CPMaxRange(aRange) > length)
[CPException raise:CPRangeException reason:"subarrayWithRange: aRange out of bounds"];

return slice(aRange.location, maxRange);
return slice(aRange.location, CPMaxRange(aRange));
}

// Sorting arrays
Expand Down
35 changes: 35 additions & 0 deletions Foundation/CPDictionary.j
Expand Up @@ -164,6 +164,14 @@
return self;
}

/*!
return a copy of the receiver (does not deep copy the objects contained in the dictionary).
*/
- (CPDictionary)copy
{
return [CPDictionary dictionaryWithDictionary:self];
}

/*!
Returns the number of entries in the dictionary
*/
Expand Down Expand Up @@ -210,6 +218,33 @@
return [[_CPDictionaryValueEnumerator alloc] initWithDictionary:self];
}

/*!
Compare the receiver to this dictionary, and return whether or not they are equal.
*/
- (BOOL)isEqualToDictionary:(CPDictionary)aDictionary
{
if (count != [aDictionary count])
return NO;

var index = count;
while (index--)
{
var currentKey = _keys[index],
lhsObject = _buckets[currentKey],
rhsObject = aDictionary._buckets[currentKey];

if (lhsObject === rhsObject)
continue;

if ([lhsObject respondsToSelector:@selector(isEqual:)] && [lhsObject isEqual:rhsObject])
continue;

return NO;
}

return YES;
}

/*
Instance.isEqualToDictionary(aDictionary)
{
Expand Down
12 changes: 12 additions & 0 deletions Foundation/CPRange.j
Expand Up @@ -129,6 +129,18 @@ function CPIntersectionRange(lhsRange, rhsRange)
return CPMakeRange(location, Math.min(CPMaxRange(lhsRange), CPMaxRange(rhsRange)) - location);
}

/*!
Checks if a range completely contains another range. In other words, if one range is the "super range" of another.
@param lhsRange the containing range
@param rhsRange the range we are testing to see if lhsRange contains it
@group CPRange
@return BOOL whether or not lhsRange completely contains rhsRange
*/
function CPRangeInRange(lhsRange, rhsRange)
{
return (lhsRange.location <= rhsRange.location && CPMaxRange(lhsRange) >= CPMaxRange(rhsRange));
}

/*!
Returns a string describing a range.
@param aRange the range to describe
Expand Down

0 comments on commit 12b58cd

Please sign in to comment.