ObjFW  Check-in [80ac05eb8f]

Overview
Comment:Improve -[stringByAppendingPathComponent:]

This now prevents double slashes / backslashes.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 80ac05eb8f59bc6e39b3e17ac1fb83a39aab9bf233c601e724f2c13f5d5c259f
User & Date: js on 2017-11-14 23:19:06
Other Links: manifest | tags
Context
2017-11-14
23:27
Add -[OFString stringByAppendingURLPathComponent:] check-in: ad18d4f976 user: js tags: trunk
23:19
Improve -[stringByAppendingPathComponent:] check-in: 80ac05eb8f user: js tags: trunk
22:50
OFURL: Improve -[initFileURLWithPath:] check-in: e2f6ad3876 user: js tags: trunk
Changes

Modified src/OFString.m from [0ce80cb81c] to [90e49f1e77].

2043
2044
2045
2046
2047
2048
2049
2050


2051
2052
2053
2054
2055
2056
2057
2058

2059
2060
2061
2062
2063
2064
2065
	[new makeImmutable];

	return new;
}

- (OFString *)stringByAppendingPathComponent: (OFString *)component
{
	void *pool = objc_autoreleasePoolPush();


	OFString *ret;

	ret = [OFString pathWithComponents:
	    [OFArray arrayWithObjects: self, component, nil]];

	[ret retain];
	objc_autoreleasePoolPop(pool);
	return [ret autorelease];

}

- (OFString *)stringByPrependingString: (OFString *)string
{
	OFMutableString *new = [[string mutableCopy] autorelease];

	[new appendString: self];







|
>
>
|

|
|

|
|
|
>







2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
	[new makeImmutable];

	return new;
}

- (OFString *)stringByAppendingPathComponent: (OFString *)component
{
	if ([self hasSuffix: OF_PATH_DELIMITER_STRING])
		return [self stringByAppendingString: component];
	else {
		OFMutableString *ret = [[self mutableCopy] autorelease];

		[ret appendString: OF_PATH_DELIMITER_STRING];
		[ret appendString: component];

		[ret makeImmutable];

		return ret;
	}
}

- (OFString *)stringByPrependingString: (OFString *)string
{
	OFMutableString *new = [[string mutableCopy] autorelease];

	[new appendString: self];

Modified tests/OFStringTests.m from [e3f6078099] to [4115eec41d].

546
547
548
549
550
551
552











553
554
555
556
557
558
559

	TEST(@"-[stringByAppendingString:]",
	    [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])

	TEST(@"-[stringByPrependingString:]",
	    [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"])












	TEST(@"-[hasPrefix:]", [C(@"foobar") hasPrefix: @"foo"] &&
	    ![C(@"foobar") hasPrefix: @"foobar0"])

	TEST(@"-[hasSuffix:]", [C(@"foobar") hasSuffix: @"bar"] &&
	    ![C(@"foobar") hasSuffix: @"foobar0"])

	i = 0;







>
>
>
>
>
>
>
>
>
>
>







546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570

	TEST(@"-[stringByAppendingString:]",
	    [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])

	TEST(@"-[stringByPrependingString:]",
	    [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"])

	s[0] = [mutableStringClass stringWithString: @"foo"];
	[s[0] appendString: OF_PATH_DELIMITER_STRING];
	[s[0] appendString: @"bar"];
	s[1] = [mutableStringClass stringWithString: s[0]];
	[s[1] appendString: OF_PATH_DELIMITER_STRING];
	is = [stringClass stringWithString: s[1]];
	[s[1] appendString: @"baz"];
	TEST(@"-[stringByAppendingPathComponent:]",
	    [[s[0] stringByAppendingPathComponent: @"baz"] isEqual: s[1]] &&
	    [[is stringByAppendingPathComponent: @"baz"] isEqual: s[1]])

	TEST(@"-[hasPrefix:]", [C(@"foobar") hasPrefix: @"foo"] &&
	    ![C(@"foobar") hasPrefix: @"foobar0"])

	TEST(@"-[hasSuffix:]", [C(@"foobar") hasSuffix: @"bar"] &&
	    ![C(@"foobar") hasSuffix: @"foobar0"])

	i = 0;