1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
/*
* This file is also used for MS-DOS! Don't forget to #ifdef Windows-specific
* parts!
*/
#include "config.h"
#import "OFString+PathAdditions.h"
#import "OFArray.h"
#import "OFFileURLHandler.h"
|
<
<
|
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
/*
* This file is also used for MS-DOS and MiNT! Don't forget to #ifdef
* Windows-specific parts!
*/
#include "config.h"
#import "OFString+PathAdditions.h"
#import "OFArray.h"
#import "OFFileURLHandler.h"
|
︙ | | | ︙ | |
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
{
void *pool = objc_autoreleasePoolPush();
OFString *ret, *fileName;
size_t pos;
fileName = self.lastPathComponent;
pos = [fileName rangeOfString: @"."
options: OF_STRING_SEARCH_BACKWARDS].location;
if (pos == OF_NOT_FOUND || pos == 0) {
objc_autoreleasePoolPop(pool);
return @"";
}
ret = [fileName substringFromIndex: pos + 1];
[ret retain];
|
|
|
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
{
void *pool = objc_autoreleasePoolPush();
OFString *ret, *fileName;
size_t pos;
fileName = self.lastPathComponent;
pos = [fileName rangeOfString: @"."
options: OFStringSearchBackwards].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return @"";
}
ret = [fileName substringFromIndex: pos + 1];
[ret retain];
|
︙ | | | ︙ | |
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
}
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];
}
|
|
|
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
}
objc_autoreleasePoolPop(pool);
return @".";
}
components = [components objectsInRange:
OFRangeMake(0, components.count - 1)];
ret = [OFString pathWithComponents: components];
[ret retain];
objc_autoreleasePoolPop(pool);
return [ret autorelease];
}
|
︙ | | | ︙ | |
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
return [[self copy] autorelease];
pool = objc_autoreleasePoolPush();
components = [[self.pathComponents mutableCopy] autorelease];
fileName = components.lastObject;
pos = [fileName rangeOfString: @"."
options: OF_STRING_SEARCH_BACKWARDS].location;
if (pos == OF_NOT_FOUND || pos == 0) {
objc_autoreleasePoolPop(pool);
return [[self copy] autorelease];
}
fileName = [fileName substringToIndex: pos];
[components replaceObjectAtIndex: components.count - 1
withObject: fileName];
|
|
|
|
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
return [[self copy] autorelease];
pool = objc_autoreleasePoolPush();
components = [[self.pathComponents mutableCopy] autorelease];
fileName = components.lastObject;
pos = [fileName rangeOfString: @"."
options: OFStringSearchBackwards].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return [[self copy] autorelease];
}
fileName = [fileName substringToIndex: pos];
[components replaceObjectAtIndex: components.count - 1
withObject: fileName];
|
︙ | | | ︙ | |
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
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;
}
}
}
|
|
|
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
if ([component isEqual: @".."] && parent != nil &&
![parent isEqual: @".."] &&
![parent hasSuffix: @":"] &&
![parent hasSuffix: @":\\"] &&
![parent hasSuffix: @"://"] &&
(![parent hasPrefix: @"\\"] || i != 1)) {
[array removeObjectsInRange:
OFRangeMake(i - 1, 2)];
done = false;
break;
}
}
}
|
︙ | | | ︙ | |
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
if (components.count < 2)
@throw [OFInvalidFormatException exception];
*URLEncodedHost = [[components objectAtIndex: 1]
stringByURLEncodingWithAllowedCharacters:
[OFCharacterSet URLHostAllowedCharacterSet]];
path = [OFString pathWithComponents: [components
objectsInRange: of_range(2, components.count - 2)]];
}
path = [path stringByReplacingOccurrencesOfString: @"\\"
withString: @"/"];
path = [path stringByPrependingString: @"/"];
return path;
|
|
|
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
if (components.count < 2)
@throw [OFInvalidFormatException exception];
*URLEncodedHost = [[components objectAtIndex: 1]
stringByURLEncodingWithAllowedCharacters:
[OFCharacterSet URLHostAllowedCharacterSet]];
path = [OFString pathWithComponents: [components
objectsInRange: OFRangeMake(2, components.count - 2)]];
}
path = [path stringByReplacingOccurrencesOfString: @"\\"
withString: @"/"];
path = [path stringByPrependingString: @"/"];
return path;
|
︙ | | | ︙ | |