ObjFW  Check-in [a69e13fa8d]

Overview
Comment:OFXMLParser: Improve handling of whitespaces.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a69e13fa8d71f4746369862b95ca9689857d84da04232df4a893dbe782d8332b
User & Date: js on 2013-08-01 23:07:24
Other Links: manifest | tags
Context
2013-08-03
10:35
Adjust TableGenerator to recent changes. check-in: 57cbfc0144 user: js tags: trunk
2013-08-01
23:07
OFXMLParser: Improve handling of whitespaces. check-in: a69e13fa8d user: js tags: trunk
22:12
OFXMLParser: Fix parsing of <![CDATA[x]]]>. check-in: 66cb66e6d8 user: js tags: trunk
Changes

Modified src/OFXMLAttribute.m from [476d95eb23] to [37b3db44bd].

178
179
180
181
182
183
184
185

186
187
188
189
178
179
180
181
182
183
184

185
186
187
188
189







-
+




	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}

- (OFString*)description
{
	return [OFString stringWithFormat: @"<OFXMLAttribute, name=%@, "
	return [OFString stringWithFormat: @"<OFXMLAttribute: name=%@, "
					   @"namespace=%@, stringValue=%@>",
					   _name, _namespace, _stringValue];
}
@end

Modified src/OFXMLParser.h from [4fa33b0da4] to [f7e0b1e32e].

130
131
132
133
134
135
136
137
138
139
140
141






142
143
144
145
146
147
148
130
131
132
133
134
135
136





137
138
139
140
141
142
143
144
145
146
147
148
149







-
-
-
-
-
+
+
+
+
+
+







		OF_XMLPARSER_IN_BYTE_ORDER_MARK,
		OF_XMLPARSER_OUTSIDE_TAG,
		OF_XMLPARSER_TAG_OPENED,
		OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS,
		OF_XMLPARSER_IN_TAG_NAME,
		OF_XMLPARSER_IN_CLOSE_TAG_NAME,
		OF_XMLPARSER_IN_TAG,
		OF_XMLPARSER_IN_ATTR_NAME,
		OF_XMLPARSER_EXPECT_DELIMITER,
		OF_XMLPARSER_IN_ATTR_VALUE,
		OF_XMLPARSER_EXPECT_CLOSE,
		OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE,
		OF_XMLPARSER_IN_ATTRIBUTE_NAME,
		OF_XMLPARSER_EXPECT_ATTRIBUTE_EQUAL_SIGN,
		OF_XMLPARSER_EXPECT_ATTRIBUTE_DELIMITER,
		OF_XMLPARSER_IN_ATTRIBUTE_VALUE,
		OF_XMLPARSER_EXPECT_TAG_CLOSE,
		OF_XMLPARSER_EXPECT_SPACE_OR_TAG_CLOSE,
		OF_XMLPARSER_IN_EXCLAMATIONMARK,
		OF_XMLPARSER_IN_CDATA_OPENING,
		OF_XMLPARSER_IN_CDATA,
		OF_XMLPARSER_IN_COMMENT_OPENING,
		OF_XMLPARSER_IN_COMMENT_1,
		OF_XMLPARSER_IN_COMMENT_2,
		OF_XMLPARSER_IN_DOCTYPE,

Modified src/OFXMLParser.m from [a08464f480] to [86a5942568].

144
145
146
147
148
149
150
151


152
153
154


155
156
157
158
159
160
161
144
145
146
147
148
149
150

151
152
153


154
155
156
157
158
159
160
161
162







-
+
+

-
-
+
+







		@selector(OF_outsideTagState),
		@selector(OF_tagOpenedState),
		@selector(OF_inProcessingInstructionsState),
		@selector(OF_inTagNameState),
		@selector(OF_inCloseTagNameState),
		@selector(OF_inTagState),
		@selector(OF_inAttributeNameState),
		@selector(OF_expectDelimiterState),
		@selector(OF_expectAttributeEqualSignState),
		@selector(OF_expectAttributeDelimiterState),
		@selector(OF_inAttributeValueState),
		@selector(OF_expectCloseState),
		@selector(OF_expectSpaceOrCloseState),
		@selector(OF_expectTagCloseState),
		@selector(OF_expectSpaceOrTagCloseState),
		@selector(OF_inExclamationMarkState),
		@selector(OF_inCDATAOpeningState),
		@selector(OF_inCDATAState),
		@selector(OF_inCommentOpeningState),
		@selector(OF_inCommentState1),
		@selector(OF_inCommentState2),
		@selector(OF_inDOCTYPEState)
602
603
604
605
606
607
608
609

610
611
612
613
614
615
616
603
604
605
606
607
608
609

610
611
612
613
614
615
616
617







-
+







			[_previous addObject: bufferString];

		[_name release];
		[_prefix release];
		_name = _prefix = nil;

		_state = (_data[_i] == '/'
		    ? OF_XMLPARSER_EXPECT_CLOSE
		    ? OF_XMLPARSER_EXPECT_TAG_CLOSE
		    : OF_XMLPARSER_OUTSIDE_TAG);
	} else
		_state = OF_XMLPARSER_IN_TAG;

	if (_data[_i] != '/')
		[_namespaces addObject: [OFMutableDictionary dictionary]];

680
681
682
683
684
685
686
687

688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705

706
707
708
709
710
711
712
681
682
683
684
685
686
687

688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705

706
707
708
709
710
711
712
713







-
+

















-
+







	[_name release];
	[_prefix release];
	_name = _prefix = nil;

	_last = _i + 1;
	_state = (_data[_i] == '>'
	    ? OF_XMLPARSER_OUTSIDE_TAG
	    : OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE);
	    : OF_XMLPARSER_EXPECT_SPACE_OR_TAG_CLOSE);

	if ([_previous count] == 0)
		_finishedParsing = true;
}

/* Inside a tag, name found */
- (void)OF_inTagState
{
	void *pool;
	OFString *namespace;
	OFXMLAttribute **attributesObjects;
	size_t j, attributesCount;

	if (_data[_i] != '>' && _data[_i] != '/') {
		if (_data[_i] != ' ' && _data[_i] != '\t' &&
		    _data[_i] != '\n' && _data[_i] != '\r') {
			_last = _i;
			_state = OF_XMLPARSER_IN_ATTR_NAME;
			_state = OF_XMLPARSER_IN_ATTRIBUTE_NAME;
			_i--;
		}

		return;
	}

	attributesObjects = [_attributes objects];
756
757
758
759
760
761
762
763

764
765
766
767
768
769
770
771

772
773
774
775


776
777
778
779
780
781
782
783
784


785
786
787
788
789
790
791
792
793
794
757
758
759
760
761
762
763

764
765
766
767
768
769
770
771

772
773
774
775

776
777
778
779
780
781
782
783
784


785
786



787
788
789
790
791
792
793







-
+







-
+



-
+
+







-
-
+
+
-
-
-







	[_name release];
	[_prefix release];
	[_attributes removeAllObjects];
	_name = _prefix = nil;

	_last = _i + 1;
	_state = (_data[_i] == '/'
	    ? OF_XMLPARSER_EXPECT_CLOSE
	    ? OF_XMLPARSER_EXPECT_TAG_CLOSE
	    : OF_XMLPARSER_OUTSIDE_TAG);
}

/* Looking for attribute name */
- (void)OF_inAttributeNameState
{
	void *pool;
	OFMutableString *bufferString;
	OFString *bufferString;
	const char *bufferCString, *tmp;
	size_t length, bufferLength;

	if (_data[_i] != '=')
	if (_data[_i] != '=' && _data[_i] != ' ' && _data[_i] != '\t' &&
	    _data[_i] != '\n' && _data[_i] != '\r')
		return;

	if ((length = _i - _last) > 0)
		buffer_append(_buffer, _data + _last, _encoding, length);

	pool = objc_autoreleasePoolPush();

	bufferString = [OFMutableString stringWithUTF8String: [_buffer items]
						      length: [_buffer count]];
	bufferString = [OFString stringWithUTF8String: [_buffer items]
					       length: [_buffer count]];
	[bufferString deleteEnclosingWhitespaces];
	/* Prevent a useless copy later */
	[bufferString makeImmutable];

	bufferCString = [bufferString UTF8String];
	bufferLength = [bufferString UTF8StringLength];

	if ((tmp = memchr(bufferCString, ':', bufferLength)) != NULL) {
		_attributeName = [[OFString alloc]
		    initWithUTF8String: tmp + 1
803
804
805
806
807
808
809










810
811



812





813
814


815
816
817
818
819
820
821
822
823
824
825
826

827
828
829
830
831
832
833
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818


819
820
821
822
823
824
825
826
827


828
829
830
831
832
833
834
835
836
837
838
839
840

841
842
843
844
845
846
847
848







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

+
+
+
+
+
-
-
+
+











-
+







	}

	objc_autoreleasePoolPop(pool);

	[_buffer removeAllItems];

	_last = _i + 1;
	_state = (_data[_i] == '='
	    ? OF_XMLPARSER_EXPECT_ATTRIBUTE_DELIMITER
	    : OF_XMLPARSER_EXPECT_ATTRIBUTE_EQUAL_SIGN);
}

/* Expecting equal sign of an attribute */
- (void)OF_expectAttributeEqualSignState
{
	if (_data[_i] == '=') {
		_last = _i + 1;
	_state = OF_XMLPARSER_EXPECT_DELIMITER;
}
		_state = OF_XMLPARSER_EXPECT_ATTRIBUTE_DELIMITER;
		return;
	}

	if (_data[_i] != ' ' && _data[_i] != '\t' && _data[_i] != '\n' &&
	    _data[_i] != '\r')
		@throw [OFMalformedXMLException exceptionWithParser: self];
}

/* Expecting delimiter */
- (void)OF_expectDelimiterState
/* Expecting name/value delimiter of an attribute */
- (void)OF_expectAttributeDelimiterState
{
	_last = _i + 1;

	if (_data[_i] == ' ' || _data[_i] == '\t' || _data[_i] == '\n' ||
	    _data[_i] == '\r')
		return;

	if (_data[_i] != '\'' && _data[_i] != '"')
		@throw [OFMalformedXMLException exceptionWithParser: self];

	_delimiter = _data[_i];
	_state = OF_XMLPARSER_IN_ATTR_VALUE;
	_state = OF_XMLPARSER_IN_ATTRIBUTE_VALUE;
}

/* Looking for attribute value */
- (void)OF_inAttributeValueState
{
	void *pool;
	OFString *attributeValue;
862
863
864
865
866
867
868
869

870
871
872
873
874
875
876
877
878
879

880
881
882
883
884
885
886
877
878
879
880
881
882
883

884
885
886
887
888
889
890
891
892
893

894
895
896
897
898
899
900
901







-
+









-
+







	_attributeName = _attributePrefix = nil;

	_last = _i + 1;
	_state = OF_XMLPARSER_IN_TAG;
}

/* Expecting closing '>' */
- (void)OF_expectCloseState
- (void)OF_expectTagCloseState
{
	if (_data[_i] == '>') {
		_last = _i + 1;
		_state = OF_XMLPARSER_OUTSIDE_TAG;
	} else
		@throw [OFMalformedXMLException exceptionWithParser: self];
}

/* Expecting closing '>' or space */
- (void)OF_expectSpaceOrCloseState
- (void)OF_expectSpaceOrTagCloseState
{
	if (_data[_i] == '>') {
		_last = _i + 1;
		_state = OF_XMLPARSER_OUTSIDE_TAG;
	} else if (_data[_i] != ' ' && _data[_i] != '\t' &&
	    _data[_i] != '\n' && _data[_i] != '\r')
		@throw [OFMalformedXMLException exceptionWithParser: self];