ObjFW  Diff

Differences From Artifact [67c5a15992]:

To Artifact [567535af96]:


558
559
560
561
562
563
564
565

566
567
568
569
570
571
572
573
574
575

576
577
578
579
580
581
582
583
584
585



586
587
588
589
590


591
592
593
594
595

596
597
598
599
600
601
602
603
604
605
606
607


608
609
610
611
612
613
614
558
559
560
561
562
563
564

565
566
567
568
569
570
571
572
573
574

575
576
577
578
579
580
581
582
583


584
585
586
587
588
589


590
591
592
593
594
595

596
597
598
599
600
601
602
603
604
605
606


607
608
609
610
611
612
613
614
615







-
+









-
+








-
-
+
+
+



-
-
+
+




-
+










-
-
+
+







		defaultNS = parent->ns;
	else if (parent != nil && parent->defaultNamespace != nil)
		defaultNS = parent->defaultNamespace;
	else
		defaultNS = defaultNamespace;

	i = 0;
	length = [name cStringLength] + 3 + (level * indentation);
	length = [name UTF8StringLength] + 3 + (level * indentation);
	cString = [self allocMemoryWithSize: length];

	memset(cString + i, ' ', level * indentation);
	i += level * indentation;

	/* Start of tag */
	cString[i++] = '<';

	if (prefix != nil && ![ns isEqual: defaultNS]) {
		length += [prefix cStringLength] + 1;
		length += [prefix UTF8StringLength] + 1;
		@try {
			cString = [self resizeMemory: cString
					      toSize: length];
		} @catch (id e) {
			[self freeMemory: cString];
			@throw e;
		}

		memcpy(cString + i, [prefix cString], [prefix cStringLength]);
		i += [prefix cStringLength];
		memcpy(cString + i, [prefix UTF8String],
		    [prefix UTF8StringLength]);
		i += [prefix UTF8StringLength];
		cString[i++] = ':';
	}

	memcpy(cString + i, [name cString], [name cStringLength]);
	i += [name cStringLength];
	memcpy(cString + i, [name UTF8String], [name UTF8StringLength]);
	i += [name UTF8StringLength];

	/* xmlns if necessary */
	if (prefix == nil && ((ns != nil && ![ns isEqual: defaultNS]) ||
	    (ns == nil && defaultNS != nil))) {
		length += [ns cStringLength] + 9;
		length += [ns UTF8StringLength] + 9;
		@try {
			cString = [self resizeMemory: cString
					      toSize: length];
		} @catch (id e) {
			[self freeMemory: cString];
			@throw e;
		}

		memcpy(cString + i, " xmlns='", 8);
		i += 8;
		memcpy(cString + i, [ns cString], [ns cStringLength]);
		i += [ns cStringLength];
		memcpy(cString + i, [ns UTF8String], [ns UTF8StringLength]);
		i += [ns UTF8StringLength];
		cString[i++] = '\'';
	}

	/* Attributes */
	attributesCArray = [attributes cArray];
	attributesCount = [attributes count];

622
623
624
625
626
627
628
629

630
631
632


633
634
635
636
637
638
639
640
641
642
643
644
645
646



647
648
649
650
651



652
653
654
655


656
657
658
659
660
661
662
623
624
625
626
627
628
629

630
631


632
633
634
635
636
637
638
639
640
641
642
643
644



645
646
647
648
649



650
651
652
653
654


655
656
657
658
659
660
661
662
663







-
+

-
-
+
+











-
-
-
+
+
+


-
-
-
+
+
+


-
-
+
+







		if ([attributesCArray[j] namespace] != nil &&
		    (attributePrefix = [allNamespaces objectForKey:
		    [attributesCArray[j] namespace]]) == nil)
			@throw [OFUnboundNamespaceException
			    newWithClass: isa
			       namespace: [attributesCArray[j] namespace]];

		length += [attributeName cStringLength] +
		length += [attributeName UTF8StringLength] +
		    (attributePrefix != nil ?
		    [attributePrefix cStringLength] + 1 : 0) +
		    [tmp cStringLength] + 4;
		    [attributePrefix UTF8StringLength] + 1 : 0) +
		    [tmp UTF8StringLength] + 4;

		@try {
			cString = [self resizeMemory: cString
					      toSize: length];
		} @catch (id e) {
			[self freeMemory: cString];
			@throw e;
		}

		cString[i++] = ' ';
		if (attributePrefix != nil) {
			memcpy(cString + i, [attributePrefix cString],
			    [attributePrefix cStringLength]);
			i += [attributePrefix cStringLength];
			memcpy(cString + i, [attributePrefix UTF8String],
			    [attributePrefix UTF8StringLength]);
			i += [attributePrefix UTF8StringLength];
			cString[i++] = ':';
		}
		memcpy(cString + i, [attributeName cString],
		    [attributeName cStringLength]);
		i += [attributeName cStringLength];
		memcpy(cString + i, [attributeName UTF8String],
		    [attributeName UTF8StringLength]);
		i += [attributeName UTF8StringLength];
		cString[i++] = '=';
		cString[i++] = '\'';
		memcpy(cString + i, [tmp cString], [tmp cStringLength]);
		i += [tmp cStringLength];
		memcpy(cString + i, [tmp UTF8String], [tmp UTF8StringLength]);
		i += [tmp UTF8StringLength];
		cString[i++] = '\'';

		[pool2 releaseObjects];
	}

	/* Childen */
	if (children != nil) {
686
687
688
689
690
691
692
693
694


695
696
697
698
699
700

701
702
703
704
705
706
707
687
688
689
690
691
692
693


694
695
696
697
698
699
700

701
702
703
704
705
706
707
708







-
-
+
+





-
+








			child = [childrenCArray[j]
			    _XMLStringWithParent: self
				      namespaces: allNamespaces
				     indentation: (indent ? indentation : 0)
					   level: level + 1];

			[tmp addNItems: [child cStringLength]
			    fromCArray: [child cString]];
			[tmp addNItems: [child UTF8StringLength]
			    fromCArray: [child UTF8String]];
		}

		if (indent)
			[tmp addItem: "\n"];

		length += [tmp count] + [name cStringLength] + 2 +
		length += [tmp count] + [name UTF8StringLength] + 2 +
		    (indent ? level * indentation : 0);
		@try {
			cString = [self resizeMemory: cString
					      toSize: length];
		} @catch (id e) {
			[self freeMemory: cString];
			@throw e;
716
717
718
719
720
721
722
723

724
725
726
727
728
729
730
731
732
733
734



735
736
737
738


739
740
741
742
743
744
745
746
747
748
749


750
751
752
753
754
755
756
717
718
719
720
721
722
723

724
725
726
727
728
729
730
731
732



733
734
735
736
737


738
739
740
741
742
743
744
745
746
747
748


749
750
751
752
753
754
755
756
757







-
+








-
-
-
+
+
+


-
-
+
+









-
-
+
+







			memset(cString + i, ' ', level * indentation);
			i += level * indentation;
		}

		cString[i++] = '<';
		cString[i++] = '/';
		if (prefix != nil) {
			length += [prefix cStringLength] + 1;
			length += [prefix UTF8StringLength] + 1;
			@try {
				cString = [self resizeMemory: cString
						      toSize: length];
			} @catch (id e) {
				[self freeMemory: cString];
				@throw e;
			}

			memcpy(cString + i, [prefix cString],
			    [prefix cStringLength]);
			i += [prefix cStringLength];
			memcpy(cString + i, [prefix UTF8String],
			    [prefix UTF8StringLength]);
			i += [prefix UTF8StringLength];
			cString[i++] = ':';
		}
		memcpy(cString + i, [name cString], [name cStringLength]);
		i += [name cStringLength];
		memcpy(cString + i, [name UTF8String], [name UTF8StringLength]);
		i += [name UTF8StringLength];
	} else
		cString[i++] = '/';

	cString[i++] = '>';
	assert(i == length);

	[pool release];

	@try {
		ret = [OFString stringWithCString: cString
					   length: length];
		ret = [OFString stringWithUTF8String: cString
					      length: length];
	} @finally {
		[self freeMemory: cString];
	}
	return ret;
}

- (OFString*)XMLString