ObjFW  Diff

Differences From Artifact [3bdc0c658c]:

To Artifact [4039ac2894]:


50
51
52
53
54
55
56
57
58


59
60
61
62
63
64
65
66
67
68
69


70
71
72
73
74
75
76
50
51
52
53
54
55
56


57
58
59
60
61
62
63
64
65
66
67


68
69
70
71
72
73
74
75
76







-
-
+
+









-
-
+
+







		[cache addNItems: length
		      fromCArray: string];
	else {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
		OFString *tmp = [OFString stringWithCString: string
						   encoding: encoding
						     length: length];
		[cache addNItems: [tmp cStringLength]
		      fromCArray: [tmp cString]];
		[cache addNItems: [tmp UTF8StringLength]
		      fromCArray: [tmp UTF8String]];
		[pool release];
	}
}

static OFString*
transform_string(OFDataArray *cache, size_t cut, BOOL unescape,
    OFObject <OFStringXMLUnescapingDelegate> *delegate)
{
	OFMutableString *ret = [OFMutableString
	    stringWithCString: [cache cArray]
		       length: [cache count]];
	    stringWithUTF8String: [cache cArray]
			  length: [cache count]];

	[ret replaceOccurrencesOfString: @"\r\n"
			     withString: @"\n"];
	[ret replaceOccurrencesOfString: @"\r"
			     withString: @"\n"];

	if (cut > 0) {
251
252
253
254
255
256
257
258
259


260
261
262
263
264
265
266
251
252
253
254
255
256
257


258
259
260
261
262
263
264
265
266







-
-
+
+







	/* In OF_XMLPARSER_IN_TAG, there can be only spaces */
	if (length - last > 0 && state != OF_XMLPARSER_IN_TAG)
		cache_append(cache, buffer + last, encoding, length - last);
}

- (void)parseString: (OFString*)string
{
	[self parseBuffer: [string cString]
	       withLength: [string cStringLength]];
	[self parseBuffer: [string UTF8String]
	       withLength: [string UTF8StringLength]];
}

- (void)parseStream: (OFStream*)stream
{
	char *buffer = [self allocMemoryWithSize: of_pagesize];

	@try {
379
380
381
382
383
384
385
386
387


388
389
390
391
392
393
394
395
396
397
398
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
379
380
381
382
383
384
385


386
387
388
389
390
391
392
393
394
395
396
397
398
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







-
-
+
+


















-
-
+
+
+


















-
-
+
+







		return NO;

	acceptProlog = NO;

	pi = [pi substringWithRange: of_range(3, [pi length] - 3)];
	pi = [pi stringByDeletingEnclosingWhitespaces];

	cString = [pi cString];
	length = [pi cStringLength];
	cString = [pi UTF8String];
	length = [pi UTF8StringLength];

	for (i = last = 0; i < length; i++) {
		switch (piState) {
		case 0:
			if (cString[i] == ' ' || cString[i] == '\t' ||
			    cString[i] == '\r' || cString[i] == '\n' ||
			    cString[i] == '\f')
				continue;

			last = i;
			piState = 1;
			i--;

			break;
		case 1:
			if (cString[i] != '=')
				continue;

			attribute = [OFString stringWithCString: cString + last
							 length: i - last];
			attribute = [OFString
			    stringWithUTF8String: cString + last
					  length: i - last];
			last = i + 1;
			piState = 2;

			break;
		case 2:
			if (cString[i] != '\'' && cString[i] != '"')
				return NO;

			piDelimiter = cString[i];
			last = i + 1;
			piState = 3;

			break;
		case 3:
			if (cString[i] != piDelimiter)
				continue;

			value = [OFMutableString
			    stringWithCString: cString + last
				       length: i - last];
			    stringWithUTF8String: cString + last
					  length: i - last];

			if ([attribute isEqual: @"version"])
				if (![value hasPrefix: @"1."])
					return NO;

			if ([attribute isEqual: @"encoding"]) {
				[value lower];
514
515
516
517
518
519
520
521
522


523
524
525
526



527
528
529
530



531
532
533
534
535
536
537
515
516
517
518
519
520
521


522
523
524
525


526
527
528




529
530
531
532
533
534
535
536
537
538







-
-
+
+


-
-
+
+
+
-
-
-
-
+
+
+







	if ((length = *i - *last) > 0)
		cache_append(cache, buffer + *last, encoding, length);

	pool = [[OFAutoreleasePool alloc] init];

	cacheCString = [cache cArray];
	cacheLength = [cache count];
	cacheString = [OFString stringWithCString: cacheCString
					   length: cacheLength];
	cacheString = [OFString stringWithUTF8String: cacheCString
					      length: cacheLength];

	if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) {
		name = [[OFString alloc] initWithCString: tmp + 1
						  length: cacheLength -
		name = [[OFString alloc]
		    initWithUTF8String: tmp + 1
				length: cacheLength - (tmp - cacheCString) - 1];
							  (tmp - cacheCString) -
							  1];
		prefix = [[OFString alloc] initWithCString: cacheCString
						    length: tmp - cacheCString];
		prefix = [[OFString alloc]
		    initWithUTF8String: cacheCString
				length: tmp - cacheCString];
	} else {
		name = [cacheString copy];
		prefix = nil;
	}

	if (buffer[*i] == '>' || buffer[*i] == '/') {
		OFAutoreleasePool *pool2;
605
606
607
608
609
610
611
612
613


614
615
616
617



618
619
620
621



622
623
624
625
626
627
628
606
607
608
609
610
611
612


613
614
615
616


617
618
619




620
621
622
623
624
625
626
627
628
629







-
-
+
+


-
-
+
+
+
-
-
-
-
+
+
+







	if ((length = *i - *last) > 0)
		cache_append(cache, buffer + *last, encoding, length);

	pool = [[OFAutoreleasePool alloc] init];

	cacheCString = [cache cArray];
	cacheLength = [cache count];
	cacheString = [OFString stringWithCString: cacheCString
					   length: cacheLength];
	cacheString = [OFString stringWithUTF8String: cacheCString
					      length: cacheLength];

	if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) {
		name = [[OFString alloc] initWithCString: tmp + 1
						  length: cacheLength -
		name = [[OFString alloc]
		    initWithUTF8String: tmp + 1
				length: cacheLength - (tmp - cacheCString) - 1];
							  (tmp - cacheCString) -
							  1];
		prefix = [[OFString alloc] initWithCString: cacheCString
						    length: tmp - cacheCString];
		prefix = [[OFString alloc]
		    initWithUTF8String: cacheCString
				length: tmp - cacheCString];
	} else {
		name = [cacheString copy];
		prefix = nil;
	}

	if (![[previous lastObject] isEqual: cacheString])
		@throw [OFMalformedXMLException newWithClass: isa
746
747
748
749
750
751
752
753
754


755
756
757
758
759
760


761
762
763
764
765


766
767
768


769
770
771
772
773
774
775
747
748
749
750
751
752
753


754
755
756
757
758
759


760
761
762
763
764


765
766
767


768
769
770
771
772
773
774
775
776







-
-
+
+




-
-
+
+



-
-
+
+

-
-
+
+







		return;

	if ((length = *i - *last) > 0)
		cache_append(cache, buffer + *last, encoding, length);

	pool = [[OFAutoreleasePool alloc] init];

	cacheString = [OFMutableString stringWithCString: [cache cArray]
						  length: [cache count]];
	cacheString = [OFMutableString stringWithUTF8String: [cache cArray]
						     length: [cache count]];
	[cacheString deleteEnclosingWhitespaces];
	/* Prevent a useless copy later */
	[cacheString makeImmutable];

	cacheCString = [cacheString cString];
	cacheLength = [cacheString cStringLength];
	cacheCString = [cacheString UTF8String];
	cacheLength = [cacheString UTF8StringLength];

	if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) {
		attributeName = [[OFString alloc]
		    initWithCString: tmp + 1
			     length: cacheLength - (tmp - cacheCString) - 1];
		    initWithUTF8String: tmp + 1
				length: cacheLength - (tmp - cacheCString) - 1];
		attributePrefix = [[OFString alloc]
		    initWithCString: cacheCString
			     length: tmp - cacheCString];
		    initWithUTF8String: cacheCString
				length: tmp - cacheCString];
	} else {
		attributeName = [cacheString copy];
		attributePrefix = nil;
	}

	[pool release];