ObjFW  Check-in [a4b719e4e9]

Overview
Comment:Add support for UNC paths on Windows
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a4b719e4e9660b426d3bf58f55e516edb1666be6ed0a8d8330cb42909d818b8e
User & Date: js on 2019-03-24 22:29:27
Other Links: manifest | tags
Context
2019-03-25
00:21
tests: Use dot syntax check-in: b045cbb9c7 user: js tags: trunk
2019-03-24
22:29
Add support for UNC paths on Windows check-in: a4b719e4e9 user: js tags: trunk
13:19
Derive of_std{in,out,err} from std{in,out,err} check-in: 0f8a72d43c user: js tags: trunk
Changes

Modified src/OFString+PathAdditions_DOS.m from [b920b866ec] to [40a93ee30e].

54
55
56
57
58
59
60





61
62
63
64
65
66
67
68
69
70
71
72
73
74







75
76
77
78
79
80
81
	objc_autoreleasePoolPop(pool);

	return ret;
}

- (bool)isAbsolutePath
{





	return ([self containsString: @":\\"] || [self containsString: @":/"]);
}

- (OFArray *)pathComponents
{
	OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array];
	void *pool = objc_autoreleasePoolPush();
	const char *cString = self.UTF8String;
	size_t i, last = 0, cStringLength = self.UTF8StringLength;

	if (cStringLength == 0) {
		objc_autoreleasePoolPop(pool);
		return ret;
	}








	for (i = 0; i < cStringLength; i++) {
		if (cString[i] == '\\' || cString[i] == '/') {
			if (i - last != 0)
				[ret addObject: [OFString
				    stringWithUTF8String: cString + last
						  length: i - last]];







>
>
>
>
>














>
>
>
>
>
>
>







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
	objc_autoreleasePoolPop(pool);

	return ret;
}

- (bool)isAbsolutePath
{
#ifdef OF_WINDOWS
	if ([self hasPrefix: @"\\\\"])
		return true;
#endif

	return ([self containsString: @":\\"] || [self containsString: @":/"]);
}

- (OFArray *)pathComponents
{
	OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array];
	void *pool = objc_autoreleasePoolPush();
	const char *cString = self.UTF8String;
	size_t i, last = 0, cStringLength = self.UTF8StringLength;

	if (cStringLength == 0) {
		objc_autoreleasePoolPop(pool);
		return ret;
	}

	if ([self hasPrefix: @"\\\\"]) {
		[ret addObject: @"\\\\"];

		cString += 2;
		cStringLength -= 2;
	}

	for (i = 0; i < cStringLength; i++) {
		if (cString[i] == '\\' || cString[i] == '/') {
			if (i - last != 0)
				[ret addObject: [OFString
				    stringWithUTF8String: cString + last
						  length: i - last]];
100
101
102
103
104
105
106





107
108
109
110
111
112
113
	const char *cString;
	size_t cStringLength;
	ssize_t i;
	OFString *ret;

	if ([self hasSuffix: @":\\"] || [self hasSuffix: @":/"])
		return self;






	cString = self.UTF8String;
	cStringLength = self.UTF8StringLength;

	if (cStringLength == 0) {
		objc_autoreleasePoolPop(pool);
		return @"";







>
>
>
>
>







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
	const char *cString;
	size_t cStringLength;
	ssize_t i;
	OFString *ret;

	if ([self hasSuffix: @":\\"] || [self hasSuffix: @":/"])
		return self;

#ifdef OF_WINDOWS
	if ([self isEqual: @"\\\\"])
		return self;
#endif

	cString = self.UTF8String;
	cStringLength = self.UTF8StringLength;

	if (cStringLength == 0) {
		objc_autoreleasePoolPop(pool);
		return @"";
170
171
172
173
174
175
176



177
178
179
180
181
182
183








184
185
186
187
188
189
190
191
192
193
194
195



196

197
198
199
200







201
202
203
204
205
206
207
208
209
210
211



212

213
214
215
216
217
218
219
}

- (OFString *)stringByDeletingLastPathComponent
{
	void *pool = objc_autoreleasePoolPush();
	const char *cString;
	size_t cStringLength;



	OFString *ret;

	if ([self hasSuffix: @":\\"] || [self hasSuffix: @":/"])
		return self;

	cString = self.UTF8String;
	cStringLength = self.UTF8StringLength;









	if (cStringLength == 0) {
		objc_autoreleasePoolPop(pool);
		return @"";
	}

	if (cString[cStringLength - 1] == '\\' ||
	    cString[cStringLength - 1] == '/')
		cStringLength--;

	if (cStringLength == 0) {
		objc_autoreleasePoolPop(pool);



		return @"";

	}

	for (size_t i = cStringLength; i >= 1; i--) {
		if (cString[i - 1] == '\\' || cString[i - 1] == '/') {







			ret = [[OFString alloc] initWithUTF8String: cString
							    length: i - 1];

			objc_autoreleasePoolPop(pool);

			return [ret autorelease];
		}
	}

	objc_autoreleasePoolPop(pool);




	return @".";

}

- (OFString *)stringByDeletingPathExtension
{
	void *pool;
	OFMutableArray OF_GENERIC(OFString *) *components;
	OFString *ret, *fileName;







>
>
>







>
>
>
>
>
>
>
>



|








>
>
>

>




>
>
>
>
>
>
>











>
>
>

>







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
}

- (OFString *)stringByDeletingLastPathComponent
{
	void *pool = objc_autoreleasePoolPush();
	const char *cString;
	size_t cStringLength;
#ifdef OF_WINDOWS
	bool isUNC = false;
#endif
	OFString *ret;

	if ([self hasSuffix: @":\\"] || [self hasSuffix: @":/"])
		return self;

	cString = self.UTF8String;
	cStringLength = self.UTF8StringLength;

#ifdef OF_WINDOWS
	if ([self hasPrefix: @"\\\\"]) {
		isUNC = true;
		cString += 2;
		cStringLength -= 2;
	}
#endif

	if (cStringLength == 0) {
		objc_autoreleasePoolPop(pool);
		return self;
	}

	if (cString[cStringLength - 1] == '\\' ||
	    cString[cStringLength - 1] == '/')
		cStringLength--;

	if (cStringLength == 0) {
		objc_autoreleasePoolPop(pool);
#ifdef OF_WINDOWS
		return (isUNC ? @"\\\\" : @"");
#else
		return @"";
#endif
	}

	for (size_t i = cStringLength; i >= 1; i--) {
		if (cString[i - 1] == '\\' || cString[i - 1] == '/') {
#ifdef OF_WINDOWS
			if (isUNC) {
				cString -= 2;
				i += 2;
			}
#endif

			ret = [[OFString alloc] initWithUTF8String: cString
							    length: i - 1];

			objc_autoreleasePoolPop(pool);

			return [ret autorelease];
		}
	}

	objc_autoreleasePoolPop(pool);

#ifdef OF_WINDOWS
	return (isUNC ? @"\\\\" : @".");
#else
	return @".";
#endif
}

- (OFString *)stringByDeletingPathExtension
{
	void *pool;
	OFMutableArray OF_GENERIC(OFString *) *components;
	OFString *ret, *fileName;
246
247
248
249
250
251
252



253
254
255
256
257
258
259
260
261
262
263
264
265







266
267
268
269
270
271
272

- (OFString *)stringByStandardizingPath
{
	void *pool = objc_autoreleasePoolPush();
	OFArray OF_GENERIC(OFString *) *components;
	OFMutableArray OF_GENERIC(OFString *) *array;
	OFString *ret;



	bool done = false;

	if (self.length == 0)
		return @"";

	components = self.pathComponents;

	if (components.count == 1) {
		objc_autoreleasePoolPop(pool);
		return [[self copy] autorelease];
	}

	array = [[components mutableCopy] autorelease];








	while (!done) {
		size_t length = array.count;

		done = true;

		for (size_t i = 0; i < length; i++) {







>
>
>













>
>
>
>
>
>
>







289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325

- (OFString *)stringByStandardizingPath
{
	void *pool = objc_autoreleasePoolPush();
	OFArray OF_GENERIC(OFString *) *components;
	OFMutableArray OF_GENERIC(OFString *) *array;
	OFString *ret;
#ifdef OF_WINDOWS
	bool isUNC = false;
#endif
	bool done = false;

	if (self.length == 0)
		return @"";

	components = self.pathComponents;

	if (components.count == 1) {
		objc_autoreleasePoolPop(pool);
		return [[self copy] autorelease];
	}

	array = [[components mutableCopy] autorelease];

#ifdef OF_WINDOWS
	if ([array.firstObject isEqual: @"\\\\"]) {
		isUNC = true;
		[array removeObjectAtIndex: 0];
	}
#endif

	while (!done) {
		size_t length = array.count;

		done = true;

		for (size_t i = 0; i < length; i++) {
288
289
290
291
292
293
294











295
296
297
298
299
300
301
				    of_range(i - 1, 2)];

				done = false;
				break;
			}
		}
	}












	if ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"])
		[array addObject: @""];

	ret = [[array componentsJoinedByString: @"\\"] retain];

	objc_autoreleasePoolPop(pool);







>
>
>
>
>
>
>
>
>
>
>







341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
				    of_range(i - 1, 2)];

				done = false;
				break;
			}
		}
	}

#ifdef OF_WINDOWS
	if (isUNC) {
		/*
		 * Only one \ is needed, as the other one is added by
		 * -[componentsJoinedByString:].
		 */
		[array insertObject: @"\\"
			    atIndex: 0];
	}
#endif

	if ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"])
		[array addObject: @""];

	ret = [[array componentsJoinedByString: @"\\"] retain];

	objc_autoreleasePoolPop(pool);

Modified src/OFURL.m from [3539c64da7] to [48639d0542].

738
739
740
741
742
743
744
















745
746
747
748
749
750
751
			OFString *currentDirectoryPath = [OFFileManager
			    defaultManager].currentDirectoryPath;

			path = [currentDirectoryPath
			    stringByAppendingPathComponent: path];
			path = path.stringByStandardizingPath;
		}

















		path = pathToURLPath(path);

		if (isDirectory && ![path hasSuffix: @"/"])
			path = [path stringByAppendingString: @"/"];

		_URLEncodedScheme = @"file";







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
			OFString *currentDirectoryPath = [OFFileManager
			    defaultManager].currentDirectoryPath;

			path = [currentDirectoryPath
			    stringByAppendingPathComponent: path];
			path = path.stringByStandardizingPath;
		}

#ifdef OF_WINDOWS
		if ([path hasPrefix: @"\\\\"]) {
			OFArray *components = path.pathComponents;

			if (components.count < 2)
				@throw [OFInvalidFormatException exception];

			_URLEncodedHost = [[[components objectAtIndex: 1]
			    stringByURLEncodingWithAllowedCharacters:
			    [OFCharacterSet URLHostAllowedCharacterSet]] copy];
			path = [OFString pathWithComponents:
			    [components objectsInRange:
			    of_range(2, components.count - 2)]];
		}
#endif

		path = pathToURLPath(path);

		if (isDirectory && ![path hasSuffix: @"/"])
			path = [path stringByAppendingString: @"/"];

		_URLEncodedScheme = @"file";
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062











1063
1064
1065
1066
1067
1068
1069
		@throw [OFInvalidArgumentException exception];

	if (![_URLEncodedPath hasPrefix: @"/"])
		@throw [OFInvalidFormatException exception];

	path = self.path;

	if ([path hasSuffix: @"/"])
		path = [path substringWithRange: of_range(0, path.length - 1)];

	path = URLPathToPath(path);












	[path retain];

	objc_autoreleasePoolPop(pool);

	return [path autorelease];
}







|



>
>
>
>
>
>
>
>
>
>
>







1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
		@throw [OFInvalidArgumentException exception];

	if (![_URLEncodedPath hasPrefix: @"/"])
		@throw [OFInvalidFormatException exception];

	path = self.path;

	if (path.length > 1 && [path hasSuffix: @"/"])
		path = [path substringWithRange: of_range(0, path.length - 1)];

	path = URLPathToPath(path);

#ifdef OF_WINDOWS
	if (_URLEncodedHost != nil) {
		if (path.length == 0)
			path = [OFString stringWithFormat: @"\\\\%@",
							   self.host];
		else
			path = [OFString stringWithFormat: @"\\\\%@\\%@",
							   self.host, path];
	}
#endif

	[path retain];

	objc_autoreleasePoolPop(pool);

	return [path autorelease];
}

Modified tests/OFStringTests.m from [0918342cf7] to [6a603058a6].

537
538
539
540
541
542
543
544





545
546
547
548
549
550
551
	TEST(@"-[stringByAppendingString:]",
	    [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])

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

#ifdef OF_HAVE_FILES
# if defined(OF_WINDOWS) || defined(OF_MSDOS)





	TEST(@"-[isAbsolutePath]",
	    [C(@"C:\\foo") isAbsolutePath] && [C(@"a:/foo") isAbsolutePath] &&
	    ![C(@"foo") isAbsolutePath] && ![C(@"b:foo") isAbsolutePath])
# elif defined(OF_AMIGAOS)
	TEST(@"-[isAbsolutePath]",
	    [C(@"dh0:foo") isAbsolutePath] && [C(@"dh0:a/b") isAbsolutePath] &&
	    ![C(@"foo/bar") isAbsolutePath] && ![C(@"foo") isAbsolutePath])







|
>
>
>
>
>







537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
	TEST(@"-[stringByAppendingString:]",
	    [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])

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

#ifdef OF_HAVE_FILES
# if defined(OF_WINDOWS)
	TEST(@"-[isAbsolutePath]",
	    [C(@"C:\\foo") isAbsolutePath] && [C(@"a:/foo") isAbsolutePath] &&
	    ![C(@"foo") isAbsolutePath] && ![C(@"b:foo") isAbsolutePath] &&
	    [C(@"\\\\foo") isAbsolutePath])
# elif  defined(OF_MSDOS)
	TEST(@"-[isAbsolutePath]",
	    [C(@"C:\\foo") isAbsolutePath] && [C(@"a:/foo") isAbsolutePath] &&
	    ![C(@"foo") isAbsolutePath] && ![C(@"b:foo") isAbsolutePath])
# elif defined(OF_AMIGAOS)
	TEST(@"-[isAbsolutePath]",
	    [C(@"dh0:foo") isAbsolutePath] && [C(@"dh0:a/b") isAbsolutePath] &&
	    ![C(@"foo/bar") isAbsolutePath] && ![C(@"foo") isAbsolutePath])
634
635
636
637
638
639
640
641
















642
643
644
645
646
647
648
					 options: OF_STRING_SKIP_EMPTY]) &&
	    [[a objectAtIndex: i++] isEqual: @"foo"] &&
	    [[a objectAtIndex: i++] isEqual: @"bar"] &&
	    [[a objectAtIndex: i++] isEqual: @"baz"] &&
	    [a count] == i)

#ifdef OF_HAVE_FILES
# if defined(OF_WINDOWS) || defined(OF_MSDOS)
















	TEST(@"+[pathWithComponents:]",
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo", @"bar", @"baz", nil]] isEqual: @"foo\\bar\\baz"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"c:", @"foo", @"bar", @"baz", nil]]
	    isEqual: @"c:\\foo\\bar\\baz"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
					 options: OF_STRING_SKIP_EMPTY]) &&
	    [[a objectAtIndex: i++] isEqual: @"foo"] &&
	    [[a objectAtIndex: i++] isEqual: @"bar"] &&
	    [[a objectAtIndex: i++] isEqual: @"baz"] &&
	    [a count] == i)

#ifdef OF_HAVE_FILES
# if defined(OF_WINDOWS)
	TEST(@"+[pathWithComponents:]",
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo", @"bar", @"baz", nil]] isEqual: @"foo\\bar\\baz"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"c:", @"foo", @"bar", @"baz", nil]]
	    isEqual: @"c:\\foo\\bar\\baz"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo/", @"bar\\", @"", @"baz", @"\\", nil]]
	    isEqual: @"foo/bar\\baz"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo", nil]] isEqual: @"foo"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObject: @"c:"]]
	    isEqual: @"c:\\"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"\\\\", @"foo", @"bar", nil]] isEqual: @"\\\\foo\\bar"])
# elif defined(OF_MSDOS)
	TEST(@"+[pathWithComponents:]",
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo", @"bar", @"baz", nil]] isEqual: @"foo\\bar\\baz"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"c:", @"foo", @"bar", @"baz", nil]]
	    isEqual: @"c:\\foo\\bar\\baz"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
687
688
689
690
691
692
693
694































695
696
697
698
699
700
701
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo/", @"bar", @"", @"baz", @"/", nil]]
	    isEqual: @"foo/bar/baz"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo", nil]] isEqual: @"foo"])
# endif

# if defined(OF_WINDOWS) || defined(OF_MSDOS)































	TEST(@"-[pathComponents]",
	    /* c:/tmp */
	    (a = [C(@"c:/tmp") pathComponents]) && [a count] == 2 &&
	    [[a objectAtIndex: 0] isEqual: @"c:"] &&
	    [[a objectAtIndex: 1] isEqual: @"tmp"] &&
	    /* c:\tmp\ */
	    (a = [C(@"c:\\tmp\\") pathComponents]) && [a count] == 2 &&







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo/", @"bar", @"", @"baz", @"/", nil]]
	    isEqual: @"foo/bar/baz"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo", nil]] isEqual: @"foo"])
# endif

# if defined(OF_WINDOWS)
	TEST(@"-[pathComponents]",
	    /* c:/tmp */
	    (a = [C(@"c:/tmp") pathComponents]) && [a count] == 2 &&
	    [[a objectAtIndex: 0] isEqual: @"c:"] &&
	    [[a objectAtIndex: 1] isEqual: @"tmp"] &&
	    /* c:\tmp\ */
	    (a = [C(@"c:\\tmp\\") pathComponents]) && [a count] == 2 &&
	    [[a objectAtIndex: 0] isEqual: @"c:"] &&
	    [[a objectAtIndex: 1] isEqual: @"tmp"] &&
	    /* c:/ */
	    (a = [C(@"c:/") pathComponents]) && [a count] == 1 &&
	    [[a objectAtIndex: 0] isEqual: @"c:"] &&
	    /* foo\bar */
	    (a = [C(@"foo\\bar") pathComponents]) && [a count] == 2 &&
	    [[a objectAtIndex: 0] isEqual: @"foo"] &&
	    [[a objectAtIndex: 1] isEqual: @"bar"] &&
	    /* foo\bar/baz/ */
	    (a = [C(@"foo\\bar/baz/") pathComponents]) && [a count] == 3 &&
	    [[a objectAtIndex: 0] isEqual: @"foo"] &&
	    [[a objectAtIndex: 1] isEqual: @"bar"] &&
	    [[a objectAtIndex: 2] isEqual: @"baz"] &&
	    /* foo\/ */
	    (a = [C(@"foo\\/") pathComponents]) && [a count] == 1 &&
	    [[a objectAtIndex: 0] isEqual: @"foo"] &&
	    [[C(@"") pathComponents] count] == 0 &&
	    /* \\foo\bar */
	    (a = [C(@"\\\\foo\\bar") pathComponents]) && [a count] == 3 &&
	    [[a objectAtIndex: 0] isEqual: @"\\\\"] &&
	    [[a objectAtIndex: 1] isEqual: @"foo"] &&
	    [[a objectAtIndex: 2] isEqual: @"bar"])
# elif defined(OF_MSDOS)
	TEST(@"-[pathComponents]",
	    /* c:/tmp */
	    (a = [C(@"c:/tmp") pathComponents]) && [a count] == 2 &&
	    [[a objectAtIndex: 0] isEqual: @"c:"] &&
	    [[a objectAtIndex: 1] isEqual: @"tmp"] &&
	    /* c:\tmp\ */
	    (a = [C(@"c:\\tmp\\") pathComponents]) && [a count] == 2 &&
791
792
793
794
795
796
797
798












799
800
801
802
803
804
805
	    [[a objectAtIndex: 2] isEqual: @"baz"] &&
	    /* foo// */
	    (a = [C(@"foo//") pathComponents]) && [a count] == 1 &&
	    [[a objectAtIndex: 0] isEqual: @"foo"] &&
	    [[C(@"") pathComponents] count] == 0)
# endif

# if defined(OF_WINDOWS) || defined(OF_MSDOS)












	TEST(@"-[lastPathComponent]",
	    [[C(@"c:/tmp") lastPathComponent] isEqual: @"tmp"] &&
	    [[C(@"c:\\tmp\\") lastPathComponent] isEqual: @"tmp"] &&
	    [[C(@"c:\\") lastPathComponent] isEqual: @"c:\\"] &&
	    [[C(@"c:/") lastPathComponent] isEqual: @"c:/"] &&
	    [[C(@"\\") lastPathComponent] isEqual: @""] &&
	    [[C(@"foo") lastPathComponent] isEqual: @"foo"] &&







|
>
>
>
>
>
>
>
>
>
>
>
>







843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
	    [[a objectAtIndex: 2] isEqual: @"baz"] &&
	    /* foo// */
	    (a = [C(@"foo//") pathComponents]) && [a count] == 1 &&
	    [[a objectAtIndex: 0] isEqual: @"foo"] &&
	    [[C(@"") pathComponents] count] == 0)
# endif

# if defined(OF_WINDOWS)
	TEST(@"-[lastPathComponent]",
	    [[C(@"c:/tmp") lastPathComponent] isEqual: @"tmp"] &&
	    [[C(@"c:\\tmp\\") lastPathComponent] isEqual: @"tmp"] &&
	    [[C(@"c:\\") lastPathComponent] isEqual: @"c:\\"] &&
	    [[C(@"c:/") lastPathComponent] isEqual: @"c:/"] &&
	    [[C(@"\\") lastPathComponent] isEqual: @""] &&
	    [[C(@"foo") lastPathComponent] isEqual: @"foo"] &&
	    [[C(@"foo\\bar") lastPathComponent] isEqual: @"bar"] &&
	    [[C(@"foo/bar/baz/") lastPathComponent] isEqual: @"baz"] &&
	    [[C(@"\\\\foo\\bar") lastPathComponent] isEqual: @"bar"] &&
	    [[C(@"\\\\") lastPathComponent] isEqual: @"\\\\"])
# elif defined(OF_MSDOS)
	TEST(@"-[lastPathComponent]",
	    [[C(@"c:/tmp") lastPathComponent] isEqual: @"tmp"] &&
	    [[C(@"c:\\tmp\\") lastPathComponent] isEqual: @"tmp"] &&
	    [[C(@"c:\\") lastPathComponent] isEqual: @"c:\\"] &&
	    [[C(@"c:/") lastPathComponent] isEqual: @"c:/"] &&
	    [[C(@"\\") lastPathComponent] isEqual: @""] &&
	    [[C(@"foo") lastPathComponent] isEqual: @"foo"] &&
835
836
837
838
839
840
841
842

















843
844
845
846
847
848
849

	TEST(@"-[pathExtension]",
	    [[C(@"foo.bar") pathExtension] isEqual: @"bar"] &&
	    [[C(@"foo/.bar") pathExtension] isEqual: @""] &&
	    [[C(@"foo/.bar.baz") pathExtension] isEqual: @"baz"] &&
	    [[C(@"foo/bar.baz/") pathExtension] isEqual: @"baz"])

# if defined(OF_WINDOWS) || defined(OF_MSDOS)

















	TEST(@"-[stringByDeletingLastPathComponent]",
	    [[C(@"\\tmp") stringByDeletingLastPathComponent] isEqual: @""] &&
	    [[C(@"/tmp/") stringByDeletingLastPathComponent] isEqual: @""] &&
	    [[C(@"c:\\") stringByDeletingLastPathComponent] isEqual: @"c:\\"] &&
	    [[C(@"c:/") stringByDeletingLastPathComponent] isEqual: @"c:/"] &&
	    [[C(@"c:\\tmp/foo/") stringByDeletingLastPathComponent]
	    isEqual: @"c:\\tmp"] &&







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930

	TEST(@"-[pathExtension]",
	    [[C(@"foo.bar") pathExtension] isEqual: @"bar"] &&
	    [[C(@"foo/.bar") pathExtension] isEqual: @""] &&
	    [[C(@"foo/.bar.baz") pathExtension] isEqual: @"baz"] &&
	    [[C(@"foo/bar.baz/") pathExtension] isEqual: @"baz"])

# if defined(OF_WINDOWS)
	TEST(@"-[stringByDeletingLastPathComponent]",
	    [[C(@"\\tmp") stringByDeletingLastPathComponent] isEqual: @""] &&
	    [[C(@"/tmp/") stringByDeletingLastPathComponent] isEqual: @""] &&
	    [[C(@"c:\\") stringByDeletingLastPathComponent] isEqual: @"c:\\"] &&
	    [[C(@"c:/") stringByDeletingLastPathComponent] isEqual: @"c:/"] &&
	    [[C(@"c:\\tmp/foo/") stringByDeletingLastPathComponent]
	    isEqual: @"c:\\tmp"] &&
	    [[C(@"foo\\bar") stringByDeletingLastPathComponent]
	    isEqual: @"foo"] &&
	    [[C(@"\\") stringByDeletingLastPathComponent] isEqual: @""] &&
	    [[C(@"foo") stringByDeletingLastPathComponent] isEqual: @"."] &&
	    [[C(@"\\\\foo\\bar") stringByDeletingLastPathComponent]
	    isEqual: @"\\\\foo"] &&
	    [[C(@"\\\\foo") stringByDeletingLastPathComponent]
	    isEqual: @"\\\\"] &&
	    [[C(@"\\\\") stringByDeletingLastPathComponent] isEqual: @"\\\\"])
# elif defined(OF_MSDOS)
	TEST(@"-[stringByDeletingLastPathComponent]",
	    [[C(@"\\tmp") stringByDeletingLastPathComponent] isEqual: @""] &&
	    [[C(@"/tmp/") stringByDeletingLastPathComponent] isEqual: @""] &&
	    [[C(@"c:\\") stringByDeletingLastPathComponent] isEqual: @"c:\\"] &&
	    [[C(@"c:/") stringByDeletingLastPathComponent] isEqual: @"c:/"] &&
	    [[C(@"c:\\tmp/foo/") stringByDeletingLastPathComponent]
	    isEqual: @"c:\\tmp"] &&
935
936
937
938
939
940
941







942
943
944
945
946
947
948
	    isEqual: @"/foo./bar"] &&
	    [[C(@"foo.bar/") stringByDeletingPathExtension] isEqual: @"foo"] &&
	    [[C(@".foo") stringByDeletingPathExtension] isEqual: @".foo"] &&
	    [[C(@".foo\\bar") stringByDeletingPathExtension]
	    isEqual: @".foo\\bar"] &&
	    [[C(@".foo.bar") stringByDeletingPathExtension] isEqual: @".foo"])
# endif







#endif

	TEST(@"-[decimalValue]",
	    [C(@"1234") decimalValue] == 1234 &&
	    [C(@"\r\n+123  ") decimalValue] == 123 &&
	    [C(@"-500\t") decimalValue] == -500 &&
	    [C(@"\t\t\r\n") decimalValue] == 0)







>
>
>
>
>
>
>







1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
	    isEqual: @"/foo./bar"] &&
	    [[C(@"foo.bar/") stringByDeletingPathExtension] isEqual: @"foo"] &&
	    [[C(@".foo") stringByDeletingPathExtension] isEqual: @".foo"] &&
	    [[C(@".foo\\bar") stringByDeletingPathExtension]
	    isEqual: @".foo\\bar"] &&
	    [[C(@".foo.bar") stringByDeletingPathExtension] isEqual: @".foo"])
# endif

# ifdef OF_WINDOWS
	/* TODO: Add more tests */
	TEST(@"-[stringByStandardizingPath]",
	    [[C(@"\\\\foo\\..\\bar\\qux") stringByStandardizingPath]
	    isEqual: @"\\\\bar\\qux"])
# endif
#endif

	TEST(@"-[decimalValue]",
	    [C(@"1234") decimalValue] == 1234 &&
	    [C(@"\r\n+123  ") decimalValue] == 123 &&
	    [C(@"-500\t") decimalValue] == -500 &&
	    [C(@"\t\t\r\n") decimalValue] == 0)

Modified tests/OFURLTests.m from [ac6cede6ad] to [623af6a22a].

100
101
102
103
104
105
106













107
108
109
110
111
112
113
		   relativeToURL: u1])

#ifdef OF_HAVE_FILES
	TEST(@"+[fileURLWithPath:]",
	    [[[OFURL fileURLWithPath: @"testfile.txt"] fileSystemRepresentation]
	    isEqual: [[[OFFileManager defaultManager] currentDirectoryPath]
	    stringByAppendingPathComponent: @"testfile.txt"]])













#endif

	TEST(@"-[string]",
	    [[u1 string] isEqual: url_str] &&
	    [[u2 string] isEqual: @"http://foo:80"] &&
	    [[u3 string] isEqual: @"http://bar/"] &&
	    [[u4 string] isEqual: @"file:///etc/passwd"])







>
>
>
>
>
>
>
>
>
>
>
>
>







100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
		   relativeToURL: u1])

#ifdef OF_HAVE_FILES
	TEST(@"+[fileURLWithPath:]",
	    [[[OFURL fileURLWithPath: @"testfile.txt"] fileSystemRepresentation]
	    isEqual: [[[OFFileManager defaultManager] currentDirectoryPath]
	    stringByAppendingPathComponent: @"testfile.txt"]])

# ifdef OF_WINDOWS
	OFURL *tmp;
	TEST(@"+[fileURLWithPath:] with UNC",
	    (tmp = [OFURL fileURLWithPath: @"\\\\foo\\bar"]) &&
	    [tmp.host isEqual: @"foo"] && [tmp.path isEqual: @"/bar"] &&
	    [tmp.string isEqual: @"file://foo/bar"] &&
	    [tmp.fileSystemRepresentation isEqual: @"\\\\foo\\bar"] &&
	    (tmp = [OFURL fileURLWithPath: @"\\\\test"]) &&
	    [tmp.host isEqual: @"test"] && [tmp.path isEqual: @"/"] &&
	    [tmp.string isEqual: @"file://test/"] &&
	    [tmp.fileSystemRepresentation isEqual: @"\\\\test"])
# endif
#endif

	TEST(@"-[string]",
	    [[u1 string] isEqual: url_str] &&
	    [[u2 string] isEqual: @"http://foo:80"] &&
	    [[u3 string] isEqual: @"http://bar/"] &&
	    [[u4 string] isEqual: @"file:///etc/passwd"])
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
	    [[u1 path] isEqual: @"/pa?th"] &&
	    [[u4 path] isEqual: @"/etc/passwd"])
	TEST(@"-[pathComponents]",
	    [[u1 pathComponents] isEqual:
	    [OFArray arrayWithObjects: @"", @"pa?th", nil]] &&
	    [[u4 pathComponents] isEqual:
	    [OFArray arrayWithObjects: @"", @"etc", @"passwd", nil]])
	TEST(@"-[lastPathComponent",
	    [[[OFURL URLWithString: @"http://host/foo//bar/baz"]
	    lastPathComponent] isEqual: @"baz"] &&
	    [[[OFURL URLWithString: @"http://host/foo//bar/baz/"]
	    lastPathComponent] isEqual: @"baz"] &&
	    [[[OFURL URLWithString: @"http://host/foo/"]
	    lastPathComponent] isEqual: @"foo"] &&
	    [[[OFURL URLWithString: @"http://host/"]







|







137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
	    [[u1 path] isEqual: @"/pa?th"] &&
	    [[u4 path] isEqual: @"/etc/passwd"])
	TEST(@"-[pathComponents]",
	    [[u1 pathComponents] isEqual:
	    [OFArray arrayWithObjects: @"", @"pa?th", nil]] &&
	    [[u4 pathComponents] isEqual:
	    [OFArray arrayWithObjects: @"", @"etc", @"passwd", nil]])
	TEST(@"-[lastPathComponent]",
	    [[[OFURL URLWithString: @"http://host/foo//bar/baz"]
	    lastPathComponent] isEqual: @"baz"] &&
	    [[[OFURL URLWithString: @"http://host/foo//bar/baz/"]
	    lastPathComponent] isEqual: @"baz"] &&
	    [[[OFURL URLWithString: @"http://host/foo/"]
	    lastPathComponent] isEqual: @"foo"] &&
	    [[[OFURL URLWithString: @"http://host/"]