ObjFW  Diff

Differences From Artifact [e2d9167ac3]:

To Artifact [7666d17f06]:


160
161
162
163
164
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
198
199
200
201
202
203
204
205
206
207
208
209
- (OFArray*)splitWithDelimiter: (const char*)delimiter
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFArray *array = nil;
	size_t delim_len = strlen(delimiter);
	size_t i, last;

	@try {
		array = [[OFArray alloc] init];

		for (i = 0, last = 0; i <= length; i++) {
			if (OF_UNLIKELY(i == length ||
			    !memcmp(string + i, delimiter, delim_len))) {
				OFString *str;
				char *tmp;

				/*
				 * We can't use [self allocWithSize:] here as
				 * self might be a @""-literal.
				 */
				if ((tmp = malloc(i - last + 1)) == NULL)
					@throw [OFNoMemException
					    newWithClass: isa
						 andSize: i - last + 1];
				memcpy(tmp, string + last, i - last);
				tmp[i - last] = '\0';
				@try {
					str = [OFString stringWithCString: tmp];
				} @finally {
					free(tmp);
				}

				[array add: str];

				[pool releaseObjects];

				i += delim_len - 1;
				last = i + 1;
			}
		}
	} @catch (OFException *e) {
		if (array != nil)
			[array release];
		@throw e;
	} @finally {
		[pool release];
	}

	return [array autorelease];
}
@end







<
|

|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
>
|

|
|
|
|
|
<
|
<
<
|
|
<
|


160
161
162
163
164
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
198
199

200


201
202

203
204
205
- (OFArray*)splitWithDelimiter: (const char*)delimiter
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFArray *array = nil;
	size_t delim_len = strlen(delimiter);
	size_t i, last;


	array = [OFArray array];

	for (i = 0, last = 0; i <= length; i++) {
		if (OF_UNLIKELY(i == length ||
		    !memcmp(string + i, delimiter, delim_len))) {
			OFString *str;
			char *tmp;

			/*
			 * We can't use [self allocWithSize:] here as
			 * self might be a @""-literal.
			 */
			if ((tmp = malloc(i - last + 1)) == NULL)
				@throw [OFNoMemException
				    newWithClass: isa
					 andSize: i - last + 1];
			memcpy(tmp, string + last, i - last);
			tmp[i - last] = '\0';
			@try {
				str = [OFString stringWithCString: tmp];
			} @finally {
				free(tmp);
			}

			[array add: str];
			[array retain];
			[pool releaseObjects];

			i += delim_len - 1;
			last = i + 1;
		}
	}


	[array retain];


	[pool release];


	return array;
}
@end