ObjFW  Diff

Differences From Artifact [07cdc30ecf]:

To Artifact [c30a5b5e0c]:


433
434
435
436
437
438
439


440
441
442
443
444
445
446
447
448

449
450
451
452
453
454
455
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







+
+









+







	 * would create a real copy each time -[copy] is called.
	 */
	ret->isa = [OFString class];
	return ret;
}

- (OFString*)_XMLStringWithParent: (OFXMLElement*)parent
		      indentation: (unsigned int)indentation
			    level: (size_t)level
{
	OFAutoreleasePool *pool, *pool2;
	char *cString;
	size_t length, i, j, attributesCount;
	OFString *prefix, *parentPrefix;
	OFXMLAttribute **attributesCArray;
	OFString *ret, *tmp;
	OFMutableDictionary *allNamespaces;
	OFString *defaultNS;
	BOOL indentAfter = YES;

	if (characters != nil)
		return [characters stringByXMLEscaping];

	if (CDATA != nil)
		return [OFString stringWithFormat: @"<![CDATA[%@]]>", CDATA];

481
482
483
484
485
486
487
488

489



490
491
492
493
494
495
496
484
485
486
487
488
489
490

491
492
493
494
495
496
497
498
499
500
501
502







-
+

+
+
+







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

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

	for (j = 0; j < level * indentation; j++)
		cString[i++] = ' ';

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

	if (prefix != nil && ![ns isEqual: defaultNS]) {
		length += [prefix cStringLength] + 1;
		@try {
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
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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639







-
+
+
+
+

-
+
+
+
+

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









+


+
+
+
+
+







		size_t childrenCount = [children count];
		IMP append;
		SEL appendSel = @selector(appendCStringWithoutUTF8Checking:);

		tmp = [OFMutableString string];
		append = [tmp methodForSelector: appendSel];

		for (j = 0; j < childrenCount; j++)
		for (j = 0; j < childrenCount; j++) {
			if (indentation > 0 && childrenCArray[j]->name != nil)
				append(tmp, appendSel, "\n");

			append(tmp, appendSel,
			    [[childrenCArray[j] _XMLStringWithParent: self]
			    [[childrenCArray[j]
			    _XMLStringWithParent: self
				     indentation: indentation
					   level: level + 1]
			    cString]);

		length += [tmp cStringLength] + [name cStringLength] + 2;
		}

		if (indentation > 0 && childrenCount > 0 &&
		    childrenCArray[j - 1]->name != nil)
			append(tmp, appendSel, "\n");
		else
			indentAfter = NO;

		length += [tmp cStringLength] + [name cStringLength] + 2 +
		    (indentAfter ? level * indentation : 0);
		@try {
			cString = [self resizeMemory: cString
					      toSize: length];
		} @catch (id e) {
			[self freeMemory: cString];
			@throw e;
		}

		cString[i++] = '>';

		memcpy(cString + i, [tmp cString], [tmp cStringLength]);
		i += [tmp cStringLength];

		if (indentAfter)
			for (j = 0; j < level * indentation; j++)
				cString[i++] = ' ';

		cString[i++] = '<';
		cString[i++] = '/';
		if (prefix != nil) {
			length += [prefix cStringLength] + 1;
			@try {
				cString = [self resizeMemory: cString
						      toSize: length];
638
639
640
641
642
643
644
645










646
647
648
649
650

651
652
653
654
655
656
657
664
665
666
667
668
669
670

671
672
673
674
675
676
677
678
679
680
681
682
683
684

685
686
687
688
689
690
691
692







-
+
+
+
+
+
+
+
+
+
+




-
+







		[self freeMemory: cString];
	}
	return ret;
}

- (OFString*)XMLString
{
	return [self _XMLStringWithParent: nil];
	return [self _XMLStringWithParent: nil
			      indentation: 0
				    level: 0];
}

- (OFString*)XMLStringWithIndentation: (unsigned int)indentation
{
	return [self _XMLStringWithParent: nil
			      indentation: indentation
				    level: 0];
}

- (OFString*)description
{
	return [self XMLString];
	return [self XMLStringWithIndentation: 2];
}

- (OFXMLElement*)XMLElementBySerializing
{
	OFAutoreleasePool *pool;
	OFXMLElement *element;