ObjFW  Diff

Differences From Artifact [006e6e5905]:

  • File src/OFXMLParser.m — part of check-in [13ee56edf3] at 2014-06-21 21:43:43 on branch trunk — Move all macros from OFObject.h to macros.h

    This means that OFObject.h imports macros.h now, making it unnecessary
    to manually import macros.h in almost every file. And while at it, also
    import autorelease.h in OFObject.h, so that this doesn't need to be
    manually imported in almost every file as well. (user: js, size: 24323) [annotate] [blame] [check-ins using]

To Artifact [7ca3cc1d6a]:


29
30
31
32
33
34
35

36
37
38
39
40
41
42
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43







+







#import "OFStream.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#endif
#import "OFSystemInfo.h"

#import "OFInitializationFailedException.h"
#import "OFInvalidFormatException.h"
#import "OFMalformedXMLException.h"
#import "OFUnboundPrefixException.h"

typedef void (*state_function_t)(id, SEL);
static SEL selectors[OF_XMLPARSER_NUM_STATES];
static state_function_t lookupTable[OF_XMLPARSER_NUM_STATES];

55
56
57
58
59
60
61
62
63


64
65
66
67
68
69
70
56
57
58
59
60
61
62


63
64
65
66
67
68
69
70
71







-
-
+
+







		[buffer addItems: [tmp UTF8String]
			   count: [tmp UTF8StringLength]];
		objc_autoreleasePoolPop(pool);
	}
}

static OFString*
transformString(OFDataArray *buffer, size_t cut, bool unescape,
    id <OFStringXMLUnescapingDelegate> delegate)
transformString(OFXMLParser *parser, OFDataArray *buffer, size_t cut,
    bool unescape)
{
	char *items;
	size_t i, length;
	bool hasEntities = false;
	OFString *ret;

	items = [buffer items];
83
84
85
86
87
88
89
90
91








92
93
94
95
96
97
98
84
85
86
87
88
89
90


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105







-
-
+
+
+
+
+
+
+
+







		} else if (items[i] == '&')
			hasEntities = true;
	}

	ret = [OFString stringWithUTF8String: items
				      length: length];

	if (unescape && hasEntities)
		return [ret stringByXMLUnescapingWithDelegate: delegate];
	if (unescape && hasEntities) {
		@try {
			return [ret stringByXMLUnescapingWithDelegate: parser];
		} @catch (OFInvalidFormatException *e) {
			@throw [OFMalformedXMLException
			    exceptionWithParser: parser];
		}
	}

	return ret;
}

static OFString*
namespaceForPrefix(OFString *prefix, OFArray *namespaces)
{
347
348
349
350
351
352
353
354

355
356
357
358
359
360
361
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368







-
+







		return;

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

	if ([_buffer count] > 0) {
		void *pool = objc_autoreleasePoolPush();
		OFString *characters = transformString(_buffer, 0, true, self);
		OFString *characters = transformString(self, _buffer, 0, true);

		if ([_delegate respondsToSelector:
		    @selector(parser:foundCharacters:)])
			[_delegate parser: self
			  foundCharacters: characters];

		objc_autoreleasePoolPop(pool);
509
510
511
512
513
514
515
516

517
518
519
520
521
522
523
516
517
518
519
520
521
522

523
524
525
526
527
528
529
530







-
+







	if (_data[_i] == '?')
		_level = 1;
	else if (_level == 1 && _data[_i] == '>') {
		void *pool = objc_autoreleasePoolPush();
		OFString *PI;

		appendToBuffer(_buffer, _data + _last, _encoding, _i - _last);
		PI = transformString(_buffer, 1, false, nil);
		PI = transformString(self, _buffer, 1, false);

		if ([PI isEqual: @"xml"] || [PI hasPrefix: @"xml "] ||
		    [PI hasPrefix: @"xml\t"] || [PI hasPrefix: @"xml\r"] ||
		    [PI hasPrefix: @"xml\n"])
			if (![self OF_parseXMLProcessingInstructions: PI])
				@throw [OFMalformedXMLException
				    exceptionWithParser: self];
852
853
854
855
856
857
858
859

860
861
862
863
864
865
866
859
860
861
862
863
864
865

866
867
868
869
870
871
872
873







-
+







	if (_data[_i] != _delimiter)
		return;

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

	pool = objc_autoreleasePoolPush();
	attributeValue = transformString(_buffer, 0, true, self);
	attributeValue = transformString(self, _buffer, 0, true);

	if (_attributePrefix == nil && [_attributeName isEqual: @"xmlns"])
		[[_namespaces lastObject] setObject: attributeValue
					     forKey: @""];
	if ([_attributePrefix isEqual: @"xmlns"])
		[[_namespaces lastObject] setObject: attributeValue
					     forKey: _attributeName];
942
943
944
945
946
947
948
949

950
951
952
953
954
955
956
949
950
951
952
953
954
955

956
957
958
959
960
961
962
963







-
+







	if (_data[_i] == ']')
		_level++;
	else if (_data[_i] == '>' && _level >= 2) {
		void *pool = objc_autoreleasePoolPush();
		OFString *CDATA;

		appendToBuffer(_buffer, _data + _last, _encoding, _i - _last);
		CDATA = transformString(_buffer, 2, false, nil);
		CDATA = transformString(self, _buffer, 2, false);

		if ([_delegate respondsToSelector:
		    @selector(parser:foundCDATA:)])
			[_delegate parser: self
			       foundCDATA: CDATA];

		objc_autoreleasePoolPop(pool);
992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004
1005
1006
999
1000
1001
1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
1013







-
+








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

	pool = objc_autoreleasePoolPush();

	appendToBuffer(_buffer, _data + _last, _encoding, _i - _last);
	comment = transformString(_buffer, 2, false, nil);
	comment = transformString(self, _buffer, 2, false);

	if ([_delegate respondsToSelector: @selector(parser:foundComment:)])
		[_delegate parser: self
		     foundComment: comment];

	objc_autoreleasePoolPop(pool);