Index: src/OFAdjacentArray.m ================================================================== --- src/OFAdjacentArray.m +++ src/OFAdjacentArray.m @@ -340,11 +340,11 @@ return (int)count; } #ifdef OF_HAVE_BLOCKS -- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block +- (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { id const *objects = _array.items; size_t count = _array.count; bool stop = false; Index: src/OFAdjacentSubarray.m ================================================================== --- src/OFAdjacentSubarray.m +++ src/OFAdjacentSubarray.m @@ -51,15 +51,15 @@ return true; } #ifdef OF_HAVE_BLOCKS -- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block +- (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { id const *objects = self.objects; bool stop = false; for (size_t i = 0; i < _range.length && !stop; i++) block(objects[i], i, &stop); } #endif @end Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -33,14 +33,23 @@ /** @file */ @class OFString; -enum { - OF_ARRAY_SKIP_EMPTY = 1, - OF_ARRAY_SORT_DESCENDING = 2 -}; +/** + * @brief Options for joining the objects of an array. + * + * This is a bit mask. + */ +typedef enum OFArrayJoinOptions { + /** Skip empty components */ + OFArraySkipEmptyComponents = 1 +} OFArrayJoinOptions; + +typedef enum OFArraySortOptions { + OFArraySortDescending = 1 +} OFArraySortOptions; #ifdef OF_HAVE_BLOCKS /** * @brief A block for enumerating an OFArray. * @@ -47,39 +56,38 @@ * @param object The current object * @param index The index of the current object * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ -typedef void (^of_array_enumeration_block_t)(id object, size_t index, - bool *stop); +typedef void (^OFArrayEnumerationBlock)(id object, size_t index, bool *stop); /** * @brief A block for filtering an OFArray. * * @param object The object to inspect * @param index The index of the object to inspect * @return Whether the object should be in the filtered array */ -typedef bool (^of_array_filter_block_t)(id object, size_t index); +typedef bool (^OFArrayFilterBlock)(id object, size_t index); /** * @brief A block for mapping objects to objects in an OFArray. * * @param object The object to map * @param index The index of the object to map * @return The object to map to */ -typedef id _Nonnull (^of_array_map_block_t)(id object, size_t index); +typedef id _Nonnull (^OFArrayMapBlock)(id object, size_t index); /** * @brief A block for folding an OFArray. * * @param left The object to which the object has been folded so far * @param right The object that should be added to the left object * @return The left and right side folded into one object */ -typedef id _Nullable (^of_array_fold_block_t)(id _Nullable left, id right); +typedef id _Nullable (^OFArrayFoldBlock)(id _Nullable left, id right); #endif /** * @class OFArray OFArray.h ObjFW/OFArray.h * @@ -329,19 +337,15 @@ /** * @brief Creates a string by joining all objects of the array. * * @param separator The string with which the objects should be joined - * @param options Options according to which the objects should be joined.@n - * Possible values are: - * Value | Description - * ----------------------|---------------------- - * `OF_ARRAY_SKIP_EMPTY` | Skip empty components + * @param options Options according to which the objects should be joined * @return A string containing all objects joined by the separator */ - (OFString *)componentsJoinedByString: (OFString *)separator - options: (int)options; + options: (OFArrayJoinOptions)options; /** * @brief Creates a string by calling the selector on all objects of the array * and joining the strings returned by calling the selector. * @@ -356,20 +360,16 @@ * @brief Creates a string by calling the selector on all objects of the array * and joining the strings returned by calling the selector. * * @param separator The string with which the objects should be joined * @param selector The selector to perform on the objects - * @param options Options according to which the objects should be joined.@n - * Possible values are: - * Value | Description - * ----------------------|---------------------- - * `OF_ARRAY_SKIP_EMPTY` | Skip empty components + * @param options Options according to which the objects should be joined * @return A string containing all objects joined by the separator */ - (OFString *)componentsJoinedByString: (OFString *)separator usingSelector: (SEL)selector - options: (int)options; + options: (OFArrayJoinOptions)options; /** * @brief Performs the specified selector on all objects in the array. * * @param selector The selector to perform on all objects in the array @@ -391,36 +391,29 @@ * @brief Returns a copy of the array sorted using the specified selector and * options. * * @param selector The selector to use to sort the array. It's signature * should be the same as that of -[compare:]. - * @param options The options to use when sorting the array.@n - * Possible values are: - * Value | Description - * ---------------------------|------------------------- - * `OF_ARRAY_SORT_DESCENDING` | Sort in descending order + * @param options The options to use when sorting the array * @return A sorted copy of the array */ -- (OFArray OF_GENERIC(ObjectType) *)sortedArrayUsingSelector: (SEL)selector - options: (int)options; +- (OFArray OF_GENERIC(ObjectType) *) + sortedArrayUsingSelector: (SEL)selector + options: (OFArraySortOptions)options; #ifdef OF_HAVE_BLOCKS /** * @brief Returns a copy of the array sorted using the specified selector and * options. * * @param comparator The comparator to use to sort the array - * @param options The options to use when sorting the array.@n - * Possible values are: - * Value | Description - * ---------------------------|------------------------- - * `OF_ARRAY_SORT_DESCENDING` | Sort in descending order + * @param options The options to use when sorting the array * @return A sorted copy of the array */ - (OFArray OF_GENERIC(ObjectType) *) sortedArrayUsingComparator: (OFComparator)comparator - options: (int)options; + options: (OFArraySortOptions)options; #endif /** * @brief Creates a new array with the specified object added. * @@ -450,19 +443,19 @@ /** * @brief Executes a block for each object. * * @param block The block to execute for each object */ -- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block; +- (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block; /** * @brief Creates a new array, mapping each object using the specified block. * * @param block A block which maps an object for each object * @return A new, autoreleased OFArray */ -- (OFArray *)mappedArrayUsingBlock: (of_array_map_block_t)block; +- (OFArray *)mappedArrayUsingBlock: (OFArrayMapBlock)block; /** * @brief Creates a new array, only containing the objects for which the block * returns true. * @@ -469,11 +462,11 @@ * @param block A block which determines if the object should be in the new * array * @return A new, autoreleased OFArray */ - (OFArray OF_GENERIC(ObjectType) *)filteredArrayUsingBlock: - (of_array_filter_block_t)block; + (OFArrayFilterBlock)block; /** * @brief Folds the array to a single object using the specified block. * * If the array is empty, it will return `nil`. @@ -487,11 +480,11 @@ * * @param block A block which folds two objects into one, which is called for * all objects except the first * @return The array folded to a single object */ -- (nullable id)foldUsingBlock: (of_array_fold_block_t)block; +- (nullable id)foldUsingBlock: (OFArrayFoldBlock)block; #endif #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -393,11 +393,11 @@ usingSelector: @selector(description) options: 0]; } - (OFString *)componentsJoinedByString: (OFString *)separator - options: (int)options + options: (OFArrayJoinOptions)options { return [self componentsJoinedByString: separator usingSelector: @selector(description) options: options]; } @@ -410,11 +410,11 @@ options: 0]; } - (OFString *)componentsJoinedByString: (OFString *)separator usingSelector: (SEL)selector - options: (int)options + options: (OFArrayJoinOptions)options { OFMutableString *ret; if (separator == nil) @throw [OFInvalidArgumentException exception]; @@ -432,11 +432,11 @@ return component; } ret = [OFMutableString string]; - if (options & OF_ARRAY_SKIP_EMPTY) { + if (options & OFArraySkipEmptyComponents) { for (id object in self) { void *pool = objc_autoreleasePoolPush(); OFString *component = [object performSelector: selector]; @@ -712,21 +712,21 @@ [new makeImmutable]; return new; } - (OFArray *)sortedArrayUsingSelector: (SEL)selector - options: (int)options + options: (OFArraySortOptions)options { OFMutableArray *new = [[self mutableCopy] autorelease]; [new sortUsingSelector: selector options: options]; [new makeImmutable]; return new; } #ifdef OF_HAVE_BLOCKS - (OFArray *)sortedArrayUsingComparator: (OFComparator)comparator - options: (int)options + options: (OFArraySortOptions)options { OFMutableArray *new = [[self mutableCopy] autorelease]; [new sortUsingComparator: comparator options: options]; [new makeImmutable]; return new; @@ -770,11 +770,11 @@ return [[[OFArrayEnumerator alloc] initWithArray: self mutationsPtr: NULL] autorelease]; } #ifdef OF_HAVE_BLOCKS -- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block +- (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { size_t i = 0; bool stop = false; for (id object in self) { @@ -816,11 +816,11 @@ [ret makeImmutable]; return ret; } #ifdef OF_HAVE_BLOCKS -- (OFArray *)mappedArrayUsingBlock: (of_array_map_block_t)block +- (OFArray *)mappedArrayUsingBlock: (OFArrayMapBlock)block { OFArray *ret; size_t count = self.count; id *tmp = of_alloc(count, sizeof(id)); @@ -836,11 +836,11 @@ } return ret; } -- (OFArray *)filteredArrayUsingBlock: (of_array_filter_block_t)block +- (OFArray *)filteredArrayUsingBlock: (OFArrayFilterBlock)block { OFArray *ret; size_t count = self.count; id *tmp = of_alloc(count, sizeof(id)); @@ -859,11 +859,11 @@ } return ret; } -- (id)foldUsingBlock: (of_array_fold_block_t)block +- (id)foldUsingBlock: (OFArrayFoldBlock)block { size_t count = self.count; __block id current; if (count == 0) Index: src/OFData.h ================================================================== --- src/OFData.h +++ src/OFData.h @@ -28,10 +28,11 @@ * @brief Options for searching in data. * * This is a bit mask. */ typedef enum OFDataSearchOptions { + /** Search backwards in the data */ OFDataSearchBackwards = 1 } OFDataSearchOptions; /** * @class OFData OFData.h ObjFW/OFData.h Index: src/OFMutableAdjacentArray.m ================================================================== --- src/OFMutableAdjacentArray.m +++ src/OFMutableAdjacentArray.m @@ -328,11 +328,11 @@ initWithArray: self mutationsPtr: &_mutations] autorelease]; } #ifdef OF_HAVE_BLOCKS -- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block +- (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { id const *objects = _array.items; size_t count = _array.count; bool stop = false; unsigned long mutations = _mutations; @@ -344,11 +344,11 @@ block(objects[i], i, &stop); } } -- (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block +- (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block { id *objects = _array.mutableItems; size_t count = _array.count; unsigned long mutations = _mutations; Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -25,11 +25,11 @@ * * @param object The object to replace * @param index The index of the object to replace * @return The object to replace the object with */ -typedef id _Nonnull (^of_array_replace_block_t)(id object, size_t index); +typedef id _Nonnull (^OFArrayReplaceBlock)(id object, size_t index); #endif /** * @class OFMutableArray OFArray.h ObjFW/OFArray.h * @@ -175,11 +175,11 @@ /** * @brief Replaces each object with the object returned by the block. * * @param block The block which returns a new object for each object */ -- (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block; +- (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block; #endif /** * @brief Exchange the objects at the specified indices. * @@ -196,30 +196,23 @@ /** * @brief Sorts the array using the specified selector and options. * * @param selector The selector to use to sort the array. It's signature * should be the same as that of -[compare:]. - * @param options The options to use when sorting the array.@n - * Possible values are: - * Value | Description - * ---------------------------|------------------------- - * `OF_ARRAY_SORT_DESCENDING` | Sort in descending order + * @param options The options to use when sorting the array */ -- (void)sortUsingSelector: (SEL)selector options: (int)options; +- (void)sortUsingSelector: (SEL)selector options: (OFArraySortOptions)options; #ifdef OF_HAVE_BLOCKS /** * @brief Sorts the array using the specified comparator and options. * * @param comparator The comparator to use to sort the array - * @param options The options to use when sorting the array.@n - * Possible values are: - * Value | Description - * ---------------------------|------------------------- - * `OF_ARRAY_SORT_DESCENDING` | Sort in descending order + * @param options The options to use when sorting the array */ -- (void)sortUsingComparator: (OFComparator)comparator options: (int)options; +- (void)sortUsingComparator: (OFComparator)comparator + options: (OFArraySortOptions)options; #endif /** * @brief Reverts the order of the objects in the array. */ Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -44,15 +44,15 @@ return comparator(left, selector, right); } static void quicksort(OFMutableArray *array, size_t left, size_t right, SEL selector, - int options) + OFArraySortOptions options) { OFComparisonResult ascending, descending; - if (options & OF_ARRAY_SORT_DESCENDING) { + if (options & OFArraySortDescending) { ascending = OFOrderedDescending; descending = OFOrderedAscending; } else { ascending = OFOrderedAscending; descending = OFOrderedDescending; @@ -90,15 +90,15 @@ } #ifdef OF_HAVE_BLOCKS static void quicksortWithBlock(OFMutableArray *array, size_t left, size_t right, - OFComparator comparator, int options) + OFComparator comparator, OFArraySortOptions options) { OFComparisonResult ascending, descending; - if (options & OF_ARRAY_SORT_DESCENDING) { + if (options & OFArraySortDescending) { ascending = OFOrderedDescending; descending = OFOrderedAscending; } else { ascending = OFOrderedAscending; descending = OFOrderedDescending; @@ -382,11 +382,11 @@ { [self removeObjectsInRange: OFMakeRange(0, self.count)]; } #ifdef OF_HAVE_BLOCKS -- (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block +- (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { id new = block(object, idx); @@ -414,11 +414,11 @@ { [self sortUsingSelector: @selector(compare:) options: 0]; } - (void)sortUsingSelector: (SEL)selector - options: (int)options + options: (OFArraySortOptions)options { size_t count = self.count; if (count == 0 || count == 1) return; @@ -425,11 +425,12 @@ quicksort(self, 0, count - 1, selector, options); } #ifdef OF_HAVE_BLOCKS -- (void)sortUsingComparator: (OFComparator)comparator options: (int)options +- (void)sortUsingComparator: (OFComparator)comparator + options: (OFArraySortOptions)options { size_t count = self.count; if (count == 0 || count == 1) return; Index: tests/OFArrayTests.m ================================================================== --- tests/OFArrayTests.m +++ tests/OFArrayTests.m @@ -237,11 +237,11 @@ [m[1] addObject: @"z"]; TEST(@"-[sortedArray]", [[m[1] sortedArray] isEqual: [arrayClass arrayWithObjects: @"0", @"Bar", @"Baz", @"Foo", @"z", nil]] && [[m[1] sortedArrayUsingSelector: @selector(compare:) - options: OF_ARRAY_SORT_DESCENDING] + options: OFArraySortDescending] isEqual: [arrayClass arrayWithObjects: @"z", @"Foo", @"Baz", @"Bar", @"0", nil]]) EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]", OFOutOfRangeException, [a[0] objectAtIndex: a[0].count]) @@ -257,12 +257,13 @@ (a[1] = [arrayClass arrayWithObject: @"foo"]) && [[a[1] componentsJoinedByString: @" "] isEqual: @"foo"]) TEST(@"-[componentsJoinedByString:options]", (a[1] = [arrayClass arrayWithObjects: @"", @"foo", @"", @"", @"bar", - @"", nil]) && [[a[1] componentsJoinedByString: @" " - options: OF_ARRAY_SKIP_EMPTY] + @"", nil]) && + [[a[1] componentsJoinedByString: @" " + options: OFArraySkipEmptyComponents] isEqual: @"foo bar"]) m[0] = [[a[0] mutableCopy] autorelease]; ok = true; i = 0; Index: tests/OFDataTests.m ================================================================== --- tests/OFDataTests.m +++ tests/OFDataTests.m @@ -96,11 +96,11 @@ range.location == 0 && range.length == 1) range = [immutable rangeOfData: [OFData dataWithItems: "aa" count: 1 itemSize: 2] - options: OF_DATA_SEARCH_BACKWARDS + options: OFDataSearchBackwards range: OFMakeRange(0, 7)]; TEST(@"-[rangeOfData:options:range:] #2", range.location == 5 && range.length == 1) range = [immutable rangeOfData: [OFData dataWithItems: "ac" @@ -128,11 +128,11 @@ range.location == 5 && range.length == 1) range = [immutable rangeOfData: [OFData dataWithItems: "aa" count: 1 itemSize: 2] - options: OF_DATA_SEARCH_BACKWARDS + options: OFDataSearchBackwards range: OFMakeRange(0, 5)]; TEST(@"-[rangeOfData:options:range:] #6", range.location == 0 && range.length == 1) EXPECT_EXCEPTION(