ObjFW  Diff

Differences From Artifact [cfc14f4098]:

To Artifact [e1f46dcc8c]:


276
277
278
279
280
281
282
283

284
285
286
287
288
289
290
				 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];







|
>







276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
				 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
						      parser: self];

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

	if ((len = *i - *last) > 0)
		[cache appendCStringWithoutUTF8Checking: buf + *last
						 length: len];
315
316
317
318
319
320
321
322

323
324
325
326
327
328
329

/* 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;







|
>







316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331

/* 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
						      parser: self];

	switch (buf[*i]) {
		case '?':
			*last = *i + 1;
			state = OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS;
			level = 0;
			break;
501
502
503
504
505
506
507
508

509
510
511
512
513
514
515
						    length: tmp - cache_c];
	} else {
		name = [cache copy];
		prefix = nil;
	}

	if (![[previous lastObject] isEqual: cache])
		@throw [OFMalformedXMLException newWithClass: isa];


	[previous removeNObjects: 1];

	[cache setToCString: ""];

	ns = namespace_for_prefix(prefix, namespaces);
	if (prefix != nil && ns == nil)







|
>







503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
						    length: tmp - cache_c];
	} else {
		name = [cache copy];
		prefix = nil;
	}

	if (![[previous lastObject] isEqual: cache])
		@throw [OFMalformedXMLException newWithClass: isa
						      parser: self];

	[previous removeNObjects: 1];

	[cache setToCString: ""];

	ns = namespace_for_prefix(prefix, namespaces);
	if (prefix != nil && ns == nil)
668
669
670
671
672
673
674
675

676
677
678
679
680
681
682
	*last = *i + 1;

	if (buf[*i] == ' ' || buf[*i] == '\t' || buf[*i] == '\n' ||
	    buf[*i] == '\r')
		return;

	if (buf[*i] != '\'' && buf[*i] != '"')
		@throw [OFMalformedXMLException newWithClass: isa];


	delim = buf[*i];
	state = OF_XMLPARSER_IN_ATTR_VALUE;
}

/* Looking for attribute value */
- (void)_parseInAttributeValueWithBuffer: (const char*)buf







|
>







671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
	*last = *i + 1;

	if (buf[*i] == ' ' || buf[*i] == '\t' || buf[*i] == '\n' ||
	    buf[*i] == '\r')
		return;

	if (buf[*i] != '\'' && buf[*i] != '"')
		@throw [OFMalformedXMLException newWithClass: isa
						      parser: self];

	delim = buf[*i];
	state = OF_XMLPARSER_IN_ATTR_VALUE;
}

/* Looking for attribute value */
- (void)_parseInAttributeValueWithBuffer: (const char*)buf
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
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
				  i: (size_t*)i
			       last: (size_t*)last
{
	if (buf[*i] == '>') {
		*last = *i + 1;
		state = OF_XMLPARSER_OUTSIDE_TAG;
	} else
		@throw [OFMalformedXMLException newWithClass: isa];

}

/* Expecting closing '>' or space */
- (void)_parseExpectSpaceOrCloseWithBuffer: (const char*)buf
					 i: (size_t*)i
				      last: (size_t*)last
{
	if (buf[*i] == '>') {
		*last = *i + 1;
		state = OF_XMLPARSER_OUTSIDE_TAG;
	} else if (buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' &&
	    buf[*i] != '\r')
		@throw [OFMalformedXMLException newWithClass: isa];

}

/* 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;
		level = 0;
	} else
		@throw [OFMalformedXMLException newWithClass: isa];


	*last = *i + 1;
}

/* CDATA */
- (void)_parseInCDATAOpeningWithBuffer: (const char*)buf
				     i: (size_t*)i
				  last: (size_t*)last
{
	if (buf[*i] != "CDATA["[level])
		@throw [OFMalformedXMLException newWithClass: isa];


	if (++level == 6) {
		state = OF_XMLPARSER_IN_CDATA_1;
		level = 0;
	}

	*last = *i + 1;







|
>












|
>








|
>










|
>










|
>







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
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
				  i: (size_t*)i
			       last: (size_t*)last
{
	if (buf[*i] == '>') {
		*last = *i + 1;
		state = OF_XMLPARSER_OUTSIDE_TAG;
	} else
		@throw [OFMalformedXMLException newWithClass: isa
						      parser: self];
}

/* Expecting closing '>' or space */
- (void)_parseExpectSpaceOrCloseWithBuffer: (const char*)buf
					 i: (size_t*)i
				      last: (size_t*)last
{
	if (buf[*i] == '>') {
		*last = *i + 1;
		state = OF_XMLPARSER_OUTSIDE_TAG;
	} else if (buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' &&
	    buf[*i] != '\r')
		@throw [OFMalformedXMLException newWithClass: isa
						      parser: self];
}

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

	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;
		level = 0;
	} else
		@throw [OFMalformedXMLException newWithClass: isa
						      parser: self];

	*last = *i + 1;
}

/* CDATA */
- (void)_parseInCDATAOpeningWithBuffer: (const char*)buf
				     i: (size_t*)i
				  last: (size_t*)last
{
	if (buf[*i] != "CDATA["[level])
		@throw [OFMalformedXMLException newWithClass: isa
						      parser: self];

	if (++level == 6) {
		state = OF_XMLPARSER_IN_CDATA_1;
		level = 0;
	}

	*last = *i + 1;
848
849
850
851
852
853
854
855

856
857
858
859
860
861
862

/* Comment */
- (void)_parseInCommentOpeningWithBuffer: (const char*)buf
				       i: (size_t*)i
				    last: (size_t*)last
{
	if (buf[*i] != '-')
		@throw [OFMalformedXMLException newWithClass: isa];


	*last = *i + 1;
	state = OF_XMLPARSER_IN_COMMENT_1;
	level = 0;
}

- (void)_parseInComment1WithBuffer: (const char*)buf







|
>







857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872

/* Comment */
- (void)_parseInCommentOpeningWithBuffer: (const char*)buf
				       i: (size_t*)i
				    last: (size_t*)last
{
	if (buf[*i] != '-')
		@throw [OFMalformedXMLException newWithClass: isa
						      parser: self];

	*last = *i + 1;
	state = OF_XMLPARSER_IN_COMMENT_1;
	level = 0;
}

- (void)_parseInComment1WithBuffer: (const char*)buf
877
878
879
880
881
882
883
884

885
886
887
888
889
890
891
			      last: (size_t*)last
{
	OFAutoreleasePool *pool;
	OFMutableString *comment;
	size_t len;

	if (buf[*i] != '>')
		@throw [OFMalformedXMLException newWithClass: isa];


	pool = [[OFAutoreleasePool alloc] init];

	[cache appendCStringWithoutUTF8Checking: buf + *last
					 length: *i - *last];
	comment = [[cache mutableCopy] autorelease];
	len = [comment length];







|
>







887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
			      last: (size_t*)last
{
	OFAutoreleasePool *pool;
	OFMutableString *comment;
	size_t len;

	if (buf[*i] != '>')
		@throw [OFMalformedXMLException newWithClass: isa
						      parser: self];

	pool = [[OFAutoreleasePool alloc] init];

	[cache appendCStringWithoutUTF8Checking: buf + *last
					 length: *i - *last];
	comment = [[cache mutableCopy] autorelease];
	len = [comment length];
920
921
922
923
924
925
926
927

928
929
930
931
932
933
934
- (void)_parseInDoctypeWithBuffer: (const char*)buf
				i: (size_t*)i
			     last: (size_t*)last
{
	if ((level < 6 && buf[*i] != "OCTYPE"[level]) ||
	    (level == 6 && buf[*i] != ' ' && buf[*i] != '\t' &&
	    buf[*i] != '\n' && buf[*i] != '\r'))
		@throw [OFMalformedXMLException newWithClass: isa];


	if (level < 7 || buf[*i] == '<')
		level++;

	if (buf[*i] == '>') {
		if (level == 7)
			state = OF_XMLPARSER_OUTSIDE_TAG;







|
>







931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
- (void)_parseInDoctypeWithBuffer: (const char*)buf
				i: (size_t*)i
			     last: (size_t*)last
{
	if ((level < 6 && buf[*i] != "OCTYPE"[level]) ||
	    (level == 6 && buf[*i] != ' ' && buf[*i] != '\t' &&
	    buf[*i] != '\n' && buf[*i] != '\r'))
		@throw [OFMalformedXMLException newWithClass: isa
						      parser: self];

	if (level < 7 || buf[*i] == '<')
		level++;

	if (buf[*i] == '>') {
		if (level == 7)
			state = OF_XMLPARSER_OUTSIDE_TAG;