ObjFW  Diff

Differences From Artifact [36e450e8e9]:

To Artifact [b0bbce5a9e]:


399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
			return SIZE_MAX;
	}
}

- (OFString*)substringFromIndex: (size_t)start
			toIndex: (size_t)end
{
	char *tmp;
	size_t len;
	OFString *ret;

	if (start > end)
		@throw [OFInvalidArgumentException newWithClass: isa
						    andSelector: _cmd];

	if (end > length)
		@throw [OFOutOfRangeException newWithClass: isa];

	len = end - start;

	if ((tmp = malloc(len + 1)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
						    andSize: len + 1];

	if (len)
		memcpy(tmp, string + start, len);
	tmp[len] = 0;

	@try {
		ret = [OFString stringWithCString: tmp];
	} @finally {
		free(tmp);
	}

	return ret;
}

- (OFArray*)splitWithDelimiter: (OFString*)delimiter
{
	OFAutoreleasePool *pool;
	OFArray *array = nil;
	OFString *str;
	const char *delim = [delimiter cString];
	size_t delim_len = [delimiter length];
	size_t i, last;

	array = [OFMutableArray array];
	pool = [[OFAutoreleasePool alloc] init];

	if (delim_len > length) {
		str = [[self copy] autorelease];
		[array addObject: str];
		[pool release];

		return array;
	}

	for (i = 0, last = 0; i <= length - delim_len; i++) {
		char *tmp;

		if (memcmp(string + i, delim, delim_len))
			continue;

		/*
		 * We can't use [self allocMemoryWithSize:] here as self might
		 * be a @""-literal.
		 */
		if ((tmp = malloc(i - last + 1)) == NULL)
			@throw [OFOutOfMemoryException
			    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 addObject: str];
		[pool releaseObjects];

		i += delim_len - 1;
		last = i + 1;
	}
	[array addObject: [OFString stringWithCString: string + last]];

	[pool release];








<
<
<
<







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





|
<








<
|






<
<



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







399
400
401
402
403
404
405




406
407
408
409
410
411
412











413



414

415
416
417
418
419
420

421
422
423
424
425
426
427
428

429
430
431
432
433
434
435


436
437
438
















439

440
441
442
443
444
445
446
447
			return SIZE_MAX;
	}
}

- (OFString*)substringFromIndex: (size_t)start
			toIndex: (size_t)end
{




	if (start > end)
		@throw [OFInvalidArgumentException newWithClass: isa
						    andSelector: _cmd];

	if (end > length)
		@throw [OFOutOfRangeException newWithClass: isa];












	return [OFString stringWithCString: string + start



				 andLength: end - start];

}

- (OFArray*)splitWithDelimiter: (OFString*)delimiter
{
	OFAutoreleasePool *pool;
	OFArray *array;

	const char *delim = [delimiter cString];
	size_t delim_len = [delimiter length];
	size_t i, last;

	array = [OFMutableArray array];
	pool = [[OFAutoreleasePool alloc] init];

	if (delim_len > length) {

		[array addObject: [[self copy] autorelease]];
		[pool release];

		return array;
	}

	for (i = 0, last = 0; i <= length - delim_len; i++) {


		if (memcmp(string + i, delim, delim_len))
			continue;

















		[array addObject: [OFString stringWithCString: string + last

						    andLength: i - last]];
		i += delim_len - 1;
		last = i + 1;
	}
	[array addObject: [OFString stringWithCString: string + last]];

	[pool release];