︙ | | |
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
-
+
|
#include <ctype.h>
#include <sys/types.h>
#import "OFString_UTF8.h"
#import "OFMutableString_UTF8.h"
#import "OFArray.h"
#import "OFAutoreleasePool.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "autorelease.h"
#import "macros.h"
#import "of_asprintf.h"
#import "unicode.h"
extern const uint16_t of_iso_8859_15[256];
extern const uint16_t of_windows_1252[256];
|
︙ | | |
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
|
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
|
-
+
-
+
|
return character;
}
- (void)getCharacters: (of_unichar_t*)buffer
inRange: (of_range_t)range
{
/* TODO: Could be slightly optimized */
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
void *pool = objc_autoreleasePoolPush();
const of_unichar_t *unicodeString = [self unicodeString];
memcpy(buffer, unicodeString + range.start,
range.length * sizeof(of_unichar_t));
[pool release];
objc_autoreleasePoolPop(pool);
}
- (size_t)indexOfFirstOccurrenceOfString: (OFString*)string
{
const char *cString = [string UTF8String];
size_t i, cStringLength = [string UTF8StringLength];
|
︙ | | |
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
|
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
|
-
+
-
+
-
+
|
return !memcmp(s->cString + (s->cStringLength - cStringLength),
[suffix UTF8String], cStringLength);
}
- (OFArray*)componentsSeparatedByString: (OFString*)delimiter
skipEmpty: (BOOL)skipEmpty
{
OFAutoreleasePool *pool;
void *pool;
OFMutableArray *array;
const char *cString = [delimiter UTF8String];
size_t cStringLength = [delimiter UTF8StringLength];
size_t i, last;
OFString *component;
array = [OFMutableArray array];
pool = [[OFAutoreleasePool alloc] init];
pool = objc_autoreleasePoolPush();
if (cStringLength > s->cStringLength) {
[array addObject: [[self copy] autorelease]];
[pool release];
objc_autoreleasePoolPop(pool);
return array;
}
for (i = 0, last = 0; i <= s->cStringLength - cStringLength; i++) {
if (memcmp(s->cString + i, cString, cStringLength))
continue;
|
︙ | | |
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
|
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
|
-
+
-
+
-
+
|
}
component = [OFString stringWithUTF8String: s->cString + last];
if (!skipEmpty || ![component isEqual: @""])
[array addObject: component];
[array makeImmutable];
[pool release];
objc_autoreleasePoolPop(pool);
return array;
}
- (OFArray*)pathComponents
{
OFMutableArray *ret;
OFAutoreleasePool *pool;
void *pool;
size_t i, last = 0, pathCStringLength = s->cStringLength;
ret = [OFMutableArray array];
if (pathCStringLength == 0)
return ret;
pool = [[OFAutoreleasePool alloc] init];
pool = objc_autoreleasePoolPush();
#ifndef _WIN32
if (s->cString[pathCStringLength - 1] == OF_PATH_DELIMITER)
#else
if (s->cString[pathCStringLength - 1] == '/' ||
s->cString[pathCStringLength - 1] == '\\')
#endif
|
︙ | | |
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
|
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
|
-
+
|
}
[ret addObject: [OFString stringWithUTF8String: s->cString + last
length: i - last]];
[ret makeImmutable];
[pool release];
objc_autoreleasePoolPop(pool);
return ret;
}
- (OFString*)lastPathComponent
{
size_t pathCStringLength = s->cStringLength;
|
︙ | | |
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
|
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
|
-
+
+
+
-
+
+
+
-
+
|
return ret;
}
#ifdef OF_HAVE_BLOCKS
- (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
void *pool;
const char *cString = s->cString;
const char *last = cString;
BOOL stop = NO, lastCarriageReturn = NO;
while (!stop && *cString != 0) {
if (lastCarriageReturn && *cString == '\n') {
lastCarriageReturn = NO;
cString++;
last++;
continue;
}
if (*cString == '\n' || *cString == '\r') {
pool = objc_autoreleasePoolPush();
block([OFString
stringWithUTF8String: last
length: cString - last], &stop);
last = cString + 1;
[pool releaseObjects];
objc_autoreleasePoolPop(pool);
}
lastCarriageReturn = (*cString == '\r');
cString++;
}
pool = objc_autoreleasePoolPush();
if (!stop)
block([OFString stringWithUTF8String: last
length: cString - last], &stop);
[pool release];
objc_autoreleasePoolPop(pool);
}
#endif
@end
|