1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
|
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
|
+
+
+
+
+
+
+
+
+
+
-
+
-
+
+
-
+
-
|
[pool release];
return !compare;
}
- (OFArray*)componentsSeparatedByString: (OFString*)delimiter
{
return [self componentsSeparatedByString: delimiter
skipEmpty: NO];
}
- (OFArray*)componentsSeparatedByString: (OFString*)delimiter
skipEmpty: (BOOL)skipEmpty
{
OFAutoreleasePool *pool;
OFMutableArray *array = [OFMutableArray array];
const of_unichar_t *string, *delimiterString;
size_t length = [self length];
size_t delimiterLength = [delimiter length];
size_t i, last;
OFString *component;
pool = [[OFAutoreleasePool alloc] init];
string = [self unicodeString];
delimiterString = [delimiter unicodeString];
if (delimiterLength > length) {
[array addObject: [[self copy] autorelease]];
[array makeImmutable];
[pool release];
return array;
}
for (i = 0, last = 0; i <= length - delimiterLength; i++) {
if (memcmp(string + i, delimiterString,
delimiterLength * sizeof(of_unichar_t)))
continue;
component = [self substringWithRange: of_range(last, i - last)];
if (!skipEmpty || ![component isEqual: @""])
[array addObject: [self substringWithRange:
[array addObject: component];
of_range(last, i - last)]];
i += delimiterLength - 1;
last = i + 1;
}
component = [self substringWithRange: of_range(last, length - last)];
if (!skipEmpty || ![component isEqual: @""])
[array addObject:
[array addObject: component];
[self substringWithRange: of_range(last, length - last)]];
[array makeImmutable];
[pool release];
return array;
}
|