ObjFW  Diff

Differences From Artifact [dd89e81e6e]:

To Artifact [808aebc7d8]:


20
21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40







-






+







#include <stdlib.h>
#include <string.h>

#include <sys/types.h>

#import "OFString.h"
#import "OFMutableString_UTF8.h"
#import "OFAutoreleasePool.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfRangeException.h"

#import "autorelease.h"
#import "macros.h"

#import "of_asprintf.h"
#import "unicode.h"

static struct {
	Class isa;
256
257
258
259
260
261
262
263

264
265
266
267
268
269
270
256
257
258
259
260
261
262

263
264
265
266
267
268
269
270







-
+







}

- (void)_convertWithWordStartTable: (const of_unichar_t *const[])startTable
		   wordMiddleTable: (const of_unichar_t *const[])middleTable
		wordStartTableSize: (size_t)startTableSize
	       wordMiddleTableSize: (size_t)middleTableSize
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	void *pool = objc_autoreleasePoolPush();
	const of_unichar_t *string = [self unicodeString];
	size_t i, length = [self length];
	BOOL isStart = YES;

	for (i = 0; i < length; i++) {
		const of_unichar_t *const *table;
		size_t tableSize;
291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306
307
308
309
310

311
312
313
314

315
316
317
318
319
320

321
322
323
324
325

326
327
328
329
330
331

332
333
334
335
336

337
338
339
340
341
342
343

344
345
346
347
348
349

350
351
352
353
354
355
356
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305
306
307
308
309

310
311
312
313

314
315
316
317
318
319

320
321
322
323
324

325
326
327
328
329
330

331
332
333
334
335

336
337
338
339
340
341
342

343
344
345
346
347
348

349
350
351
352
353
354
355
356







-
+











-
+



-
+





-
+




-
+





-
+




-
+






-
+





-
+







			break;
		default:
			isStart = NO;
			break;
		}
	}

	[pool release];
	objc_autoreleasePoolPop(pool);
}

- (void)setCharacter: (of_unichar_t)character
	     atIndex: (size_t)index
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}

- (void)appendUTF8String: (const char*)UTF8String
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	void *pool = objc_autoreleasePoolPush();

	[self appendString: [OFString stringWithUTF8String: UTF8String]];

	[pool release];
	objc_autoreleasePoolPop(pool);
}

- (void)appendUTF8String: (const char*)UTF8String
	      withLength: (size_t)UTF8StringLength
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	void *pool = objc_autoreleasePoolPush();

	[self appendString: [OFString stringWithUTF8String: UTF8String
						    length: UTF8StringLength]];

	[pool release];
	objc_autoreleasePoolPop(pool);
}

- (void)appendCString: (const char*)cString
	 withEncoding: (of_string_encoding_t)encoding
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	void *pool = objc_autoreleasePoolPush();

	[self appendString: [OFString stringWithCString: cString
					       encoding: encoding]];

	[pool release];
	objc_autoreleasePoolPop(pool);
}

- (void)appendCString: (const char*)cString
	 withEncoding: (of_string_encoding_t)encoding
	       length: (size_t)cStringLength
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	void *pool = objc_autoreleasePoolPush();

	[self appendString: [OFString stringWithCString: cString
					       encoding: encoding
						 length: cStringLength]];

	[pool release];
	objc_autoreleasePoolPop(pool);
}

- (void)appendString: (OFString*)string
{
	return [self insertString: string
			  atIndex: [self length]];
}
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
488
489
490
491
492
493
494
495
496
497
498
499


500
501
502
503
504

505
506
507
508
509
510
511
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
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







-
+










-
+



-
+















-
+
+




-
+







				 inRange: of_range(0, [self length])];
}

- (void)replaceOccurrencesOfString: (OFString*)string
			withString: (OFString*)replacement
			   inRange: (of_range_t)range
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2;
	void *pool = objc_autoreleasePoolPush(), *pool2;
	const of_unichar_t *unicodeString;
	const of_unichar_t *searchString = [string unicodeString];
	size_t searchLength = [string length];
	size_t replacementLength = [replacement length];
	size_t i;

	if (range.start + range.length > [self length])
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	if (searchLength > range.length) {
		[pool release];
		objc_autoreleasePoolPop(pool);
		return;
	}

	pool2 = [[OFAutoreleasePool alloc] init];
	pool2 = objc_autoreleasePoolPush();
	unicodeString = [self unicodeString];

	for (i = range.start; i <= range.length - searchLength; i++) {
		if (memcmp(unicodeString + i, searchString,
		    searchLength * sizeof(of_unichar_t)))
			continue;

		[self replaceCharactersInRange: of_range(i, searchLength)
				    withString: replacement];

		range.length -= searchLength;
		range.length += replacementLength;

		i += replacementLength - 1;

		[pool2 releaseObjects];
		objc_autoreleasePoolPop(pool2);
		pool2 = objc_autoreleasePoolPush();

		unicodeString = [self unicodeString];
	}

	[pool release];
	objc_autoreleasePoolPop(pool);
}

- (void)deleteLeadingWhitespaces
{
	size_t i, length = [self length];

	for (i = 0; i < length; i++) {