ObjFW  Diff

Differences From Artifact [223d3e3c81]:

To Artifact [800379d99e]:


23
24
25
26
27
28
29













30





31
32
33
34
35
36
37
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51
52
53
54







+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+







#import "OFOutOfRangeException.h"

int _OFString_PathAdditions_reference;

@implementation OFString (PathAdditions)
+ (OFString *)pathWithComponents: (OFArray *)components
{
	void *pool = objc_autoreleasePoolPush();
	OFString *ret;

	if ([[components firstObject] isEqual: @"/"]) {
		OFMutableArray OF_GENERIC(OFString *) *mutableComponents =
		    [[components mutableCopy] autorelease];

		[mutableComponents replaceObjectAtIndex: 0
					     withObject: @""];

		components = mutableComponents;
	}

	return [components componentsJoinedByString: @"/"];
	ret = [components componentsJoinedByString: @"/"];

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

- (bool)isAbsolutePath
{
	return [self hasPrefix: @"/"];
}

56
57
58
59
60
61
62




63
64
65
66
67
68
69
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90







+
+
+
+







			    [OFString stringWithUTF8String: cString + last
						    length: i - last]];
			last = i + 1;
		}
	}
	[ret addObject: [OFString stringWithUTF8String: cString + last
						length: i - last]];

	if ([[ret firstObject] isEqual: @""])
		[ret replaceObjectAtIndex: 0
			       withObject: @"/"];

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
}
208
209
210
211
212
213
214
215

216
217
218


219










220




221
222

223
224
225
226
227
228
229
230
231
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
263
264
265







-
+

-
-
+
+

+
+
+
+
+
+
+
+
+
+

+
+
+
+

-
+

-







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

- (OFString *)stringByStandardizingPath
{
	void *pool = objc_autoreleasePoolPush();
	OFArray OF_GENERIC(OFString *) *components = [self pathComponents];
	OFArray OF_GENERIC(OFString *) *components;
	OFMutableArray OF_GENERIC(OFString *) *array;
	OFString *ret;
	bool done = false, startsWithEmpty, endsWithEmpty;
	OFString *firstComponent, *ret;
	bool done = false, startsWithSlash, endsWithEmpty;

	if ([self length] == 0)
		return @"";

	components = [self pathComponents];

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

	array = [[components mutableCopy] autorelease];
	firstComponent = [array firstObject];
	startsWithSlash =
	    ([firstComponent isEqual: @"/"] || [firstComponent length] == 0);
	endsWithEmpty = ([[array lastObject] length] == 0);

	if ((startsWithEmpty = [[array firstObject] isEqual: @""]))
	if (startsWithSlash)
		[array removeObjectAtIndex: 0];
	endsWithEmpty = [[array lastObject] isEqual: @""];

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

		done = true;

		for (size_t i = 0; i < length; i++) {
248
249
250
251
252
253
254
255

256
257

258
259
260
261
262
263
264
282
283
284
285
286
287
288

289
290
291
292
293
294
295
296
297
298
299







-
+


+








				done = false;
				break;
			}
		}
	}

	if (startsWithEmpty)
	if (startsWithSlash)
		[array insertObject: @""
			    atIndex: 0];

	if (endsWithEmpty)
		[array addObject: @""];

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

	objc_autoreleasePoolPop(pool);