Index: src/OFConstantString.m ================================================================== --- src/OFConstantString.m +++ src/OFConstantString.m @@ -431,10 +431,17 @@ { [self finishInitialization]; return [self stringByAppendingPathComponent: component]; } + +- (OFString *)stringByAppendingURLPathComponent: (OFString *)component +{ + [self finishInitialization]; + + return [self stringByAppendingURLPathComponent: component]; +} - (OFString *)stringByPrependingString: (OFString *)string { [self finishInitialization]; Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -1080,10 +1080,18 @@ * @param component The path component to append * @return A new, autoreleased OFString with the path component appended */ - (OFString *)stringByAppendingPathComponent: (OFString *)component; +/*! + * @brief Creates a new string by appending a URL path component. + * + * @param component The URL path component to append + * @return A new, autoreleased OFString with the URL path component appended + */ +- (OFString *)stringByAppendingURLPathComponent: (OFString *)component; + /*! * @brief Creates a new string by prepending another string. * * @param string The string to prepend * @return A new autoreleased OFString with the specified string prepended Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -2053,10 +2053,26 @@ OFMutableString *ret = [[self mutableCopy] autorelease]; [ret appendString: OF_PATH_DELIMITER_STRING]; [ret appendString: component]; + [ret makeImmutable]; + + return ret; + } +} + +- (OFString *)stringByAppendingURLPathComponent: (OFString *)component +{ + if ([self hasSuffix: @"/"]) + return [self stringByAppendingString: component]; + else { + OFMutableString *ret = [[self mutableCopy] autorelease]; + + [ret appendString: @"/"]; + [ret appendString: component]; + [ret makeImmutable]; return ret; } } Index: tests/OFStringTests.m ================================================================== --- tests/OFStringTests.m +++ tests/OFStringTests.m @@ -559,10 +559,21 @@ [s[1] appendString: @"baz"]; TEST(@"-[stringByAppendingPathComponent:]", [[s[0] stringByAppendingPathComponent: @"baz"] isEqual: s[1]] && [[is stringByAppendingPathComponent: @"baz"] isEqual: s[1]]) + s[0] = [mutableStringClass stringWithString: @"foo"]; + [s[0] appendString: @"/"]; + [s[0] appendString: @"bar"]; + s[1] = [mutableStringClass stringWithString: s[0]]; + [s[1] appendString: @"/"]; + is = [stringClass stringWithString: s[1]]; + [s[1] appendString: @"baz"]; + TEST(@"-[stringByAppendingURLPathComponent:]", + [[s[0] stringByAppendingURLPathComponent: @"baz"] isEqual: s[1]] && + [[is stringByAppendingURLPathComponent: @"baz"] isEqual: s[1]]) + TEST(@"-[hasPrefix:]", [C(@"foobar") hasPrefix: @"foo"] && ![C(@"foobar") hasPrefix: @"foobar0"]) TEST(@"-[hasSuffix:]", [C(@"foobar") hasSuffix: @"bar"] && ![C(@"foobar") hasSuffix: @"foobar0"])