ObjFW  Check-in [9975294bb1]

Overview
Comment:Remove blocks support in OFXMLParser as it was useless.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9975294bb11f600ef38352e9c1f91a8ebe36cb55d6119d43eb0d22c5e0bbc3b8
User & Date: js on 2011-09-11 00:09:21
Other Links: manifest | tags
Context
2011-09-11
01:28
Fix ObjC++. check-in: f786163cf8 user: js tags: trunk
00:09
Remove blocks support in OFXMLParser as it was useless. check-in: 9975294bb1 user: js tags: trunk
00:06
Fix missing @try. check-in: 6f18cbc1ea user: js tags: trunk
Changes

Modified src/OFXMLParser.h from [dcec4d0e65] to [7d8e91b03c].

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

@class OFXMLParser;
@class OFArray;
@class OFMutableArray;
@class OFDataArray;
@class OFStream;

#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
typedef void (^of_xml_parser_processing_instructions_block_t)(
    OFXMLParser *parser, OFString *pi);
typedef void (^of_xml_parser_element_start_block_t)(OFXMLParser *parser,
    OFString *name, OFString *prefix, OFString *ns, OFArray *attributes);
typedef void (^of_xml_parser_element_end_block_t)(OFXMLParser *parser,
    OFString *name, OFString *prefix, OFString *ns);
typedef void (^of_xml_parser_string_block_t)(OFXMLParser *parser,
    OFString *string);
typedef OFString* (^of_xml_parser_unknown_entity_block_t)(OFXMLParser *parser,
    OFString *entity);
#endif

/**
 * \brief A protocol that needs to be implemented by delegates for OFXMLParser.
 */
#ifndef OF_XML_PARSER_M
@protocol OFXMLParserDelegate <OFObject>
#else
@protocol OFXMLParserDelegate







<
<
<
<
<
<
<
<
<
<
<
<
<







20
21
22
23
24
25
26













27
28
29
30
31
32
33

@class OFXMLParser;
@class OFArray;
@class OFMutableArray;
@class OFDataArray;
@class OFStream;














/**
 * \brief A protocol that needs to be implemented by delegates for OFXMLParser.
 */
#ifndef OF_XML_PARSER_M
@protocol OFXMLParserDelegate <OFObject>
#else
@protocol OFXMLParserDelegate
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
	OFString *prefix;
	OFMutableArray *namespaces;
	OFMutableArray *attributes;
	OFString *attributeName;
	OFString *attributePrefix;
	char delimiter;
	OFMutableArray *previous;
#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
	of_xml_parser_processing_instructions_block_t
	    processingInstructionsHandler;
	of_xml_parser_element_start_block_t elementStartHandler;
	of_xml_parser_element_end_block_t elementEndHandler;
	of_xml_parser_string_block_t charactersHandler;
	of_xml_parser_string_block_t CDATAHandler;
	of_xml_parser_string_block_t commentHandler;
	of_xml_parser_unknown_entity_block_t unknownEntityHandler;
#endif
	size_t level;
	BOOL acceptProlog;
	size_t lineNumber;
	BOOL lastCarriageReturn;
	BOOL finishedParsing;
	of_string_encoding_t encoding;
}

#ifdef OF_HAVE_PROPERTIES
@property (retain) id <OFXMLParserDelegate> delegate;
# ifdef OF_HAVE_BLOCKS
@property (retain) of_xml_parser_processing_instructions_block_t
    processingInstructionsHandler;
@property (retain) of_xml_parser_element_start_block_t elementStartHandler;
@property (retain) of_xml_parser_element_end_block_t elementEndHandler;
@property (retain) of_xml_parser_string_block_t charactersHandler;
@property (retain) of_xml_parser_string_block_t CDATAHandler;
@property (retain) of_xml_parser_string_block_t commentHandler;
@property (retain) of_xml_parser_unknown_entity_block_t unknownEntityHandler;
# endif
#endif

/**
 * \return A new, autoreleased OFXMLParser
 */
+ parser;

/**
 * \return The delegate that is used by the XML parser
 */
- (id <OFXMLParserDelegate>)delegate;

/**
 * Sets the delegate the OFXMLParser should use.
 *
 * \param delegate The delegate to use
 */
- (void)setDelegate: (id <OFXMLParserDelegate>)delegate;

#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
/**
 * \return The processing instructions handler
 */
- (of_xml_parser_processing_instructions_block_t)processingInstructionsHandler;

/**
 * Sets the processing instructions handler.
 *
 * \param block A processing instructions handler
 */
- (void)setProcessingInstructionsHandler:
    (of_xml_parser_processing_instructions_block_t)block;

/**
 * \return The element start handler
 */
- (of_xml_parser_element_start_block_t)elementStartHandler;

/**
 * Sets the element start handler.
 *
 * \param block An element start handler
 */
- (void)setElementStartHandler: (of_xml_parser_element_start_block_t)block;

/**
 * \return The element end handler
 */
- (of_xml_parser_element_end_block_t)elementEndHandler;

/**
 * Sets the element end handler.
 *
 * \param block An element end handler
 */
- (void)setElementEndHandler: (of_xml_parser_element_end_block_t)block;

/**
 * \return The characters handler
 */
- (of_xml_parser_string_block_t)charactersHandler;

/**
 * Sets the characters handler.
 *
 * \param block A characters handler
 */
- (void)setCharactersHandler: (of_xml_parser_string_block_t)block;

/**
 * \return The CDATA handler
 */
- (of_xml_parser_string_block_t)CDATAHandler;

/**
 * Sets the CDATA handler.
 *
 * \param block A CDATA handler
 */
- (void)setCDATAHandler: (of_xml_parser_string_block_t)block;

/**
 * \return The comment handler
 */
- (of_xml_parser_string_block_t)commentHandler;

/**
 * Sets the comment handler.
 *
 * \param block A comment handler
 */
- (void)setCommentHandler: (of_xml_parser_string_block_t)block;

/**
 * \return The unknown entity handler
 */
- (of_xml_parser_unknown_entity_block_t)unknownEntityHandler;

/**
 * Sets the unknown entity handler.
 *
 * \param block An unknown entity handler
 */
- (void)setUnknownEntityHandler: (of_xml_parser_unknown_entity_block_t)block;
#endif

/**
 * Parses a buffer with the specified size.
 *
 * \param buffer The buffer to parse
 * \param length The length of the buffer
 */
- (void)parseBuffer: (const char*)buffer







<
<
<
<
<
<
<
<
<
<










<
<
<
<
<
<
<
<
<
<



















<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







153
154
155
156
157
158
159










160
161
162
163
164
165
166
167
168
169










170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188























































































189
190
191
192
193
194
195
	OFString *prefix;
	OFMutableArray *namespaces;
	OFMutableArray *attributes;
	OFString *attributeName;
	OFString *attributePrefix;
	char delimiter;
	OFMutableArray *previous;










	size_t level;
	BOOL acceptProlog;
	size_t lineNumber;
	BOOL lastCarriageReturn;
	BOOL finishedParsing;
	of_string_encoding_t encoding;
}

#ifdef OF_HAVE_PROPERTIES
@property (retain) id <OFXMLParserDelegate> delegate;










#endif

/**
 * \return A new, autoreleased OFXMLParser
 */
+ parser;

/**
 * \return The delegate that is used by the XML parser
 */
- (id <OFXMLParserDelegate>)delegate;

/**
 * Sets the delegate the OFXMLParser should use.
 *
 * \param delegate The delegate to use
 */
- (void)setDelegate: (id <OFXMLParserDelegate>)delegate;
























































































/**
 * Parses a buffer with the specified size.
 *
 * \param buffer The buffer to parse
 * \param length The length of the buffer
 */
- (void)parseBuffer: (const char*)buffer

Modified src/OFXMLParser.m from [2217f932b7] to [3bdc0c658c].

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
			  prefix: attributePrefix];

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

@implementation OFXMLParser
#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
@synthesize processingInstructionsHandler, elementStartHandler;
@synthesize elementEndHandler, charactersHandler, CDATAHandler, commentHandler;
@synthesize unknownEntityHandler;
#endif

+ (void)initialize
{
	size_t i;

	const SEL selectors_[] = {
		@selector(_parseOutsideTagWithBuffer:i:last:),
		@selector(_parseTagOpenedWithBuffer:i:last:),







<
<
<
<
<
<







124
125
126
127
128
129
130






131
132
133
134
135
136
137
			  prefix: attributePrefix];

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

@implementation OFXMLParser






+ (void)initialize
{
	size_t i;

	const SEL selectors_[] = {
		@selector(_parseOutsideTagWithBuffer:i:last:),
		@selector(_parseTagOpenedWithBuffer:i:last:),
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
	[name release];
	[prefix release];
	[namespaces release];
	[attributes release];
	[attributeName release];
	[attributePrefix release];
	[previous release];
#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
	[elementStartHandler release];
	[elementEndHandler release];
	[charactersHandler release];
	[CDATAHandler release];
	[commentHandler release];
	[unknownEntityHandler release];
#endif

	[super dealloc];
}

- (id <OFXMLParserDelegate>)delegate
{
	OF_GETTER(delegate, YES)







<
<
<
<
<
<
<
<







209
210
211
212
213
214
215








216
217
218
219
220
221
222
	[name release];
	[prefix release];
	[namespaces release];
	[attributes release];
	[attributeName release];
	[attributePrefix release];
	[previous release];









	[super dealloc];
}

- (id <OFXMLParserDelegate>)delegate
{
	OF_GETTER(delegate, YES)
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
	if ([cache count] > 0) {
		OFString *characters;
		OFAutoreleasePool *pool;

		pool = [[OFAutoreleasePool alloc] init];
		characters = transform_string(cache, 0, YES, self);

#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
		if (charactersHandler != NULL)
			charactersHandler(self, characters);
		else
#endif
			[delegate parser: self
			 foundCharacters: characters];

		[pool release];
	}

	[cache removeNItems: [cache count]];

	*last = *i + 1;







<
<
<
<
<
|
|







316
317
318
319
320
321
322





323
324
325
326
327
328
329
330
331
	if ([cache count] > 0) {
		OFString *characters;
		OFAutoreleasePool *pool;

		pool = [[OFAutoreleasePool alloc] init];
		characters = transform_string(cache, 0, YES, self);






		[delegate parser: self
		 foundCharacters: characters];

		[pool release];
	}

	[cache removeNItems: [cache count]];

	*last = *i + 1;
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
		if (prefix != nil && ns == nil)
			@throw
			    [OFUnboundNamespaceException newWithClass: isa
							       prefix: prefix];

		pool2 = [[OFAutoreleasePool alloc] init];

#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
		if (elementStartHandler != NULL)
			elementStartHandler(self, name, prefix, ns, nil);
		else
#endif
			[delegate parser: self
			 didStartElement: name
			      withPrefix: prefix
			       namespace: ns
			      attributes: nil];

		if (buffer[*i] == '/') {
#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
			if (elementEndHandler != NULL)
				elementEndHandler(self, name, prefix, ns);
			else
#endif
				[delegate parser: self
				   didEndElement: name
				      withPrefix: prefix
				       namespace: ns];

			if ([previous count] == 0)
				finishedParsing = YES;
		} else
			[previous addObject: cacheString];

		[pool2 release];







<
<
<
<
<
|
|
|
|
|


<
<
<
<
<
|
|
|
|







542
543
544
545
546
547
548





549
550
551
552
553
554
555





556
557
558
559
560
561
562
563
564
565
566
		if (prefix != nil && ns == nil)
			@throw
			    [OFUnboundNamespaceException newWithClass: isa
							       prefix: prefix];

		pool2 = [[OFAutoreleasePool alloc] init];






		[delegate parser: self
		 didStartElement: name
		      withPrefix: prefix
		       namespace: ns
		      attributes: nil];

		if (buffer[*i] == '/') {





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

			if ([previous count] == 0)
				finishedParsing = YES;
		} else
			[previous addObject: cacheString];

		[pool2 release];
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
	[cache removeNItems: [cache count]];

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

#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
	if (elementEndHandler != NULL)
		elementEndHandler(self, name, prefix, ns);
	else
#endif
		[delegate parser: self
		   didEndElement: name
		      withPrefix: prefix
		       namespace: ns];

	[pool release];

	[namespaces removeLastObject];
	[name release];
	[prefix release];
	name = prefix = nil;







<
<
<
<
<
|
|
|
|







633
634
635
636
637
638
639





640
641
642
643
644
645
646
647
648
649
650
	[cache removeNItems: [cache count]];

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






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

	[pool release];

	[namespaces removeLastObject];
	[name release];
	[prefix release];
	name = prefix = nil;
725
726
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

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

	pool = [[OFAutoreleasePool alloc] init];

#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
	if (elementStartHandler != NULL)
		elementStartHandler(self, name, prefix, ns, attributes);
	else
#endif
		[delegate parser: self
		 didStartElement: name
		      withPrefix: prefix
		       namespace: ns
		      attributes: attributes];

	if (buffer[*i] == '/') {
#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
		if (elementEndHandler != NULL)
			elementEndHandler(self, name, prefix, ns);
		else
#endif
			[delegate parser: self
			   didEndElement: name
			      withPrefix: prefix
			       namespace: ns];

		if ([previous count] == 0)
			finishedParsing = YES;

		[namespaces removeLastObject];
	} else if (prefix != nil) {
		OFString *str = [OFString stringWithFormat: @"%@:%@",







<
<
<
<
<
|
|
|
|
|


<
<
<
<
<
|
|
|
|







691
692
693
694
695
696
697





698
699
700
701
702
703
704





705
706
707
708
709
710
711
712
713
714
715

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

	pool = [[OFAutoreleasePool alloc] init];






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

	if (buffer[*i] == '/') {





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

		if ([previous count] == 0)
			finishedParsing = YES;

		[namespaces removeLastObject];
	} else if (prefix != nil) {
		OFString *str = [OFString stringWithFormat: @"%@:%@",
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
	}

	pool = [[OFAutoreleasePool alloc] init];

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

#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
	if (CDATAHandler != NULL)
		CDATAHandler(self, CDATA);
	else
#endif
		[delegate parser: self
		      foundCDATA: CDATA];

	[pool release];

	[cache removeNItems: [cache count]];

	*last = *i + 1;
	state = OF_XMLPARSER_OUTSIDE_TAG;







<
<
<
<
<
|
|







938
939
940
941
942
943
944





945
946
947
948
949
950
951
952
953
	}

	pool = [[OFAutoreleasePool alloc] init];

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






	[delegate parser: self
	      foundCDATA: CDATA];

	[pool release];

	[cache removeNItems: [cache count]];

	*last = *i + 1;
	state = OF_XMLPARSER_OUTSIDE_TAG;
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
						      parser: self];

	pool = [[OFAutoreleasePool alloc] init];

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

#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
	if (commentHandler != NULL)
		commentHandler(self, comment);
	else
#endif
		[delegate parser: self
		    foundComment: comment];

	[pool release];

	[cache removeNItems: [cache count]];

	*last = *i + 1;
	state = OF_XMLPARSER_OUTSIDE_TAG;







<
<
<
<
<
|
|







992
993
994
995
996
997
998





999
1000
1001
1002
1003
1004
1005
1006
1007
						      parser: self];

	pool = [[OFAutoreleasePool alloc] init];

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






	[delegate parser: self
	    foundComment: comment];

	[pool release];

	[cache removeNItems: [cache count]];

	*last = *i + 1;
	state = OF_XMLPARSER_OUTSIDE_TAG;
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
{
	return finishedParsing;
}

-	   (OFString*)string: (OFString*)string
  containsUnknownEntityNamed: (OFString*)entity
{
#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
	if (unknownEntityHandler != NULL)
		return unknownEntityHandler(self, entity);
#endif

	return [delegate parser: self
	foundUnknownEntityNamed: entity];
}
@end

@implementation OFObject (OFXMLParserDelegate)
-		 (void)parser: (OFXMLParser*)parser







<
<
<
<
<







1040
1041
1042
1043
1044
1045
1046





1047
1048
1049
1050
1051
1052
1053
{
	return finishedParsing;
}

-	   (OFString*)string: (OFString*)string
  containsUnknownEntityNamed: (OFString*)entity
{





	return [delegate parser: self
	foundUnknownEntityNamed: entity];
}
@end

@implementation OFObject (OFXMLParserDelegate)
-		 (void)parser: (OFXMLParser*)parser