ObjFW  Diff

Differences From Artifact [40a93ee30e]:

To Artifact [e7d86c2c3e]:


31
32
33
34
35
36
37

38
39
40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
	void *pool = objc_autoreleasePoolPush();
	bool first = true;

	for (OFString *component in components) {
		if (component.length == 0)
			continue;


		if ([component isEqual: @"\\"] || [component isEqual: @"/"])
			continue;

		if (!first && ![ret hasSuffix: @"\\"] && ![ret hasSuffix: @"/"])

			[ret appendString: @"\\"];

		[ret appendString: component];

		first = false;
	}

	if ([ret hasSuffix: @":"])
		[ret appendString: @"\\"];

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
}








>
|


|
>







<
<
<







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50



51
52
53
54
55
56
57
	void *pool = objc_autoreleasePoolPush();
	bool first = true;

	for (OFString *component in components) {
		if (component.length == 0)
			continue;

		if (!first && ![ret hasSuffix: @":"] &&
		    ([component isEqual: @"\\"] || [component isEqual: @"/"]))
			continue;

		if (!first && ![ret hasSuffix: @"\\"] &&
		    ![ret hasSuffix: @"/"] && ![ret hasSuffix: @":"])
			[ret appendString: @"\\"];

		[ret appendString: component];

		first = false;
	}




	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
}

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
94










95
96
97
98
99
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
127
128

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

- (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]];











			last = i + 1;
		}
	}
	if (i - last != 0)
		[ret addObject: [OFString stringWithUTF8String: cString + last
							length: i - last]];

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
}

- (OFString *)lastPathComponent
{
	void *pool = objc_autoreleasePoolPush();
	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 @"";
	}

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

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

	if (cStringLength - 1 > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];

	for (i = cStringLength - 1; i >= 0; i--) {
		if (cString[i] == '\\' || cString[i] == '/') {
			i++;
			break;
		}
	}

	/*
	 * Only one component, but the trailing delimiter might have been
	 * removed, so return a new string anyway.
	 */
	if (i < 0)
		i = 0;

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

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (OFString *)pathExtension
{
	void *pool = objc_autoreleasePoolPush();
	OFString *ret, *fileName;







>







>








>
>
>
>
|




>
>
>
>
>
>
>
>
>
>
















<
<
<
<
<
|
<
<
|
<
<
<
<
|
<
<
|
<
>
|
<
<
|
<
<
<

|




<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<







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
94
95
96
97
98
99
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


127




128


129

130
131


132



133
134
135
136
137
138


139

















140

141
142
143
144
145
146
147

- (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;
	bool isUNC = false;

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

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

		cString += 2;
		cStringLength -= 2;
	}

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

			last = i + 1;
		} else if (!isUNC && cString[i] == ':') {
			if (i + 1 < cStringLength &&
			    (cString[i + 1] == '\\' || cString[i + 1] == '/'))
				i++;

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

			last = i + 1;
		}
	}
	if (i - last != 0)
		[ret addObject: [OFString stringWithUTF8String: cString + last
							length: i - last]];

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
}

- (OFString *)lastPathComponent
{





	/*


	 * Windows/DOS need the full parsing to determine the last path




	 * component. This could be optimized by not creating the temporary


	 * objects, though.

	 */
	void *pool = objc_autoreleasePoolPush();


	OFString *ret = self.pathComponents.lastObject;




	if (ret == nil) {
		objc_autoreleasePoolPop(pool);
		return @"";
	}



	[ret retain];

















	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (OFString *)pathExtension
{
	void *pool = objc_autoreleasePoolPush();
	OFString *ret, *fileName;
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
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
	[ret retain];
	objc_autoreleasePoolPop(pool);
	return [ret autorelease];
}

- (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;







>
>
>
>

|
|
<
<
<


<
<
|
<
<
<
<
<
<
<
<
<
<
<
<

|


|
<
|

|
>
>
>
>
|
<
<
<
|
<
|

<
<
<
<
<
<
<
<
<
<
<
<
|
<
|
|
|
>
>
>

>

<
<
<
<
|
<







161
162
163
164
165
166
167
168
169
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
	[ret retain];
	objc_autoreleasePoolPop(pool);
	return [ret autorelease];
}

- (OFString *)stringByDeletingLastPathComponent
{
	/*
	 * Windows/DOS need the full parsing to delete the last path component.
	 * This could be optimized, though.
	 */
	void *pool = objc_autoreleasePoolPush();
	OFArray OF_GENERIC(OFString *) *components = self.pathComponents;
	size_t count = components.count;



	OFString *ret;



	if (count == 0) {












		objc_autoreleasePoolPop(pool);
		return @"";
	}

	if (count == 1) {

		OFString *firstComponent = components.firstObject;

		if ([firstComponent hasSuffix: @":"] ||
		    [firstComponent hasSuffix: @":\\"] ||
		    [firstComponent hasSuffix: @":/"] ||
		    [firstComponent hasPrefix: @"\\"]) {
			ret = [firstComponent retain];
			objc_autoreleasePoolPop(pool);



			return [ret autorelease];

		}













		objc_autoreleasePoolPop(pool);

		return @".";
	}

	components = [components objectsInRange:
	    of_range(0, components.count - 1)];
	ret = [OFString pathWithComponents: components];

	[ret retain];
	objc_autoreleasePoolPop(pool);




	return [ret autorelease];

}

- (OFString *)stringByDeletingPathExtension
{
	void *pool;
	OFMutableArray OF_GENERIC(OFString *) *components;
	OFString *ret, *fileName;
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339




340
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
366
367
368
369
370

- (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++) {
			OFString *component = [array objectAtIndex: i];
			OFString *parent =
			    (i > 0 ? [array objectAtIndex: i - 1] : 0);

			if ([component isEqual: @"."] ||
			   component.length == 0) {
				[array removeObjectAtIndex: i];

				done = false;
				break;
			}

			if ([component isEqual: @".."] &&
			    parent != nil && ![parent isEqual: @".."]) {




				[array removeObjectsInRange:
				    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);

	return [ret autorelease];
}

- (OFString *)stringByAppendingPathComponent: (OFString *)component







<
<
<














<
<
<
<
<
<
<


















|
|
>
>
>
>









<
<
<
<
<
<
<
<
<
<
|
<
<
<
<







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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291










292




293
294
295
296
297
298
299

- (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++) {
			OFString *component = [array objectAtIndex: i];
			OFString *parent =
			    (i > 0 ? [array objectAtIndex: i - 1] : 0);

			if ([component isEqual: @"."] ||
			   component.length == 0) {
				[array removeObjectAtIndex: i];

				done = false;
				break;
			}

			if ([component isEqual: @".."] && parent != nil &&
			    ![parent isEqual: @".."] &&
			    ![parent hasSuffix: @":"] &&
			    ![parent hasSuffix: @":\\"] &&
			    ![parent hasSuffix: @"://"] &&
			    (![parent hasPrefix: @"\\"] || i != 1)) {
				[array removeObjectsInRange:
				    of_range(i - 1, 2)];

				done = false;
				break;
			}
		}
	}











	ret = [[OFString pathWithComponents: array] retain];





	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (OFString *)stringByAppendingPathComponent: (OFString *)component