︙ | | |
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
-
+
-
+
|
#endif
static OFString *module = nil;
static OFString *whitespace[] = {
@" \r \t\n\t \tasd \t \t\t\r\n",
@" \t\t \t\t \t \t"
};
static of_unichar_t ucstr[] = {
static OFUnichar ucstr[] = {
0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0x1F03A, 0
};
static of_unichar_t sucstr[] = {
static OFUnichar sucstr[] = {
0xFFFE0000, 0x66000000, 0xF6000000, 0xF6000000, 0x62000000, 0xE4000000,
0x72000000, 0x3AF00100, 0
};
static uint16_t utf16str[] = {
0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0xD83C, 0xDC3A, 0
};
static uint16_t sutf16str[] = {
|
︙ | | |
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
|
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
|
-
+
-
+
|
}
return self;
}
- (instancetype)initWithUTF16String: (const of_char16_t *)UTF16String
length: (size_t)length
byteOrder: (of_byte_order_t)byteOrder
byteOrder: (OFByteOrder)byteOrder
{
self = [super init];
@try {
_string = [[OFMutableString alloc]
initWithUTF16String: UTF16String
length: length
byteOrder: byteOrder];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithUTF32String: (const of_char32_t *)UTF32String
length: (size_t)length
byteOrder: (of_byte_order_t)byteOrder
byteOrder: (OFByteOrder)byteOrder
{
self = [super init];
@try {
_string = [[OFMutableString alloc]
initWithUTF32String: UTF32String
length: length
|
︙ | | |
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
|
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
|
-
+
-
+
|
- (void)dealloc
{
[_string release];
[super dealloc];
}
- (of_unichar_t)characterAtIndex: (size_t)idx
- (OFUnichar)characterAtIndex: (size_t)idx
{
return [_string characterAtIndex: idx];
}
- (size_t)length
{
return _string.length;
}
@end
@implementation SimpleMutableString
+ (void)initialize
{
if (self == [SimpleMutableString class])
[self inheritMethodsFromClass: [SimpleString class]];
}
- (void)replaceCharactersInRange: (of_range_t)range
- (void)replaceCharactersInRange: (OFRange)range
withString: (OFString *)string
{
[_string replaceCharactersInRange: range withString: string];
}
@end
@interface EntityHandler: OFObject <OFStringXMLUnescapingDelegate>
|
︙ | | |
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
263
264
265
266
267
268
|
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
263
264
265
266
267
268
|
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
+
+
|
mutableClass: (Class)mutableStringClass
{
void *pool = objc_autoreleasePoolPush();
OFMutableString *s[3];
OFString *is;
OFArray *a;
size_t i;
const of_unichar_t *ua;
const OFUnichar *ua;
const uint16_t *u16a;
OFCharacterSet *cs;
EntityHandler *h;
#ifdef OF_HAVE_BLOCKS
__block int j;
__block bool ok;
#endif
#define C(s) ((OFString *)[stringClass stringWithString: s])
s[0] = [mutableStringClass stringWithString: @"täs€"];
s[1] = [mutableStringClass string];
s[2] = [[s[0] copy] autorelease];
TEST(@"-[isEqual:]", [s[0] isEqual: s[2]] &&
![s[0] isEqual: [[[OFObject alloc] init] autorelease]])
TEST(@"-[compare:]", [s[0] compare: s[2]] == OF_ORDERED_SAME &&
[s[0] compare: @""] != OF_ORDERED_SAME &&
[C(@"") compare: @"a"] == OF_ORDERED_ASCENDING &&
[C(@"a") compare: @"b"] == OF_ORDERED_ASCENDING &&
[C(@"cd") compare: @"bc"] == OF_ORDERED_DESCENDING &&
[C(@"ä") compare: @"ö"] == OF_ORDERED_ASCENDING &&
[C(@"€") compare: @"ß"] == OF_ORDERED_DESCENDING &&
[C(@"aa") compare: @"z"] == OF_ORDERED_ASCENDING)
TEST(@"-[compare:]", [s[0] compare: s[2]] == OFOrderedSame &&
[s[0] compare: @""] != OFOrderedSame &&
[C(@"") compare: @"a"] == OFOrderedAscending &&
[C(@"a") compare: @"b"] == OFOrderedAscending &&
[C(@"cd") compare: @"bc"] == OFOrderedDescending &&
[C(@"ä") compare: @"ö"] == OFOrderedAscending &&
[C(@"€") compare: @"ß"] == OFOrderedDescending &&
[C(@"aa") compare: @"z"] == OFOrderedAscending)
#ifdef OF_HAVE_UNICODE_TABLES
TEST(@"-[caseInsensitiveCompare:]",
[C(@"a") caseInsensitiveCompare: @"A"] == OF_ORDERED_SAME &&
[C(@"Ä") caseInsensitiveCompare: @"ä"] == OF_ORDERED_SAME &&
[C(@"я") caseInsensitiveCompare: @"Я"] == OF_ORDERED_SAME &&
[C(@"€") caseInsensitiveCompare: @"ß"] == OF_ORDERED_DESCENDING &&
[C(@"ß") caseInsensitiveCompare: @"→"] == OF_ORDERED_ASCENDING &&
[C(@"AA") caseInsensitiveCompare: @"z"] == OF_ORDERED_ASCENDING &&
[C(@"a") caseInsensitiveCompare: @"A"] == OFOrderedSame &&
[C(@"Ä") caseInsensitiveCompare: @"ä"] == OFOrderedSame &&
[C(@"я") caseInsensitiveCompare: @"Я"] == OFOrderedSame &&
[C(@"€") caseInsensitiveCompare: @"ß"] == OFOrderedDescending &&
[C(@"ß") caseInsensitiveCompare: @"→"] == OFOrderedAscending &&
[C(@"AA") caseInsensitiveCompare: @"z"] == OFOrderedAscending &&
[[stringClass stringWithUTF8String: "ABC"] caseInsensitiveCompare:
[stringClass stringWithUTF8String: "AbD"]] ==
[C(@"abc") compare: @"abd"])
#else
TEST(@"-[caseInsensitiveCompare:]",
[C(@"a") caseInsensitiveCompare: @"A"] == OF_ORDERED_SAME &&
[C(@"AA") caseInsensitiveCompare: @"z"] == OF_ORDERED_ASCENDING &&
[C(@"a") caseInsensitiveCompare: @"A"] == OFOrderedSame &&
[C(@"AA") caseInsensitiveCompare: @"z"] == OFOrderedAscending &&
[[stringClass stringWithUTF8String: "ABC"] caseInsensitiveCompare:
[stringClass stringWithUTF8String: "AbD"]] ==
[C(@"abc") compare: @"abd"])
#endif
TEST(@"-[hash] is the same if -[isEqual:] is true",
s[0].hash == s[2].hash)
|
︙ | | |
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
|
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
|
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
+
-
+
|
R(([s[0] appendFormat: @"%02X", 15])) &&
[s[0] isEqual: @"test:1230F"])
TEST(@"-[rangeOfString:]",
[C(@"𝄞öö") rangeOfString: @"öö"].location == 1 &&
[C(@"𝄞öö") rangeOfString: @"ö"].location == 1 &&
[C(@"𝄞öö") rangeOfString: @"𝄞"].location == 0 &&
[C(@"𝄞öö") rangeOfString: @"x"].location == OF_NOT_FOUND &&
[C(@"𝄞öö") rangeOfString: @"x"].location == OFNotFound &&
[C(@"𝄞öö") rangeOfString: @"öö"
options: OF_STRING_SEARCH_BACKWARDS].location == 1 &&
[C(@"𝄞öö") rangeOfString: @"ö"
options: OF_STRING_SEARCH_BACKWARDS].location == 2 &&
[C(@"𝄞öö") rangeOfString: @"𝄞"
options: OF_STRING_SEARCH_BACKWARDS].location == 0 &&
[C(@"𝄞öö") rangeOfString: @"x"
options: OF_STRING_SEARCH_BACKWARDS].location == OF_NOT_FOUND)
options: OF_STRING_SEARCH_BACKWARDS].location == OFNotFound)
EXPECT_EXCEPTION(
@"Detect out of range in -[rangeOfString:options:range:]",
OFOutOfRangeException,
[C(@"𝄞öö") rangeOfString: @"ö" options: 0 range: of_range(3, 1)])
[C(@"𝄞öö") rangeOfString: @"ö" options: 0 range: OFMakeRange(3, 1)])
cs = [OFCharacterSet characterSetWithCharactersInString: @"cđ"];
TEST(@"-[indexOfCharacterFromSet:]",
[C(@"abcđabcđe") indexOfCharacterFromSet: cs] == 2 &&
[C(@"abcđabcđë")
indexOfCharacterFromSet: cs
options: OF_STRING_SEARCH_BACKWARDS] == 7 &&
[C(@"abcđabcđë")
indexOfCharacterFromSet: cs
options: 0
range: of_range(4, 4)] == 6 &&
range: OFMakeRange(4, 4)] == 6 &&
[C(@"abcđabcđëf")
indexOfCharacterFromSet: cs
options: 0
range: of_range(8, 2)] == OF_NOT_FOUND)
range: OFMakeRange(8, 2)] == OFNotFound)
EXPECT_EXCEPTION(
@"Detect out of range in -[indexOfCharacterFromSet:options:range:]",
OFOutOfRangeException,
[C(@"𝄞öö") indexOfCharacterFromSet: cs
options: 0
range: of_range(3, 1)])
range: OFMakeRange(3, 1)])
TEST(@"-[substringWithRange:]",
[[C(@"𝄞öö") substringWithRange: of_range(1, 1)] isEqual: @"ö"] &&
[[C(@"𝄞öö") substringWithRange: of_range(3, 0)] isEqual: @""])
[[C(@"𝄞öö") substringWithRange: OFMakeRange(1, 1)] isEqual: @"ö"] &&
[[C(@"𝄞öö") substringWithRange: OFMakeRange(3, 0)] isEqual: @""])
EXPECT_EXCEPTION(@"Detect out of range in -[substringWithRange:] #1",
OFOutOfRangeException,
[C(@"𝄞öö") substringWithRange: of_range(2, 2)])
[C(@"𝄞öö") substringWithRange: OFMakeRange(2, 2)])
EXPECT_EXCEPTION(@"Detect out of range in -[substringWithRange:] #2",
OFOutOfRangeException,
[C(@"𝄞öö") substringWithRange: of_range(4, 0)])
[C(@"𝄞öö") substringWithRange: OFMakeRange(4, 0)])
TEST(@"-[stringByAppendingString:]",
[[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])
TEST(@"-[stringByPrependingString:]",
[[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"])
|
︙ | | |
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
|
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
|
-
+
-
+
|
@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF")
unsignedLongLongValueWithBase: 16])
TEST(@"-[characters]", (ua = C(@"fööbär🀺").characters) &&
!memcmp(ua, ucstr + 1, sizeof(ucstr) - 8))
#ifdef OF_BIG_ENDIAN
# define SWAPPED_BYTE_ORDER OF_BYTE_ORDER_LITTLE_ENDIAN
# define SWAPPED_BYTE_ORDER OFByteOrderLittleEndian
#else
# define SWAPPED_BYTE_ORDER OF_BYTE_ORDER_BIG_ENDIAN
# define SWAPPED_BYTE_ORDER OFByteOrderBigEndian
#endif
TEST(@"-[UTF16String]", (u16a = C(@"fööbär🀺").UTF16String) &&
!memcmp(u16a, utf16str + 1, of_string_utf16_length(utf16str) * 2) &&
(u16a = [C(@"fööbär🀺")
UTF16StringWithByteOrder: SWAPPED_BYTE_ORDER]) &&
!memcmp(u16a, sutf16str + 1, of_string_utf16_length(sutf16str) * 2))
|
︙ | | |
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
|
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
[s[0] isEqual: @"abcde"] &&
R([s[0] setCharacter: 0x20AC atIndex: 3]) &&
[s[0] isEqual: @"abc€e"] &&
R([s[0] setCharacter: 'x' atIndex: 1]) && [s[0] isEqual: @"axc€e"])
TEST(@"-[deleteCharactersInRange:]",
(s[0] = [mutableStringClass stringWithString: @"𝄞öööbä€"]) &&
R([s[0] deleteCharactersInRange: of_range(1, 3)]) &&
R([s[0] deleteCharactersInRange: OFMakeRange(1, 3)]) &&
[s[0] isEqual: @"𝄞bä€"] &&
R([s[0] deleteCharactersInRange: of_range(0, 4)]) &&
R([s[0] deleteCharactersInRange: OFMakeRange(0, 4)]) &&
[s[0] isEqual: @""])
TEST(@"-[replaceCharactersInRange:withString:]",
(s[0] = [mutableStringClass stringWithString: @"𝄞öööbä€"]) &&
R([s[0] replaceCharactersInRange: of_range(1, 3)
R([s[0] replaceCharactersInRange: OFMakeRange(1, 3)
withString: @"äöüß"]) &&
[s[0] isEqual: @"𝄞äöüßbä€"] &&
R([s[0] replaceCharactersInRange: of_range(4, 2)
R([s[0] replaceCharactersInRange: OFMakeRange(4, 2)
withString: @"b"]) &&
[s[0] isEqual: @"𝄞äöübä€"] &&
R([s[0] replaceCharactersInRange: of_range(0, 7)
R([s[0] replaceCharactersInRange: OFMakeRange(0, 7)
withString: @""]) &&
[s[0] isEqual: @""])
EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #1",
OFOutOfRangeException,
{
s[0] = [mutableStringClass stringWithString: @"𝄞öö"];
[s[0] deleteCharactersInRange: of_range(2, 2)];
[s[0] deleteCharactersInRange: OFMakeRange(2, 2)];
})
EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #2",
OFOutOfRangeException,
[s[0] deleteCharactersInRange: of_range(4, 0)])
[s[0] deleteCharactersInRange: OFMakeRange(4, 0)])
EXPECT_EXCEPTION(@"Detect OoR in "
@"-[replaceCharactersInRange:withString:] #1",
OFOutOfRangeException,
[s[0] replaceCharactersInRange: of_range(2, 2) withString: @""])
[s[0] replaceCharactersInRange: OFMakeRange(2, 2) withString: @""])
EXPECT_EXCEPTION(@"Detect OoR in "
@"-[replaceCharactersInRange:withString:] #2",
OFOutOfRangeException,
[s[0] replaceCharactersInRange: of_range(4, 0) withString: @""])
[s[0] replaceCharactersInRange: OFMakeRange(4, 0) withString: @""])
TEST(@"-[replaceOccurrencesOfString:withString:]",
(s[0] = [mutableStringClass stringWithString:
@"asd fo asd fofo asd"]) &&
R([s[0] replaceOccurrencesOfString: @"fo" withString: @"foo"]) &&
[s[0] isEqual: @"asd foo asd foofoo asd"] &&
(s[0] = [mutableStringClass stringWithString: @"XX"]) &&
R([s[0] replaceOccurrencesOfString: @"X" withString: @"XX"]) &&
[s[0] isEqual: @"XXXX"])
TEST(@"-[replaceOccurrencesOfString:withString:options:range:]",
(s[0] = [mutableStringClass stringWithString:
@"foofoobarfoobarfoo"]) &&
R([s[0] replaceOccurrencesOfString: @"oo"
withString: @"óò"
options: 0
range: of_range(2, 15)]) &&
range: OFMakeRange(2, 15)]) &&
[s[0] isEqual: @"foofóòbarfóòbarfoo"])
TEST(@"-[deleteLeadingWhitespaces]",
(s[0] = [mutableStringClass stringWithString: whitespace[0]]) &&
R([s[0] deleteLeadingWhitespaces]) &&
[s[0] isEqual: @"asd \t \t\t\r\n"] &&
(s[0] = [mutableStringClass stringWithString: whitespace[1]]) &&
|
︙ | | |