ObjFW  Check-in [83c351c9fd]

Overview
Comment:Add -[xmlParser:foundUnknownEntityNamed:] to OFXMLParserDelegate.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 83c351c9fd8f3e14430ea327b3e06d34aa242d995dc4d0ae5aa2c8e5aeba4075
User & Date: js on 2009-07-19 20:39:07
Other Links: manifest | tags
Context
2009-07-20
18:39
Add support for C strings encoded in ISO 8859-15. check-in: 0ea758cd9c user: js tags: trunk
2009-07-19
20:39
Add -[xmlParser:foundUnknownEntityNamed:] to OFXMLParserDelegate. check-in: 83c351c9fd user: js tags: trunk
18:14
Add support for C strings encoded in ISO 8859-1. check-in: 8216fb9343 user: js tags: trunk
Changes

Modified src/OFXMLParser.h from [46733a7e27] to [b01ef202a5].

25
26
27
28
29
30
31


32
33




34
35
36
37
38
39
40
41
	   attributes: (OFDictionary*)attrs;
-   (BOOL)xmlParser: (OFXMLParser*)parser
  didEndTagWithName: (OFString*)name
	     prefix: (OFString*)prefix
	  namespace: (OFString*)ns;
- (BOOL)xmlParser: (OFXMLParser*)parser
      foundString: (OFString*)string;


@end





@interface OFXMLParser: OFObject
{
	OFObject <OFXMLParserDelegate> *delegate;
	enum {
		OF_XMLPARSER_OUTSIDE_TAG,
		OF_XMLPARSER_TAG_OPENED,
		OF_XMLPARSER_IN_TAG_NAME,
		OF_XMLPARSER_IN_CLOSE_TAG_NAME,







>
>


>
>
>
>
|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
	   attributes: (OFDictionary*)attrs;
-   (BOOL)xmlParser: (OFXMLParser*)parser
  didEndTagWithName: (OFString*)name
	     prefix: (OFString*)prefix
	  namespace: (OFString*)ns;
- (BOOL)xmlParser: (OFXMLParser*)parser
      foundString: (OFString*)string;
-    (OFString*)xmlParser: (OFXMLParser*)parser
  foundUnknownEntityNamed: (OFString*)entity;
@end

@protocol OFXMLUnescapingDelegate
- (OFString*)foundUnknownEntityNamed: (OFString*)entitiy;
@end

@interface OFXMLParser: OFObject <OFXMLUnescapingDelegate>
{
	OFObject <OFXMLParserDelegate> *delegate;
	enum {
		OF_XMLPARSER_OUTSIDE_TAG,
		OF_XMLPARSER_TAG_OPENED,
		OF_XMLPARSER_IN_TAG_NAME,
		OF_XMLPARSER_IN_CLOSE_TAG_NAME,
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
+ xmlParser;
- (id)delegate;
- setDelegate: (OFObject <OFXMLParserDelegate>*)delegate;
- parseBuffer: (const char*)buf
     withSize: (size_t)size;
@end

@protocol OFXMLUnescapingDelegate
- (OFString*)foundUnknownEntityNamed: (OFString*)entitiy;
@end

@interface OFString (OFXMLUnescaping)
- stringByXMLUnescaping;
- stringByXMLUnescapingWithHandler: (OFObject <OFXMLUnescapingDelegate>*)h;
@end







<
<
<
<




64
65
66
67
68
69
70




71
72
73
74
+ xmlParser;
- (id)delegate;
- setDelegate: (OFObject <OFXMLParserDelegate>*)delegate;
- parseBuffer: (const char*)buf
     withSize: (size_t)size;
@end





@interface OFString (OFXMLUnescaping)
- stringByXMLUnescaping;
- stringByXMLUnescapingWithHandler: (OFObject <OFXMLUnescapingDelegate>*)h;
@end

Modified src/OFXMLParser.m from [47f877a838] to [8b1f567d63].

86
87
88
89
90
91
92


93
94
95
96
97
98
99
	}

	return self;
}

- (void)dealloc
{


	[cache release];
	[name release];
	[prefix release];
	[ns release];
	[attrs release];
	[attr_name release];








>
>







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
	}

	return self;
}

- (void)dealloc
{
	[delegate release];

	[cache release];
	[name release];
	[prefix release];
	[ns release];
	[attrs release];
	[attr_name release];

132
133
134
135
136
137
138
139


140
141
142
143
144
145
146
					[cache appendCString: buf + last
						  withLength: len];

				if ([cache length] > 0) {
					OFString *str;

					pool = [[OFAutoreleasePool alloc] init];
					str = [cache stringByXMLUnescaping];



					[delegate xmlParser: self
						foundString: str];

					[pool release];
				}








|
>
>







134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
					[cache appendCString: buf + last
						  withLength: len];

				if ([cache length] > 0) {
					OFString *str;

					pool = [[OFAutoreleasePool alloc] init];
					str = [cache
					    stringByXMLUnescapingWithHandler:
					    self];

					[delegate xmlParser: self
						foundString: str];

					[pool release];
				}

338
339
340
341
342
343
344


345
346
347
348
349
350
351
352
353
354


355
356
357
358
359
360
361
362
			last = i + 1;
			state = OF_XMLPARSER_IN_ATTR_VALUE;
			break;

		/* Looking for attribute value */
		case OF_XMLPARSER_IN_ATTR_VALUE:
			if (buf[i] == delim) {


				len = i - last;
				if (len > 0)
					[cache appendCString: buf + last
						  withLength: len];

				if (attrs == nil)
					attrs =
					    [[OFMutableDictionary alloc] init];

				pool = [[OFAutoreleasePool alloc] init];


				[attrs setObject: [cache stringByXMLUnescaping]
					  forKey: attr_name];
				[pool release];

				[cache setToCString: ""];
				[attr_name release];

				last = i + 1;







>
>










>
>
|







342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
			last = i + 1;
			state = OF_XMLPARSER_IN_ATTR_VALUE;
			break;

		/* Looking for attribute value */
		case OF_XMLPARSER_IN_ATTR_VALUE:
			if (buf[i] == delim) {
				OFString *attr_val;

				len = i - last;
				if (len > 0)
					[cache appendCString: buf + last
						  withLength: len];

				if (attrs == nil)
					attrs =
					    [[OFMutableDictionary alloc] init];

				pool = [[OFAutoreleasePool alloc] init];
				attr_val = [cache
				    stringByXMLUnescapingWithHandler: self];
				[attrs setObject: attr_val
					  forKey: attr_name];
				[pool release];

				[cache setToCString: ""];
				[attr_name release];

				last = i + 1;
390
391
392
393
394
395
396






397
398
399
400
401
402
403
	/* In OF_XMLPARSER_IN_TAG, there can be only spaces */
	if (len > 0 && state != OF_XMLPARSER_IN_TAG)
		[cache appendCString: buf + last
			  withLength: len];

	return self;
}






@end

@implementation OFString (OFXMLUnescaping)
- stringByXMLUnescaping
{
	return [self stringByXMLUnescapingWithHandler: nil];
}







>
>
>
>
>
>







398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
	/* In OF_XMLPARSER_IN_TAG, there can be only spaces */
	if (len > 0 && state != OF_XMLPARSER_IN_TAG)
		[cache appendCString: buf + last
			  withLength: len];

	return self;
}

- (OFString*)foundUnknownEntityNamed: (OFString*)entity
{
	return [delegate xmlParser: self
	   foundUnknownEntityNamed: entity];
}
@end

@implementation OFString (OFXMLUnescaping)
- stringByXMLUnescaping
{
	return [self stringByXMLUnescapingWithHandler: nil];
}

Modified tests/OFXMLParser/OFXMLParser.m from [b3f4a79e63] to [5db627fdbd].

64
65
66
67
68
69
70









71
72
73
74
75
76
77
78
79
80
81
82
83
84
- (BOOL)xmlParser: (OFXMLParser*)parser
      foundString: (OFString*)string
{
	printf("STRING\n\"%s\"\n\n", [string cString]);

	return YES;
}









@end

int
main()
{
	const char *foo = "bar<foo:bar  bar='b&amp;az'  qux=\"quux\">foo&lt;bar"
	    "<qux  >bar<baz name=''/>quxbar</xasd>";
	size_t len = strlen(foo);
	size_t i;
	OFXMLParser *parser = [OFXMLParser xmlParser];

	[parser setDelegate: [[ParserDelegate alloc] init]];

	/* Simulate a stream where we only get chunks */







>
>
>
>
>
>
>
>
>






|







64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
- (BOOL)xmlParser: (OFXMLParser*)parser
      foundString: (OFString*)string
{
	printf("STRING\n\"%s\"\n\n", [string cString]);

	return YES;
}

-    (OFString*)xmlParser: (OFXMLParser*)parser
  foundUnknownEntityNamed: (OFString*)entity
{
	if ([entity isEqual: @"foo"])
		return @"foobar";

	return nil;
}
@end

int
main()
{
	const char *foo = "bar<foo:bar  bar='b&amp;az'  qux=\"quux\">foo&lt;bar"
	    "<qux  >bar<baz name='' test='&foo;'/>quxbar</xasd>";
	size_t len = strlen(foo);
	size_t i;
	OFXMLParser *parser = [OFXMLParser xmlParser];

	[parser setDelegate: [[ParserDelegate alloc] init]];

	/* Simulate a stream where we only get chunks */