ObjFW  Check-in [f40092db22]

Overview
Comment:OFXMLParser: Allow comments after the document root.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f40092db228e266a96f9a89ec46a19a09b1e27f62c36dbbe3caeaf58857b6bf3
User & Date: js on 2010-12-20 15:51:33
Other Links: manifest | tags
Context
2010-12-20
15:55
Extend OFXMLElementBuilderDelegate. check-in: 976f115da9 user: js tags: trunk
15:51
OFXMLParser: Allow comments after the document root. check-in: f40092db22 user: js tags: trunk
15:12
Documentation improvements. check-in: bf836060fb user: js tags: trunk
Changes

Modified src/OFXMLParser.m from [d446a92ae5] to [e8e4fcea92].

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
194
195
196
197
198
199
200










201
202
203
204
205
206
207







-
-
-
-
-
-
-
-
-
-







}

- (void)parseBuffer: (const char*)buf
	   withSize: (size_t)size
{
	size_t i, last = 0;

	if (finishedParsing) {
		for (i = 0; i < size; i++)
			if (buf[i] != ' ' && buf[i] != '\t' &&
			    buf[i] != '\n' && buf[i] != '\r')
				@throw [OFMalformedXMLException
				    newWithClass: isa];

		return;
	}

	for (i = 0; i < size; i++) {
		size_t j = i;

		lookup_table[state](self, selectors[state], buf, &i, &last);

		/* Ensure we don't count this character twice */
		if (i != j)
273
274
275
276
277
278
279




280
281
282
283
284
285
286
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280







+
+
+
+







/* Not in a tag */
- (void)_parseOutsideTagWithBuffer: (const char*)buf
				 i: (size_t*)i
			      last: (size_t*)last
{
	size_t len;

	if (finishedParsing && buf[*i] != ' ' && buf[*i] != '\t' &&
	    buf[*i] != '\n' && buf[*i] != '\r' && buf[*i] != '<')
		@throw [OFMalformedXMLException newWithClass: isa];

	if (buf[*i] != '<')
		return;

	if ((len = *i - *last) > 0)
		[cache appendCStringWithoutUTF8Checking: buf + *last
						 length: len];

309
310
311
312
313
314
315



316
317
318
319
320
321
322
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319







+
+
+







}

/* Tag was just opened */
- (void)_parseTagOpenedWithBuffer: (const char*)buf
				i: (size_t*)i
			     last: (size_t*)last
{
	if (finishedParsing && buf[*i] != '!')
		@throw [OFMalformedXMLException newWithClass: isa];

	switch (buf[*i]) {
		case '?':
			*last = *i + 1;
			state = OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS;
			level = 0;
			break;
		case '/':
734
735
736
737
738
739
740



741
742
743
744
745
746
747
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747







+
+
+







}

/* In <! */
- (void)_parseInExclamationMarkWithBuffer: (const char*)buf
					i: (size_t*)i
				     last: (size_t*)last
{
	if (finishedParsing && buf[*i] != '-')
		@throw [OFMalformedXMLException newWithClass: isa];

	if (buf[*i] == '-')
		state = OF_XMLPARSER_IN_COMMENT_OPENING;
	else if (buf[*i] == '[') {
		state = OF_XMLPARSER_IN_CDATA_OPENING;
		level = 0;
	} else if (buf[*i] == 'D') {
		state = OF_XMLPARSER_IN_DOCTYPE;

Modified tests/OFXMLParserTests.m from [542c5c5171] to [b0b9d9cd30].

358
359
360
361
362
363
364



365

366



367
368
369
370
358
359
360
361
362
363
364
365
366
367

368
369
370
371
372
373
374
375
376







+
+
+
-
+

+
+
+




	    i == 32 && [parser lineNumber] == 18)

	TEST(@"-[finishedParsing]", [parser finishedParsing])

	TEST(@"Parsing whitespaces after the document",
	    R([parser parseString: @" \t\r\n "]))

	TEST(@"Parsing comments after the document",
	    R([parser parseString: @" \t<!-- foo -->\r<!--bar-->\n "]))

	EXPECT_EXCEPTION(@"Detection of junk after the document",
	EXPECT_EXCEPTION(@"Detection of junk after the document #1",
	    OFMalformedXMLException, [parser parseString: @"a"])

	EXPECT_EXCEPTION(@"Detection of junk after the document #2",
	    OFMalformedXMLException, [parser parseString: @"<!["])

	[pool drain];
}
@end