Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -169,10 +169,22 @@ * * \return The last object of the array or nil */ - (id)lastObject; +/** + * Returns the objects from the specified index to the specified index as an + * OFArray. + * + * \param start The index where the subarray starts + * \param end The index where the subarray ends. + * This points BEHIND the last object! + * \return The subarray as a new autoreleased OFArray + */ +- (OFArray*)objectsFromIndex: (size_t)start + toIndex: (size_t)end; + /** * Creates a string by joining all objects of the array. * * \param separator The string with which the objects should be joined * \return A string containing all objects joined by the separator Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -254,10 +254,22 @@ { id *last = [array lastItem]; return (last != NULL ? *last : nil); } + +- (OFArray*)objectsFromIndex: (size_t)start + toIndex: (size_t)end +{ + size_t count = [array count]; + + if (end > count || start > end) + @throw [OFOutOfRangeException newWithClass: isa]; + + return [OFArray arrayWithCArray: (id*)[array cArray] + start + length: end - start]; +} - (OFString*)componentsJoinedByString: (OFString*)separator { OFString *str; OFString **objs = [array cArray]; Index: tests/OFArrayTests.m ================================================================== --- tests/OFArrayTests.m +++ tests/OFArrayTests.m @@ -74,10 +74,15 @@ TEST(@"-[indexOfObject:]", [a[0] indexOfObject: c_ary[1]] == 1) TEST(@"-[indexOfObjectIdenticalTo:]", [a[1] indexOfObjectIdenticalTo: c_ary[1]] == 1) + TEST(@"-[objectsFromIndex:toIndex", + [[a[0] objectsFromIndex: 1 + toIndex: 3] isEqual: + ([OFArray arrayWithObjects: c_ary[1], c_ary[2], nil])]) + TEST(@"-[replaceObject:withObject:]", R([m[0] replaceObject: c_ary[1] withObject: c_ary[0]]) && [[m[0] objectAtIndex: 0] isEqual: c_ary[0]] && [[m[0] objectAtIndex: 1] isEqual: c_ary[0]] &&