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
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
|
#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;
}
ret = [components componentsJoinedByString: @"/"];
[ret retain];
objc_autoreleasePoolPop(pool);
return [ret autorelease];
}
- (bool)isAbsolutePath
{
return [self hasPrefix: @"/"];
}
- (OFArray *)pathComponents
{
OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array];
void *pool = objc_autoreleasePoolPush();
const char *cString = [self UTF8String];
size_t i, last = 0, pathCStringLength = [self UTF8StringLength];
if (pathCStringLength == 0) {
objc_autoreleasePoolPop(pool);
return ret;
}
if (cString[pathCStringLength - 1] == '/')
pathCStringLength--;
for (i = 0; i < pathCStringLength; i++) {
if (cString[i] == '/') {
[ret addObject:
[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;
}
|
>
|
|
<
|
>
|
>
|
>
>
|
|
>
|
<
<
>
|
<
<
<
>
>
>
|
|
|
>
>
|
|
<
<
<
<
|
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
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
|
#import "OFOutOfRangeException.h"
int _OFString_PathAdditions_reference;
@implementation OFString (PathAdditions)
+ (OFString *)pathWithComponents: (OFArray *)components
{
OFMutableString *ret = [OFMutableString string];
void *pool = objc_autoreleasePoolPush();
bool first = true;
for (OFString *component in components) {
if ([component length] == 0)
continue;
if (!first && [component isEqual: @"/"])
continue;
if (!first && ![ret hasSuffix: @"/"])
[ret appendString: @"/"];
[ret appendString: component];
first = false;
}
objc_autoreleasePoolPop(pool);
return ret;
}
- (bool)isAbsolutePath
{
return [self hasPrefix: @"/"];
}
- (OFArray *)pathComponents
{
OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array];
void *pool = objc_autoreleasePoolPush();
const char *cString = [self UTF8String];
size_t i, last = 0, pathCStringLength = [self UTF8StringLength];
if (pathCStringLength == 0) {
objc_autoreleasePoolPop(pool);
return ret;
}
for (i = 0; i < pathCStringLength; i++) {
if (cString[i] == '/') {
if (i == 0)
[ret addObject: @"/"];
else 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;
}
|