ObjFW  Check-in [f01153154d]

Overview
Comment:Fix setting of is_utf8.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f01153154dd75e43f833dde4281c4e3a444b86fdb4c3820d4597f0e04463f329
User & Date: js on 2009-10-03 21:12:32
Other Links: manifest | tags
Context
2009-10-03
21:18
Add -[length] to OFString. check-in: 0fcb47fb59 user: js tags: trunk
21:12
Fix setting of is_utf8. check-in: f01153154d user: js tags: trunk
20:41
Indexes are now relative to the Unicode character, not the C character. check-in: 2b615e0443 user: js tags: trunk
Changes

Modified src/OFMutableString.m from [e137055b69] to [693bddf4d9].

37
38
39
40
41
42
43



44
45
46
47
48
49
50
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53







+
+
+








	if (string != NULL)
		[self freeMemory: string];

	len = strlen(str);

	switch (of_string_check_utf8(str, len)) {
	case 0:
		is_utf8 = NO;
		break;
	case 1:
		is_utf8 = YES;
		break;
	case -1:
		string = NULL;
		length = 0;
		is_utf8 = NO;
130
131
132
133
134
135
136
137






138
139
140
141
142
143
144
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152







-
+
+
+
+
+
+







	string[length] = 0;

	return self;
}

- appendString: (OFString*)str
{
	return [self appendCStringWithoutUTF8Checking: [str cString]];
	[self appendCStringWithoutUTF8Checking: [str cString]];

	if (str->is_utf8)
		is_utf8 = YES;

	return self;
}

- appendWithFormat: (OFString*)fmt, ...
{
	id ret;
	va_list args;

Modified src/OFString.m from [329139cf3c] to [5b6856fe26].

455
456
457
458
459
460
461


462
463
464

465

















466
467
468
469
470
471
472
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
488
489
490
491







+
+


-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	}

	return self;
}

- initWithString: (OFString*)str
{
	Class c;

	self = [super init];

	string = strdup([str cString]);
	string = (char*)[str cString];
	length = [str cStringLength];

	switch (of_string_check_utf8(string, length)) {
		case 1:
			is_utf8 = YES;
			break;
		case -1:
			c = isa;
			[self dealloc];
			@throw [OFInvalidEncodingException newWithClass: c];
	}

	if ((string = strdup(string)) == NULL) {
		c = isa;
		[self dealloc];
		@throw [OFOutOfMemoryException newWithClass: c
						       size: length + 1];
	}

	@try {
		[self addMemoryToPool: string];
	} @catch (OFException *e) {
		/*
		 * We can't use [super dealloc] on OS X here.
		 * Compiler bug? Anyway, [self dealloc] will do here as we

Modified src/OFXMLParser.m from [3727e76ca7] to [50080689c1].

508
509
510
511
512
513
514

515
516
517
518
519
520
521
522
523
524
525
526
527
528


529
530


531
532


533
534


535
536


537
538
539
540
541
542
543
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528

529
530
531

532
533
534

535
536
537

538
539
540

541
542
543
544
545
546
547
548
549







+













-
+
+

-
+
+

-
+
+

-
+
+

-
+
+







	size_t i, last;
	BOOL in_entity;
	OFString *ret;

	last = 0;
	in_entity = NO;
	ret = [OFMutableString string];
	ret->is_utf8 = is_utf8;

	for (i = 0; i < length; i++) {
		if (!in_entity && string[i] == '&') {
			[ret appendCStringWithoutUTF8Checking: string + last
						    length: i - last];

			last = i + 1;
			in_entity = YES;
		} else if (in_entity && string[i] == ';') {
			char *entity = string + last;
			size_t len = i - last;

			if (len == 2 && !memcmp(entity, "lt", 2))
				[ret appendString: @"<"];
				[ret appendCStringWithoutUTF8Checking: "<"
							       length: 1];
			else if (len == 2 && !memcmp(entity, "gt", 2))
				[ret appendString: @">"];
				[ret appendCStringWithoutUTF8Checking: ">"
							       length: 1];
			else if (len == 4 && !memcmp(entity, "quot", 4))
				[ret appendString: @"\""];
				[ret appendCStringWithoutUTF8Checking: "\""
							       length: 1];
			else if (len == 4 && !memcmp(entity, "apos", 4))
				[ret appendString: @"'"];
				[ret appendCStringWithoutUTF8Checking: "'"
							       length: 1];
			else if (len == 3 && !memcmp(entity, "amp", 3))
				[ret appendString: @"&"];
				[ret appendCStringWithoutUTF8Checking: "&"
							       length: 1];
			else if (entity[0] == '#') {
				OFAutoreleasePool *pool;
				OFString *tmp;

				pool = [[OFAutoreleasePool alloc] init];
				tmp = parse_numeric_entity(entity, len);