Index: src/OFConstantString.m ================================================================== --- src/OFConstantString.m +++ src/OFConstantString.m @@ -267,18 +267,19 @@ { [self finishInitialization]; return [self rangeOfString: string]; } -- (OFRange)rangeOfString: (OFString *)string options: (int)options +- (OFRange)rangeOfString: (OFString *)string + options: (OFStringSearchOptions)options { [self finishInitialization]; return [self rangeOfString: string options: options]; } - (OFRange)rangeOfString: (OFString *)string - options: (int)options + options: (OFStringSearchOptions)options range: (OFRange)range { [self finishInitialization]; return [self rangeOfString: string options: options range: range]; } @@ -288,18 +289,18 @@ [self finishInitialization]; return [self indexOfCharacterFromSet: characterSet]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet - options: (int)options + options: (OFStringSearchOptions)options { [self finishInitialization]; return [self indexOfCharacterFromSet: characterSet options: options]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet - options: (int)options + options: (OFStringSearchOptions)options range: (OFRange)range { [self finishInitialization]; return [self indexOfCharacterFromSet: characterSet options: options @@ -428,11 +429,11 @@ [self finishInitialization]; return [self componentsSeparatedByString: delimiter]; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter - options: (int)options + options: (OFStringSeparationOptions)options { [self finishInitialization]; return [self componentsSeparatedByString: delimiter options: options]; } @@ -443,11 +444,11 @@ return [self componentsSeparatedByCharactersInSet: characterSet]; } - (OFArray *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet - options: (int)options + options: (OFStringSeparationOptions)options { [self finishInitialization]; return [self componentsSeparatedByCharactersInSet: characterSet options: options]; } Index: src/OFDNSResolverSettings.m ================================================================== --- src/OFDNSResolverSettings.m +++ src/OFDNSResolverSettings.m @@ -270,11 +270,11 @@ if (pos != OFNotFound) line = [line substringToIndex: pos]; components = [line componentsSeparatedByCharactersInSet: whitespaceCharacterSet - options: OF_STRING_SKIP_EMPTY]; + options: OFStringSkipEmptyComponents]; if (components.count < 2) continue; address = components.firstObject; @@ -371,11 +371,11 @@ if (pos != OFNotFound) line = [line substringToIndex: pos]; components = [line componentsSeparatedByCharactersInSet: whitespaceCharacterSet - options: OF_STRING_SKIP_EMPTY]; + options: OFStringSkipEmptyComponents]; if (components.count < 2) { objc_autoreleasePoolPop(pool2); continue; } Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -460,13 +460,12 @@ value = [old stringByAppendingFormat: @",%@", value]; [_headers setObject: value forKey: key]; if ([key isEqual: @"Host"]) { - pos = [value - rangeOfString: @":" - options: OF_STRING_SEARCH_BACKWARDS].location; + pos = [value rangeOfString: @":" + options: OFStringSearchBackwards].location; if (pos != OFNotFound) { [_host release]; _host = [[value substringToIndex: pos] retain]; Index: src/OFINIFileSettings.m ================================================================== --- src/OFINIFileSettings.m +++ src/OFINIFileSettings.m @@ -55,11 +55,11 @@ - (void)of_getCategory: (OFString **)category andKey: (OFString **)key forPath: (OFString *)path OF_DIRECT { size_t pos = [path rangeOfString: @"." - options: OF_STRING_SEARCH_BACKWARDS].location; + options: OFStringSearchBackwards].location; if (pos == OFNotFound) { *category = @""; *key = path; return; Index: src/OFLocale.m ================================================================== --- src/OFLocale.m +++ src/OFLocale.m @@ -106,11 +106,11 @@ /* Substitute variables and convert to RPN first */ tokens = [OFMutableArray array]; operators = [OFMutableArray array]; for (OFString *token in [condition componentsSeparatedByString: @" " - options: OF_STRING_SKIP_EMPTY]) { + options: OFStringSkipEmptyComponents]) { unsigned precedence; OFUnichar c; if ([token isEqual: @"("]) { [operators addObject: @"("]; Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -100,14 +100,29 @@ OFStringEncodingKOI8U, /** Try to automatically detect the encoding */ OFStringEncodingAutodetect = 0xFF } OFStringEncoding; -enum { - OF_STRING_SEARCH_BACKWARDS = 1, - OF_STRING_SKIP_EMPTY = 2 -}; +/** + * @brief Options for searching in strings. + * + * This is a bit mask. + */ +typedef enum OFStringSearchOptions { + /** Search backwards in the string */ + OFStringSearchBackwards = 1 +} OFStringSearchOptions; + +/** + * @brief Options for separating strings. + * + * This is a bit mask. + */ +typedef enum OFStringSeparationOptions { + /** Skip empty components */ + OFStringSkipEmptyComponents = 1 +} OFStringSeparationOptions; #ifdef OF_HAVE_BLOCKS /** * @brief A block for enumerating the lines of a string. * @@ -927,35 +942,28 @@ /** * @brief Returns the range of the string. * * @param string The string to search - * @param options Options modifying search behavior.@n - * Possible values are: - * Value | Description - * -----------------------------|------------------------------- - * `OF_STRING_SEARCH_BACKWARDS` | Search backwards in the string + * @param options Options modifying search behavior * @return The range of the first occurrence of the string or a range with * `OFNotFound` as start position if it was not found */ -- (OFRange)rangeOfString: (OFString *)string options: (int)options; +- (OFRange)rangeOfString: (OFString *)string + options: (OFStringSearchOptions)options; /** * @brief Returns the range of the string in the specified range. * * @param string The string to search - * @param options Options modifying search behaviour.@n - * Possible values are: - * Value | Description - * -----------------------------|------------------------------- - * `OF_STRING_SEARCH_BACKWARDS` | Search backwards in the string + * @param options Options modifying search behaviour * @param range The range in which to search * @return The range of the first occurrence of the string or a range with * `OFNotFound` as start position if it was not found */ - (OFRange)rangeOfString: (OFString *)string - options: (int)options + options: (OFStringSearchOptions)options range: (OFRange)range; /** * @brief Returns the index of the first character from the set. * @@ -967,36 +975,28 @@ /** * @brief Returns the index of the first character from the set. * * @param characterSet The set of characters to search for - * @param options Options modifying search behaviour.@n - * Possible values are: - * Value | Description - * -----------------------------|------------------------------- - * `OF_STRING_SEARCH_BACKWARDS` | Search backwards in the string + * @param options Options modifying search behaviour * @return The index of the first occurrence of a character from the set or * `OFNotFound` if it was not found */ - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet - options: (int)options; + options: (OFStringSearchOptions)options; /** * @brief Returns the index of the first character from the set. * * @param characterSet The set of characters to search for - * @param options Options modifying search behaviour.@n - * Possible values are: - * Value | Description - * -----------------------------|------------------------------- - * `OF_STRING_SEARCH_BACKWARDS` | Search backwards in the string + * @param options Options modifying search behaviour * @param range The range in which to search * @return The index of the first occurrence of a character from the set or * `OFNotFound` if it was not found */ - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet - options: (int)options + options: (OFStringSearchOptions)options range: (OFRange)range; /** * @brief Returns whether the string contains the specified string. * @@ -1159,20 +1159,16 @@ /** * @brief Separates the string into an array of strings, split by the specified * delimiter. * * @param delimiter The delimiter for separating - * @param options Options according to which the string should be separated.@n - * Possible values are: - * Value | Description - * -----------------------|---------------------- - * `OF_STRING_SKIP_EMPTY` | Skip empty components + * @param options Options according to which the string should be separated * @return An autoreleased OFArray with the separated string */ - (OFArray OF_GENERIC(OFString *) *) componentsSeparatedByString: (OFString *)delimiter - options: (int)options; + options: (OFStringSeparationOptions)options; /** * @brief Separates the string into an array of strings, split by characters in * the specified set. * @@ -1185,20 +1181,16 @@ /** * @brief Separates the string into an array of strings, split by characters in * the specified set. * * @param characterSet The character set for separating - * @param options Options according to which the string should be separated.@n - * Possible values are: - * Value | Description - * -----------------------|---------------------- - * `OF_STRING_SKIP_EMPTY` | Skip empty components + * @param options Options according to which the string should be separated * @return An autoreleased OFArray with the separated string */ - (OFArray OF_GENERIC(OFString *) *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet - options: (int)options; + options: (OFStringSeparationOptions)options; /** * @brief Returns the string in UTF-16 encoding with the specified byte order. * * The result is valid until the autorelease pool is released. If you want to Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1803,19 +1803,20 @@ return [self rangeOfString: string options: 0 range: OFMakeRange(0, self.length)]; } -- (OFRange)rangeOfString: (OFString *)string options: (int)options +- (OFRange)rangeOfString: (OFString *)string + options: (OFStringSearchOptions)options { return [self rangeOfString: string options: options range: OFMakeRange(0, self.length)]; } - (OFRange)rangeOfString: (OFString *)string - options: (int)options + options: (OFStringSearchOptions)options range: (OFRange)range { void *pool; const OFUnichar *searchCharacters; OFUnichar *characters; @@ -1836,11 +1837,11 @@ characters = of_alloc(range.length, sizeof(OFUnichar)); @try { [self getCharacters: characters inRange: range]; - if (options & OF_STRING_SEARCH_BACKWARDS) { + if (options & OFStringSearchBackwards) { for (size_t i = range.length - searchLength;; i--) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) == 0) { objc_autoreleasePoolPop(pool); return OFMakeRange(range.location + i, @@ -1877,19 +1878,19 @@ options: 0 range: OFMakeRange(0, self.length)]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet - options: (int)options + options: (OFStringSearchOptions)options { return [self indexOfCharacterFromSet: characterSet options: options range: OFMakeRange(0, self.length)]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet - options: (int)options + options: (OFStringSearchOptions)options range: (OFRange)range { bool (*characterIsMember)(id, SEL, OFUnichar) = (bool (*)(id, SEL, OFUnichar))[characterSet methodForSelector: @selector(characterIsMember:)]; @@ -1903,11 +1904,11 @@ characters = of_alloc(range.length, sizeof(OFUnichar)); @try { [self getCharacters: characters inRange: range]; - if (options & OF_STRING_SEARCH_BACKWARDS) { + if (options & OFStringSearchBackwards) { for (size_t i = range.length - 1;; i--) { if (characterIsMember(characterSet, @selector(characterIsMember:), characters[i])) return range.location + i; @@ -2162,16 +2163,16 @@ { return [self componentsSeparatedByString: delimiter options: 0]; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter - options: (int)options + options: (OFStringSeparationOptions)options { void *pool; OFMutableArray *array; const OFUnichar *characters, *delimiterCharacters; - bool skipEmpty = (options & OF_STRING_SKIP_EMPTY); + bool skipEmpty = (options & OFStringSkipEmptyComponents); size_t length = self.length; size_t delimiterLength = delimiter.length; size_t last; OFString *component; @@ -2228,15 +2229,15 @@ options: 0]; } - (OFArray *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet - options: (int)options + options: (OFStringSeparationOptions)options { OFMutableArray *array = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); - bool skipEmpty = (options & OF_STRING_SKIP_EMPTY); + bool skipEmpty = (options & OFStringSkipEmptyComponents); const OFUnichar *characters = self.characters; size_t length = self.length; bool (*characterIsMember)(id, SEL, OFUnichar) = (bool (*)(id, SEL, OFUnichar))[characterSet methodForSelector: @selector(characterIsMember:)]; Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -676,11 +676,11 @@ (URL->_URLEncodedPath != nil ? URL->_URLEncodedPath : @"/")]; OFRange range = [path rangeOfString: @"/" - options: OF_STRING_SEARCH_BACKWARDS]; + options: OFStringSearchBackwards]; if (range.location == OFNotFound) @throw [OFInvalidFormatException exception]; Index: src/OFUTF8String.m ================================================================== --- src/OFUTF8String.m +++ src/OFUTF8String.m @@ -980,11 +980,11 @@ objc_autoreleasePoolPop(pool); } - (OFRange)rangeOfString: (OFString *)string - options: (int)options + options: (OFStringSearchOptions)options range: (OFRange)range { const char *cString = string.UTF8String; size_t cStringLength = string.UTF8StringLength; size_t rangeLocation, rangeLength; @@ -1008,11 +1008,11 @@ return OFMakeRange(0, 0); if (cStringLength > rangeLength) return OFMakeRange(OFNotFound, 0); - if (options & OF_STRING_SEARCH_BACKWARDS) { + if (options & OFStringSearchBackwards) { for (size_t i = rangeLength - cStringLength;; i--) { if (memcmp(_s->cString + rangeLocation + i, cString, cStringLength) == 0) { range.location += of_string_utf8_get_index( _s->cString + rangeLocation, i); @@ -1098,17 +1098,17 @@ return (memcmp(_s->cString + (_s->cStringLength - cStringLength), suffix.UTF8String, cStringLength) == 0); } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter - options: (int)options + options: (OFStringSeparationOptions)options { void *pool; OFMutableArray *array; const char *cString; size_t cStringLength; - bool skipEmpty = (options & OF_STRING_SKIP_EMPTY); + bool skipEmpty = (options & OFStringSkipEmptyComponents); size_t last; OFString *component; if (delimiter == nil) @throw [OFInvalidArgumentException exception]; Index: src/platform/amiga/OFString+PathAdditions.m ================================================================== --- src/platform/amiga/OFString+PathAdditions.m +++ src/platform/amiga/OFString+PathAdditions.m @@ -117,11 +117,11 @@ OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." - options: OF_STRING_SEARCH_BACKWARDS].location; + options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } @@ -176,11 +176,11 @@ pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." - options: OF_STRING_SEARCH_BACKWARDS].location; + options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } Index: src/platform/libfat/OFString+PathAdditions.m ================================================================== --- src/platform/libfat/OFString+PathAdditions.m +++ src/platform/libfat/OFString+PathAdditions.m @@ -151,11 +151,11 @@ OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." - options: OF_STRING_SEARCH_BACKWARDS].location; + options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } @@ -221,11 +221,11 @@ pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." - options: OF_STRING_SEARCH_BACKWARDS].location; + options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } Index: src/platform/posix/OFString+PathAdditions.m ================================================================== --- src/platform/posix/OFString+PathAdditions.m +++ src/platform/posix/OFString+PathAdditions.m @@ -144,11 +144,11 @@ OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." - options: OF_STRING_SEARCH_BACKWARDS].location; + options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } @@ -213,11 +213,11 @@ pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." - options: OF_STRING_SEARCH_BACKWARDS].location; + options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } Index: src/platform/windows/OFString+PathAdditions.m ================================================================== --- src/platform/windows/OFString+PathAdditions.m +++ src/platform/windows/OFString+PathAdditions.m @@ -155,11 +155,11 @@ OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." - options: OF_STRING_SEARCH_BACKWARDS].location; + options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } @@ -224,11 +224,11 @@ pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." - options: OF_STRING_SEARCH_BACKWARDS].location; + options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } Index: tests/OFStringTests.m ================================================================== --- tests/OFStringTests.m +++ tests/OFStringTests.m @@ -487,17 +487,17 @@ [C(@"𝄞öö") rangeOfString: @"öö"].location == 1 && [C(@"𝄞öö") rangeOfString: @"ö"].location == 1 && [C(@"𝄞öö") rangeOfString: @"𝄞"].location == 0 && [C(@"𝄞öö") rangeOfString: @"x"].location == OFNotFound && [C(@"𝄞öö") rangeOfString: @"öö" - options: OF_STRING_SEARCH_BACKWARDS].location == 1 && + options: OFStringSearchBackwards].location == 1 && [C(@"𝄞öö") rangeOfString: @"ö" - options: OF_STRING_SEARCH_BACKWARDS].location == 2 && + options: OFStringSearchBackwards].location == 2 && [C(@"𝄞öö") rangeOfString: @"𝄞" - options: OF_STRING_SEARCH_BACKWARDS].location == 0 && + options: OFStringSearchBackwards].location == 0 && [C(@"𝄞öö") rangeOfString: @"x" - options: OF_STRING_SEARCH_BACKWARDS].location == OFNotFound) + options: OFStringSearchBackwards].location == OFNotFound) EXPECT_EXCEPTION( @"Detect out of range in -[rangeOfString:options:range:]", OFOutOfRangeException, [C(@"𝄞öö") rangeOfString: @"ö" options: 0 range: OFMakeRange(3, 1)]) @@ -505,11 +505,11 @@ cs = [OFCharacterSet characterSetWithCharactersInString: @"cđ"]; TEST(@"-[indexOfCharacterFromSet:]", [C(@"abcđabcđe") indexOfCharacterFromSet: cs] == 2 && [C(@"abcđabcđë") indexOfCharacterFromSet: cs - options: OF_STRING_SEARCH_BACKWARDS] == 7 && + options: OFStringSearchBackwards] == 7 && [C(@"abcđabcđë") indexOfCharacterFromSet: cs options: 0 range: OFMakeRange(4, 4)] == 6 && [C(@"abcđabcđëf") @@ -608,11 +608,11 @@ i = 0; TEST(@"-[componentsSeparatedByString:options:]", (a = [C(@"fooXXbarXXXXbazXXXX") componentsSeparatedByString: @"XX" - options: OF_STRING_SKIP_EMPTY]) && + options: OFStringSkipEmptyComponents]) && [[a objectAtIndex: i++] isEqual: @"foo"] && [[a objectAtIndex: i++] isEqual: @"bar"] && [[a objectAtIndex: i++] isEqual: @"baz"] && a.count == i) @@ -637,11 +637,11 @@ i = 0; TEST(@"-[componentsSeparatedByCharactersInSet:options:]", (a = [C(@"fooXYbarXYZXbazXYXZ") componentsSeparatedByCharactersInSet: cs - options: OF_STRING_SKIP_EMPTY]) && + options: OFStringSkipEmptyComponents]) && [[a objectAtIndex: i++] isEqual: @"foo"] && [[a objectAtIndex: i++] isEqual: @"bar"] && [[a objectAtIndex: i++] isEqual: @"baz"] && a.count == i) Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -385,11 +385,11 @@ - (void)setProxy: (OFString *)proxy { @try { size_t pos = [proxy rangeOfString: @":" - options: OF_STRING_SEARCH_BACKWARDS].location; + options: OFStringSearchBackwards].location; OFString *host; unsigned long long port; if (pos == OFNotFound) @throw [OFInvalidFormatException exception];