ObjFW  Diff

Differences From Artifact [4119684e10]:

To Artifact [c329ebfb71]:


112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131

132
133
134
135
136
137
138
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138







-
+











-
+







	}

	return nil;
}

static OF_INLINE void
resolve_attribute_namespace(OFXMLAttribute *attribute, OFArray *namespaces,
    Class isa)
    OFXMLParser *self)
{
	OFString *attributeNS;
	OFString *attributePrefix = attribute->ns;

	if (attributePrefix == nil)
		return;

	attributeNS = namespace_for_prefix(attributePrefix, namespaces);

	if ((attributePrefix != nil && attributeNS == nil))
		@throw [OFUnboundNamespaceException
		    exceptionWithClass: isa
		    exceptionWithClass: [self class]
				prefix: attributePrefix];

	[attribute->ns release];
	attribute->ns = [attributeNS retain];
}

@implementation OFXMLParser
307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
307
308
309
310
311
312
313

314
315
316
317
318
319
320
321







-
+







			      last: (size_t*)last
{
	size_t length;

	if ((finishedParsing || [previous count] < 1) && buffer[*i] != ' ' &&
	    buffer[*i] != '\t' && buffer[*i] != '\n' && buffer[*i] != '\r' &&
	    buffer[*i] != '<')
		@throw [OFMalformedXMLException exceptionWithClass: isa
		@throw [OFMalformedXMLException exceptionWithClass: [self class]
							    parser: self];

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

	if ((length = *i - *last) > 0)
		cache_append(cache, buffer + *last, encoding, length);
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
341
342
343
344
345
346
347

348
349
350
351
352
353
354
355







-
+








/* Tag was just opened */
- (void)_parseTagOpenedWithBuffer: (const char*)buffer
				i: (size_t*)i
			     last: (size_t*)last
{
	if (finishedParsing && buffer[*i] != '!' && buffer[*i] != '?')
		@throw [OFMalformedXMLException exceptionWithClass: isa
		@throw [OFMalformedXMLException exceptionWithClass: [self class]
							    parser: self];

	switch (buffer[*i]) {
	case '?':
		*last = *i + 1;
		state = OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS;
		level = 0;
483
484
485
486
487
488
489
490

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

490
491
492
493
494
495
496
497







-
+







		pi = transform_string(cache, 1, NO, nil);

		if ([pi isEqual: @"xml"] || [pi hasPrefix: @"xml "] ||
		    [pi hasPrefix: @"xml\t"] || [pi hasPrefix: @"xml\r"] ||
		    [pi hasPrefix: @"xml\n"])
			if (![self _parseXMLProcessingInstructions: pi])
				@throw [OFMalformedXMLException
				    exceptionWithClass: isa
				    exceptionWithClass: [self class]
						parser: self];

		[delegate parser: self
		    foundProcessingInstructions: pi];

		[pool release];

543
544
545
546
547
548
549
550

551
552
553
554
555
556
557
543
544
545
546
547
548
549

550
551
552
553
554
555
556
557







-
+







		OFAutoreleasePool *pool2;
		OFString *ns;

		ns = namespace_for_prefix(prefix, namespaces);

		if (prefix != nil && ns == nil)
			@throw [OFUnboundNamespaceException
			    exceptionWithClass: isa
			    exceptionWithClass: [self class]
					prefix: prefix];

		pool2 = [[OFAutoreleasePool alloc] init];

		[delegate parser: self
		 didStartElement: name
		      withPrefix: prefix
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
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







-
+








-
-
+
+
+







				length: tmp - cacheCString];
	} else {
		name = [cacheString copy];
		prefix = nil;
	}

	if (![[previous lastObject] isEqual: cacheString])
		@throw [OFMalformedXMLException exceptionWithClass: isa
		@throw [OFMalformedXMLException exceptionWithClass: [self class]
							    parser: self];

	[previous removeLastObject];

	[cache removeAllItems];

	ns = namespace_for_prefix(prefix, namespaces);
	if (prefix != nil && ns == nil)
		@throw [OFUnboundNamespaceException exceptionWithClass: isa
								prefix: prefix];
		@throw [OFUnboundNamespaceException
		    exceptionWithClass: [self class]
				prefix: prefix];

	[delegate parser: self
	   didEndElement: name
	      withPrefix: prefix
	       namespace: ns];

	[pool release];
687
688
689
690
691
692
693
694
695



696
697
698
699

700
701
702
703
704
705
706
688
689
690
691
692
693
694


695
696
697
698
699
700

701
702
703
704
705
706
707
708







-
-
+
+
+



-
+








	attributesObjects = [attributes objects];
	attributesCount = [attributes count];

	ns = namespace_for_prefix(prefix, namespaces);

	if (prefix != nil && ns == nil)
		@throw [OFUnboundNamespaceException exceptionWithClass: isa
								prefix: prefix];
		@throw [OFUnboundNamespaceException
		    exceptionWithClass: [self class]
				prefix: prefix];

	for (j = 0; j < attributesCount; j++)
		resolve_attribute_namespace(attributesObjects[j], namespaces,
		    isa);
		    self);

	pool = [[OFAutoreleasePool alloc] init];

	[delegate parser: self
	 didStartElement: name
	      withPrefix: prefix
	       namespace: ns
791
792
793
794
795
796
797
798

799
800
801
802
803
804
805
793
794
795
796
797
798
799

800
801
802
803
804
805
806
807







-
+







	*last = *i + 1;

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

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

	delimiter = buffer[*i];
	state = OF_XMLPARSER_IN_ATTR_VALUE;
}

/* Looking for attribute value */
848
849
850
851
852
853
854
855

856
857
858
859
860
861
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
887
888
889
890
891

892
893
894
895
896
897
898
899
900
901
902
903

904
905
906
907
908
909
910
850
851
852
853
854
855
856

857
858
859
860
861
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
887
888
889
890
891
892

893
894
895
896
897
898
899
900
901
902
903
904

905
906
907
908
909
910
911
912







-
+













-
+









-
+











-
+











-
+







				  i: (size_t*)i
			       last: (size_t*)last
{
	if (buffer[*i] == '>') {
		*last = *i + 1;
		state = OF_XMLPARSER_OUTSIDE_TAG;
	} else
		@throw [OFMalformedXMLException exceptionWithClass: isa
		@throw [OFMalformedXMLException exceptionWithClass: [self class]
							    parser: self];
}

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

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

	if (buffer[*i] == '-')
		state = OF_XMLPARSER_IN_COMMENT_OPENING;
	else if (buffer[*i] == '[') {
		state = OF_XMLPARSER_IN_CDATA_OPENING;
		level = 0;
	} else if (buffer[*i] == 'D') {
		state = OF_XMLPARSER_IN_DOCTYPE;
		level = 0;
	} else
		@throw [OFMalformedXMLException exceptionWithClass: isa
		@throw [OFMalformedXMLException exceptionWithClass: [self class]
							    parser: self];

	*last = *i + 1;
}

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

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

956
957
958
959
960
961
962
963

964
965
966
967
968
969
970
958
959
960
961
962
963
964

965
966
967
968
969
970
971
972







-
+








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

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

985
986
987
988
989
990
991
992

993
994
995
996
997
998
999
987
988
989
990
991
992
993

994
995
996
997
998
999
1000
1001







-
+







				 i: (size_t*)i
			      last: (size_t*)last
{
	OFAutoreleasePool *pool;
	OFString *comment;

	if (buffer[*i] != '>')
		@throw [OFMalformedXMLException exceptionWithClass: isa
		@throw [OFMalformedXMLException exceptionWithClass: [self class]
							    parser: self];

	pool = [[OFAutoreleasePool alloc] init];

	cache_append(cache, buffer + *last, encoding, *i - *last);
	comment = transform_string(cache, 2, NO, nil);

1012
1013
1014
1015
1016
1017
1018
1019

1020
1021
1022
1023
1024
1025
1026
1014
1015
1016
1017
1018
1019
1020

1021
1022
1023
1024
1025
1026
1027
1028







-
+







- (void)_parseInDoctypeWithBuffer: (const char*)buffer
				i: (size_t*)i
			     last: (size_t*)last
{
	if ((level < 6 && buffer[*i] != "OCTYPE"[level]) ||
	    (level == 6 && buffer[*i] != ' ' && buffer[*i] != '\t' &&
	    buffer[*i] != '\n' && buffer[*i] != '\r'))
		@throw [OFMalformedXMLException exceptionWithClass: isa
		@throw [OFMalformedXMLException exceptionWithClass: [self class]
							    parser: self];

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

	if (buffer[*i] == '>') {
		if (level == 7)