mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-20 05:29:23 +00:00
CPIndexSet enumerateIndexesInRange:options:usingBlock:.
This commit is contained in:
1 parent
a26bca5dbe
commit
44236795b5
2 files changed
+49
-4
No files matched your search
+13
-3
@@ -492,6 +492,13 @@
|
||||
{
|
||||
if (!_count)
|
||||
return;
|
||||
[self enumerateIndexesInRange:CPMakeRange(0, CPMaxRange(_ranges[_ranges.length - 1])) options:options usingBlock:aFunction];
|
||||
}
|
||||
|
||||
- (void)enumerateIndexesInRange:(CPRange)enumerationRange options:(CPEnumerationOptions)options usingBlock:(Function /*(int idx, @ref BOOL stop)*/)aFunction
|
||||
{
|
||||
if (!_count || CPEmptyRange(enumerationRange))
|
||||
return;
|
||||
|
||||
var shouldStop = NO,
|
||||
index,
|
||||
@@ -534,9 +541,12 @@
|
||||
|
||||
for (; rangeIndex !== rangeStop; rangeIndex += rangeIncrement)
|
||||
{
|
||||
aFunction(rangeIndex, AT_REF(shouldStop));
|
||||
if (shouldStop)
|
||||
return;
|
||||
if (CPLocationInRange(rangeIndex, enumerationRange))
|
||||
{
|
||||
aFunction(rangeIndex, AT_REF(shouldStop));
|
||||
if (shouldStop)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,9 +483,44 @@ function descriptionWithoutEntity(aString)
|
||||
visitedIndexes = [];
|
||||
[set2 enumerateIndexesWithOptions:CPEnumerationReverse usingBlock:aBlock];
|
||||
[self assert:[4, 3, 0] equals:visitedIndexes message:"reverse enumerate " + [set2 description]];
|
||||
|
||||
}
|
||||
|
||||
- (void)testEnumerateIndexesInRange_options_usingBlock_
|
||||
{
|
||||
var set0 = [CPIndexSet indexSet],
|
||||
set1 = [CPMutableIndexSet indexSet],
|
||||
set2 = [CPMutableIndexSet indexSet];
|
||||
|
||||
[set1 addIndexesInRange:CPMakeRange(3, 2)];
|
||||
|
||||
[set2 addIndexesInRange:CPMakeRange(3, 2)];
|
||||
[set2 addIndexesInRange:CPMakeRange(0, 1)];
|
||||
|
||||
var visitedIndexes = [],
|
||||
aBlock;
|
||||
|
||||
aBlock = function(idx)
|
||||
{
|
||||
visitedIndexes.push(idx);
|
||||
};
|
||||
|
||||
visitedIndexes = [];
|
||||
[set0 enumerateIndexesInRange:CPMakeRange(0, 4) options:CPEnumerationReverse usingBlock:aBlock];
|
||||
[self assert:[] equals:visitedIndexes message:"reverse enumerate in range empty set"];
|
||||
|
||||
visitedIndexes = [];
|
||||
[set1 enumerateIndexesInRange:CPMakeRange(0, 5) options:CPEnumerationReverse usingBlock:aBlock];
|
||||
[self assert:[4, 3] equals:visitedIndexes message:"reverse enumerate in range " + [set1 description]];
|
||||
|
||||
visitedIndexes = [];
|
||||
[set1 enumerateIndexesInRange:CPMakeRange(0, 4) options:CPEnumerationReverse usingBlock:aBlock];
|
||||
[self assert:[3] equals:visitedIndexes message:"reverse enumerate in range " + [set1 description]];
|
||||
|
||||
visitedIndexes = [];
|
||||
[set2 addIndexesInRange:CPMakeRange(7, 2)];
|
||||
[set2 enumerateIndexesInRange:CPMakeRange(2, 4) options:CPEnumerationReverse usingBlock:aBlock];
|
||||
[self assert:[4, 3] equals:visitedIndexes message:"reverse enumerate " + [set2 description]];
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user