ObjFW  Check-in [1b2efa1f5d]

Overview
Comment:Correctly handle componentsSeparatedByString: @""
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1b2efa1f5d0c47779e1f8f3ce2596bbe52f11e9ca666a25a560b0f51e5a2a132
User & Date: js on 2020-12-22 20:09:40
Other Links: manifest | tags
Context
2020-12-22
20:15
Fix files accidentally being executable check-in: 55fdd76bb7 user: js tags: trunk
20:09
Correctly handle componentsSeparatedByString: @"" check-in: 1b2efa1f5d user: js tags: trunk
18:25
Rename hostname() to avoid shadowing check-in: 1a6dbb19bc user: js tags: trunk
Changes

Modified src/OFString.m from [68a16bb73e] to [0e8c3a02df].

2240
2241
2242
2243
2244
2245
2246
2247

2248
2249
2250
2251
2252
2253
2254







2255
2256
2257
2258
2259
2260
2261
2240
2241
2242
2243
2244
2245
2246

2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268







-
+







+
+
+
+
+
+
+







					 options: 0];
}

- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
				 options: (int)options
{
	void *pool;
	OFMutableArray *array = [OFMutableArray array];
	OFMutableArray *array;
	const of_unichar_t *characters, *delimiterCharacters;
	bool skipEmpty = (options & OF_STRING_SKIP_EMPTY);
	size_t length = self.length;
	size_t delimiterLength = delimiter.length;
	size_t last;
	OFString *component;

	if (delimiter == nil)
		@throw [OFInvalidArgumentException exception];

	if (delimiter.length == 0)
		return [OFArray arrayWithObject: self];

	array = [OFMutableArray array];
	pool = objc_autoreleasePoolPush();

	characters = self.characters;
	delimiterCharacters = delimiter.characters;

	if (delimiterLength > length) {
		[array addObject: [[self copy] autorelease]];

Modified src/OFUTF8String.m from [4b2268ed9f] to [212afc270e].

1109
1110
1111
1112
1113
1114
1115
1116
1117


1118
1119
1120
1121






1122
1123


1124
1125
1126
1127
1128
1129
1130
1109
1110
1111
1112
1113
1114
1115


1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138







-
-
+
+




+
+
+
+
+
+


+
+







}

- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
				 options: (int)options
{
	void *pool;
	OFMutableArray *array;
	const char *cString = delimiter.UTF8String;
	size_t cStringLength = delimiter.UTF8StringLength;
	const char *cString;
	size_t cStringLength;
	bool skipEmpty = (options & OF_STRING_SKIP_EMPTY);
	size_t last;
	OFString *component;

	if (delimiter == nil)
		@throw [OFInvalidArgumentException exception];

	if (delimiter.length == 0)
		return [OFArray arrayWithObject: self];

	array = [OFMutableArray array];
	pool = objc_autoreleasePoolPush();
	cString = delimiter.UTF8String;
	cStringLength = delimiter.UTF8StringLength;

	if (cStringLength > _s->cStringLength) {
		[array addObject: [[self copy] autorelease]];
		objc_autoreleasePoolPop(pool);

		return array;
	}

Modified tests/OFStringTests.m from [bb912e724d] to [484cb7d0ac].

601
602
603
604
605
606
607
608




609
610
611
612
613
614
615
601
602
603
604
605
606
607

608
609
610
611
612
613
614
615
616
617
618







-
+
+
+
+







	    componentsSeparatedByString: @"XX"]) &&
	    [[a objectAtIndex: i++] isEqual: @"foo"] &&
	    [[a objectAtIndex: i++] isEqual: @"bar"] &&
	    [[a objectAtIndex: i++] isEqual: @""] &&
	    [[a objectAtIndex: i++] isEqual: @"baz"] &&
	    [[a objectAtIndex: i++] isEqual: @""] &&
	    [[a objectAtIndex: i++] isEqual: @""] &&
	    a.count == i)
	    a.count == i &&
	    (a = [C(@"foo") componentsSeparatedByString: @""]) &&
	    [[a objectAtIndex: 0] isEqual: @"foo"] &&
	    a.count == 1)

	i = 0;
	TEST(@"-[componentsSeparatedByString:options:]",
	    (a = [C(@"fooXXbarXXXXbazXXXX")
	    componentsSeparatedByString: @"XX"
				options: OF_STRING_SKIP_EMPTY]) &&
	    [[a objectAtIndex: i++] isEqual: @"foo"] &&