ObjFW  Diff

Differences From Artifact [08bf6cc4f2]:

To Artifact [e395ba83dc]:


90
91
92
93
94
95
96
97

98
99
100
101
102
103
104

105
106
107
108
109
110
111
112
90
91
92
93
94
95
96

97

98
99
100
101
102

103

104
105
106
107
108
109
110







-
+
-





-
+
-







};

static OF_INLINE void
appendToBuffer(OFMutableData *buffer, const char *string,
    of_string_encoding_t encoding, size_t length)
{
	if OF_LIKELY(encoding == OF_STRING_ENCODING_UTF_8)
		[buffer addItems: string
		[buffer addItems: string count: length];
			   count: length];
	else {
		void *pool = objc_autoreleasePoolPush();
		OFString *tmp = [OFString stringWithCString: string
						   encoding: encoding
						     length: length];
		[buffer addItems: tmp.UTF8String
		[buffer addItems: tmp.UTF8String count: tmp.UTF8StringLength];
			   count: tmp.UTF8StringLength];
		objc_autoreleasePoolPop(pool);
	}
}

static OFString *
transformString(OFXMLParser *parser, OFMutableData *buffer, size_t cut,
    bool unescape)
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
124
125
126
127
128
129
130

131

132
133
134
135
136
137
138







-
+
-







				length--;
			} else
				items[i] = '\n';
		} else if (items[i] == '&')
			hasEntities = true;
	}

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

	if (unescape && hasEntities) {
		@try {
			return [ret stringByXMLUnescapingWithDelegate: parser];
		} @catch (OFInvalidFormatException *e) {
			@throw [OFMalformedXMLException
			    exceptionWithParser: parser];
236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251
233
234
235
236
237
238
239

240

241
242
243
244
245
246
247







-
+
-







	[_attributeName release];
	[_attributePrefix release];
	[_previous release];

	[super dealloc];
}

- (void)parseBuffer: (const char *)buffer
- (void)parseBuffer: (const char *)buffer length: (size_t)length
	     length: (size_t)length
{
	_data = buffer;

	for (_i = _last = 0; _i < length; _i++) {
		size_t j = _i;

		lookupTable[_state](self);
265
266
267
268
269
270
271
272

273
274
275
276
277
278
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
261
262
263
264
265
266
267

268

269
270
271
272
273
274
275
276
277
278
279


280

281
282
283
284
285
286
287







-
+
-











-
-
+
-







	if (length - _last > 0 && _state != OF_XMLPARSER_IN_TAG)
		appendToBuffer(_buffer, _data + _last, _encoding,
		    length - _last);
}

- (void)parseString: (OFString *)string
{
	[self parseBuffer: string.UTF8String
	[self parseBuffer: string.UTF8String length: string.UTF8StringLength];
		   length: string.UTF8StringLength];
}

- (void)parseStream: (OFStream *)stream
{
	size_t pageSize = [OFSystemInfo pageSize];
	char *buffer = of_alloc(1, pageSize);

	@try {
		while (!stream.atEndOfStream) {
			size_t length = [stream readIntoBuffer: buffer
							length: pageSize];

			[self parseBuffer: buffer
			[self parseBuffer: buffer length: length];
				   length: length];
		}
	} @finally {
		free(buffer);
	}
}

static void
499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
492
493
494
495
496
497
498

499
500
501
502
503
504
505
506







-
+







		    [PI hasPrefix: @"xml\n"])
			if (!parseXMLProcessingInstructions(self, PI))
				@throw [OFMalformedXMLException
				    exceptionWithParser: self];

		if ([self->_delegate respondsToSelector:
		    @selector(parser:foundProcessingInstructions:)])
			[self->_delegate	 parser: self
			[self->_delegate parser: self
			    foundProcessingInstructions: PI];

		objc_autoreleasePoolPop(pool);

		[self->_buffer removeAllItems];

		self->_last = self->_i + 1;
953
954
955
956
957
958
959
960

961
962
963
964
965
966
967
968
946
947
948
949
950
951
952

953

954
955
956
957
958
959
960







-
+
-








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

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

		objc_autoreleasePoolPop(pool);

		[self->_buffer removeAllItems];

		self->_last = self->_i + 1;
		self->_state = OF_XMLPARSER_OUTSIDE_TAG;
1007
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018
1019
1020
1021
1022
999
1000
1001
1002
1003
1004
1005

1006

1007
1008
1009
1010
1011
1012
1013







-
+
-








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

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

	objc_autoreleasePoolPop(pool);

	[self->_buffer removeAllItems];

	self->_last = self->_i + 1;
	self->_state = OF_XMLPARSER_OUTSIDE_TAG;
1052
1053
1054
1055
1056
1057
1058
1059

1060
1061
1062
1063
1064
1043
1044
1045
1046
1047
1048
1049

1050

1051
1052
1053
1054







-
+
-




}

-	  (OFString *)string: (OFString *)string
  containsUnknownEntityNamed: (OFString *)entity
{
	if ([_delegate respondsToSelector:
	    @selector(parser:foundUnknownEntityNamed:)])
		return [_delegate parser: self
		return [_delegate parser: self foundUnknownEntityNamed: entity];
		 foundUnknownEntityNamed: entity];

	return nil;
}
@end