1
2
3
4
5
6
7
8
9
|
1
2
3
4
5
6
7
8
9
|
-
+
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2008-2024 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.
*
|
| ︙ | | |
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
-
-
+
+
|
* Windows-specific parts!
*/
#include "config.h"
#import "OFString+PathAdditions.h"
#import "OFArray.h"
#import "OFFileURIHandler.h"
#import "OFURI.h"
#import "OFFileIRIHandler.h"
#import "OFIRI.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
int _OFString_PathAdditions_reference;
@implementation OFString (PathAdditions)
|
| ︙ | | |
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
+
+
+
|
objc_autoreleasePoolPop(pool);
return [ret autorelease];
}
- (OFString *)stringByAppendingPathComponent: (OFString *)component
{
if (self.length == 0)
return component;
if ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"])
return [self stringByAppendingString: component];
else {
OFMutableString *ret = [[self mutableCopy] autorelease];
[ret appendString: @"\\"];
[ret appendString: component];
|
| ︙ | | |
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
371
372
373
374
375
376
377
378
379
380
381
|
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
-
+
-
+
-
+
-
+
|
} else
return [self stringByAppendingFormat: @".%@", extension];
}
- (bool)of_isDirectoryPath
{
return ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"] ||
[OFFileURIHandler of_directoryExistsAtPath: self]);
[OFFileIRIHandler of_directoryExistsAtPath: self]);
}
- (OFString *)of_pathToURIPathWithPercentEncodedHost:
- (OFString *)of_pathToIRIPathWithPercentEncodedHost:
(OFString **)percentEncodedHost
{
OFString *path = self;
if ([path hasPrefix: @"\\\\"]) {
OFArray *components = path.pathComponents;
if (components.count < 2)
@throw [OFInvalidFormatException exception];
*percentEncodedHost = [[components objectAtIndex: 1]
stringByAddingPercentEncodingWithAllowedCharacters:
[OFCharacterSet URIHostAllowedCharacterSet]];
[OFCharacterSet IRIHostAllowedCharacterSet]];
path = [OFString pathWithComponents: [components
objectsInRange: OFMakeRange(2, components.count - 2)]];
}
path = [path stringByReplacingOccurrencesOfString: @"\\"
withString: @"/"];
path = [@"/" stringByAppendingString: path];
return path;
}
- (OFString *)of_URIPathToPathWithPercentEncodedHost:
- (OFString *)of_IRIPathToPathWithPercentEncodedHost:
(OFString *)percentEncodedHost
{
OFString *path = self;
if (path.length > 1 && [path hasSuffix: @"/"] &&
![path hasSuffix: @":/"])
path = [path substringToIndex: path.length - 1];
|
| ︙ | | |
394
395
396
397
398
399
400
401
402
403
404
405
406
|
397
398
399
400
401
402
403
404
405
406
407
408
409
|
-
+
|
path = [OFString stringWithFormat: @"\\\\%@\\%@",
host, path];
}
return path;
}
- (OFString *)of_pathComponentToURIPathComponent
- (OFString *)of_pathComponentToIRIPathComponent
{
return [self stringByReplacingOccurrencesOfString: @"\\"
withString: @"/"];
}
@end
|