Index: src/OFConstantString.m ================================================================== --- src/OFConstantString.m +++ src/OFConstantString.m @@ -352,11 +352,11 @@ return [self rangeOfString: string]; } - (of_range_t)rangeOfString: (OFString*)string - options: (of_string_search_options_t)options + options: (int)options { [self finishInitialization]; return [self rangeOfString: string options: options]; Index: src/OFMutableString.h ================================================================== --- src/OFMutableString.h +++ src/OFMutableString.h @@ -165,15 +165,18 @@ * \brief Replaces all occurrences of a string in the specified range with * another string. * * \param string The string to replace * \param replacement The string with which it should be replaced + * \param options Options modifying search behaviour + * Possible values: None yet * \param range The range in which the string should be replaced */ - (void)replaceOccurrencesOfString: (OFString*)string withString: (OFString*)replacement - inRange: (of_range_t)range; + options: (int)options + range: (of_range_t)range; /** * \brief Deletes all whitespaces at the beginning of the string. */ - (void)deleteLeadingWhitespaces; Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -456,16 +456,18 @@ - (void)replaceOccurrencesOfString: (OFString*)string withString: (OFString*)replacement { [self replaceOccurrencesOfString: string withString: replacement - inRange: of_range(0, [self length])]; + options: 0 + range: of_range(0, [self length])]; } - (void)replaceOccurrencesOfString: (OFString*)string withString: (OFString*)replacement - inRange: (of_range_t)range + options: (int)options + range: (of_range_t)range { void *pool = objc_autoreleasePoolPush(), *pool2; const of_unichar_t *unicodeString; const of_unichar_t *searchString = [string unicodeString]; size_t searchLength = [string length]; Index: src/OFMutableString_UTF8.m ================================================================== --- src/OFMutableString_UTF8.m +++ src/OFMutableString_UTF8.m @@ -593,11 +593,12 @@ s->length = newLength; } - (void)replaceOccurrencesOfString: (OFString*)string withString: (OFString*)replacement - inRange: (of_range_t)range + options: (int)options + range: (of_range_t)range { const char *searchString = [string UTF8String]; const char *replacementString = [replacement UTF8String]; size_t searchLength = [string UTF8StringLength]; size_t replacementLength = [replacement UTF8StringLength]; Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -42,14 +42,14 @@ OF_STRING_ENCODING_ISO_8859_15, OF_STRING_ENCODING_WINDOWS_1252, OF_STRING_ENCODING_AUTODETECT = 0xFF } of_string_encoding_t; - -typedef enum of_string_search_options_t { - OF_STRING_SEARCH_BACKWARDS = 1 -} of_string_search_options_t; +enum { + OF_STRING_SEARCH_BACKWARDS = 1, + OF_STRING_SKIP_EMPTY = 2 +}; /* FIXME */ #define OF_STRING_ENCODING_NATIVE OF_STRING_ENCODING_UTF_8 #ifdef OF_HAVE_BLOCKS @@ -625,28 +625,30 @@ /** * \brief Returns the range of the string. * * \param string The string to search - * \param options Options modifying search behaviour + * \param options Options modifying search behaviour. + * Possible values: OF_STRING_SEARCH_BACKWARDS * \return The range of the first occurrence of the string or a range with * OF_NOT_FOUND as start position if it was not found */ - (of_range_t)rangeOfString: (OFString*)string - options: (of_string_search_options_t)options; + options: (int)options; /** * \brief Returns the range of the string in the specified range. * * \param string The string to search - * \param options Options modifying search behaviour + * \param options Options modifying search behaviour. + * Possible values: OF_STRING_SEARCH_BACKWARDS * \param range The range in which to search * \return The range of the first occurrence of the string or a range with * OF_NOT_FOUND as start position if it was not found */ - (of_range_t)rangeOfString: (OFString*)string - options: (of_string_search_options_t)options + options: (int)options range: (of_range_t)range; /** * \brief Returns whether the string contains the specified string. * @@ -702,16 +704,19 @@ * \brief Creates a new string by replacing the occurrences of the specified * string in the specified range with the specified replacement. * * \param string The string to replace * \param replacement The string with which it should be replaced + * \param options Options modifying search behaviour. + * Possible values: None yet * \param range The range in which to replace the string * \return A new string with the occurrences of the specified string replaced */ - (OFString*)stringByReplacingOccurrencesOfString: (OFString*)string withString: (OFString*)replacement - inRange: (of_range_t)range; + options: (int)options + range: (of_range_t)range; /** * \brief Returns the string in uppercase. * * \return The string in uppercase @@ -773,26 +778,27 @@ * \return A boolean whether the string has the specified suffix */ - (BOOL)hasSuffix: (OFString*)suffix; /** - * \brief Splits an OFString into an OFArray of OFStrings. + * \brief Separates an OFString into an OFArray of OFStrings. * - * \param delimiter The delimiter for splitting - * \return An autoreleased OFArray with the split string + * \param delimiter The delimiter for separating + * \return An autoreleased OFArray with the separated string */ - (OFArray*)componentsSeparatedByString: (OFString*)delimiter; /** - * \brief Splits an OFString into an OFArray of OFStrings. + * \brief Separates an OFString into an OFArray of OFStrings. * - * \param delimiter The delimiter for splitting - * \param skipEmpty Whether empty components should be skipped - * \return An autoreleased OFArray with the split string + * \param delimiter The delimiter for separating + * \param options Options according to which the string should be separated + * Possible values: OF_STRING_SKIP_EMPTY + * \return An autoreleased OFArray with the separated string */ - (OFArray*)componentsSeparatedByString: (OFString*)delimiter - skipEmpty: (BOOL)skipEmpty; + options: (int)options; /** * \brief Returns the components of the path. * * \return The components of the path Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1161,19 +1161,19 @@ options: 0 range: of_range(0, [self length])]; } - (of_range_t)rangeOfString: (OFString*)string - options: (of_string_search_options_t)options + options: (int)options { return [self rangeOfString: string options: options range: of_range(0, [self length])]; } - (of_range_t)rangeOfString: (OFString*)string - options: (of_string_search_options_t)options + options: (int)options range: (of_range_t)range { void *pool; const of_unichar_t *searchString; of_unichar_t *unicodeString; @@ -1324,17 +1324,19 @@ return new; } - (OFString*)stringByReplacingOccurrencesOfString: (OFString*)string withString: (OFString*)replacement - inRange: (of_range_t)range + options: (int)options + range: (of_range_t)range { OFMutableString *new = [[self mutableCopy] autorelease]; [new replaceOccurrencesOfString: string withString: replacement - inRange: range]; + options: options + range: range]; [new makeImmutable]; return new; } @@ -1469,19 +1471,20 @@ } - (OFArray*)componentsSeparatedByString: (OFString*)delimiter { return [self componentsSeparatedByString: delimiter - skipEmpty: NO]; + options: 0]; } - (OFArray*)componentsSeparatedByString: (OFString*)delimiter - skipEmpty: (BOOL)skipEmpty + options: (int)options { void *pool; OFMutableArray *array = [OFMutableArray array]; const of_unichar_t *string, *delimiterString; + BOOL skipEmpty = (options & OF_STRING_SKIP_EMPTY); size_t length = [self length]; size_t delimiterLength = [delimiter length]; size_t i, last; OFString *component; Index: src/OFString_UTF8.m ================================================================== --- src/OFString_UTF8.m +++ src/OFString_UTF8.m @@ -1040,11 +1040,11 @@ objc_autoreleasePoolPop(pool); } - (of_range_t)rangeOfString: (OFString*)string - options: (of_string_search_options_t)options + options: (int)options range: (of_range_t)range { const char *cString = [string UTF8String]; size_t i, cStringLength = [string UTF8StringLength]; size_t rangeLocation, rangeLength; @@ -1158,16 +1158,17 @@ return !memcmp(s->cString + (s->cStringLength - cStringLength), [suffix UTF8String], cStringLength); } - (OFArray*)componentsSeparatedByString: (OFString*)delimiter - skipEmpty: (BOOL)skipEmpty + options: (int)options { void *pool; OFMutableArray *array; const char *cString = [delimiter UTF8String]; size_t cStringLength = [delimiter UTF8StringLength]; + BOOL skipEmpty = (options & OF_STRING_SKIP_EMPTY); size_t i, last; OFString *component; array = [OFMutableArray array]; pool = objc_autoreleasePoolPush(); Index: tests/OFStringTests.m ================================================================== --- tests/OFStringTests.m +++ tests/OFStringTests.m @@ -267,13 +267,14 @@ [[a objectAtIndex: i++] isEqual: @"baz"] && [[a objectAtIndex: i++] isEqual: @""] && [[a objectAtIndex: i++] isEqual: @""]) i = 0; - TEST(@"-[componentsSeparatedByString:skipEmpty:]", - (a = [@"fooXXbarXXXXbazXXXX" componentsSeparatedByString: @"XX" - skipEmpty: YES]) && + TEST(@"-[componentsSeparatedByString:options:]", + (a = [@"fooXXbarXXXXbazXXXX" + componentsSeparatedByString: @"XX" + options: OF_STRING_SKIP_EMPTY]) && [a count] == 3 && [[a objectAtIndex: i++] isEqual: @"foo"] && [[a objectAtIndex: i++] isEqual: @"bar"] && [[a objectAtIndex: i++] isEqual: @"baz"]) @@ -499,16 +500,17 @@ (s[0] = [OFMutableString stringWithString: @"XX"]) && R([s[0] replaceOccurrencesOfString: @"X" withString: @"XX"]) && [s[0] isEqual: @"XXXX"]) - TEST(@"-[replaceOccurrencesOfString:withString:inRange:]", + TEST(@"-[replaceOccurrencesOfString:withString:options:range:]", (s[0] = [OFMutableString stringWithString: @"foofoobarfoobarfoo"]) && R([s[0] replaceOccurrencesOfString: @"oo" withString: @"óò" - inRange: of_range(2, 15)]) && + options: 0 + range: of_range(2, 15)]) && [s[0] isEqual: @"foofóòbarfóòbarfoo"]) TEST(@"-[deleteLeadingWhitespaces]", (s[0] = [OFMutableString stringWithString: whitespace[0]]) && R([s[0] deleteLeadingWhitespaces]) &&