ObjFW  Check-in [a36135d018]

Overview
Comment:Don't add unwanted whitespaces to character data on indentation.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a36135d0182d4a2364da9f8249b82884662bf504cae7f28f9d97874b5070b1fa
User & Date: js on 2011-06-06 00:35:06
Other Links: manifest | tags
Context
2011-06-06
00:46
Don't let a comment prevent indentation and indent comments correctly. check-in: ddc9f8ac04 user: js tags: trunk
00:35
Don't add unwanted whitespaces to character data on indentation. check-in: a36135d018 user: js tags: trunk
00:22
Add -[{decimal,hexadecimal,float,double}Value] to OFXMLElement. check-in: 2447ceff6e user: js tags: trunk
Changes

Modified src/OFXMLElement.m from [c82b6a1f56] to [f4ee2b186f].

464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
	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];








<







464
465
466
467
468
469
470

471
472
473
474
475
476
477
	char *cString;
	size_t length, i, j, attributesCount;
	OFString *prefix, *parentPrefix;
	OFXMLAttribute **attributesCArray;
	OFString *ret, *tmp;
	OFMutableDictionary *allNamespaces;
	OFString *defaultNS;


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

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

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
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656

	/* Childen */
	if (children != nil) {
		OFXMLElement **childrenCArray = [children cArray];
		size_t childrenCount = [children count];
		IMP append;
		SEL appendSel = @selector(appendCStringWithoutUTF8Checking:);


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




		for (j = 0; j < childrenCount; j++) {
			if (indentation > 0 && childrenCArray[j]->name != nil)









				append(tmp, appendSel, "\n");

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

		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;







>




>
>
>
|
|
>
>
>
>
>
>
>
>
>





|




|
<

<
<


|













|







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
640

641


642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665

	/* Childen */
	if (children != nil) {
		OFXMLElement **childrenCArray = [children cArray];
		size_t childrenCount = [children count];
		IMP append;
		SEL appendSel = @selector(appendCStringWithoutUTF8Checking:);
		BOOL indent;

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

		if (indentation > 0) {
			indent = YES;

			for (j = 0; j < childrenCount; j++) {
				if (childrenCArray[j]->name == nil) {
					indent = NO;
					break;
				}
			}
		} else
			indent = NO;

		for (j = 0; j < childrenCount; j++) {
			if (indent)
				append(tmp, appendSel, "\n");

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

		if (indent)

			append(tmp, appendSel, "\n");



		length += [tmp cStringLength] + [name cStringLength] + 2 +
		    (indent ? 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 (indent)
			for (j = 0; j < level * indentation; j++)
				cString[i++] = ' ';

		cString[i++] = '<';
		cString[i++] = '/';
		if (prefix != nil) {
			length += [prefix cStringLength] + 1;