︙ | | | ︙ | |
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#import "OFXMLAttribute.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "macros.h"
static OF_INLINE OFString*
transform_string(OFMutableString *cache,
OFObject <OFStringXMLUnescapingDelegate> *handler)
{
[cache replaceOccurrencesOfString: @"\r\n"
withString: @"\n"];
[cache replaceOccurrencesOfString: @"\r"
withString: @"\n"];
return [cache stringByXMLUnescapingWithHandler: handler];
}
static OF_INLINE OFString*
namespace_for_prefix(OFString *prefix, OFArray *namespaces)
{
OFDictionary **carray = [namespaces cArray];
ssize_t i;
|
|
|
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#import "OFXMLAttribute.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "macros.h"
static OF_INLINE OFString*
transform_string(OFMutableString *cache,
OFObject <OFStringXMLUnescapingDelegate> *delegate)
{
[cache replaceOccurrencesOfString: @"\r\n"
withString: @"\n"];
[cache replaceOccurrencesOfString: @"\r"
withString: @"\n"];
return [cache stringByXMLUnescapingWithDelegate: delegate];
}
static OF_INLINE OFString*
namespace_for_prefix(OFString *prefix, OFArray *namespaces)
{
OFDictionary **carray = [namespaces cArray];
ssize_t i;
|
︙ | | | ︙ | |
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
length: len];
if ([cache cStringLength] > 0) {
OFString *str;
pool = [[OFAutoreleasePool alloc] init];
str = transform_string(cache, self);
[delegate xmlParser: self
didFindString: str];
[pool release];
}
[cache setToCString: ""];
last = i + 1;
state = OF_XMLPARSER_TAG_OPENED;
|
|
|
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
length: len];
if ([cache cStringLength] > 0) {
OFString *str;
pool = [[OFAutoreleasePool alloc] init];
str = transform_string(cache, self);
[delegate parser: self
foundCharacters: str];
[pool release];
}
[cache setToCString: ""];
last = i + 1;
state = OF_XMLPARSER_TAG_OPENED;
|
︙ | | | ︙ | |
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
|
if (prefix != nil && ns == nil)
@throw
[OFUnboundNamespaceException
newWithClass: isa
prefix: prefix];
[delegate xmlParser: self
didStartTagWithName: name
prefix: prefix
namespace: ns
attributes: nil];
if (buf[i] == '/')
[delegate xmlParser: self
didEndTagWithName: name
prefix: prefix
namespace: ns];
else
[previous addObject:
[[cache copy] autorelease]];
[pool release];
[name release];
|
|
|
|
|
|
|
|
|
|
|
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
|
if (prefix != nil && ns == nil)
@throw
[OFUnboundNamespaceException
newWithClass: isa
prefix: prefix];
[delegate parser: self
didStartElement: name
withPrefix: prefix
namespace: ns
attributes: nil];
if (buf[i] == '/')
[delegate parser: self
didEndElement: name
withPrefix: prefix
namespace: ns];
else
[previous addObject:
[[cache copy] autorelease]];
[pool release];
[name release];
|
︙ | | | ︙ | |
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
ns = namespace_for_prefix(prefix, namespaces);
if (prefix != nil && ns == nil)
@throw [OFUnboundNamespaceException
newWithClass: isa
prefix: prefix];
[namespaces removeNObjects: 1];
[delegate xmlParser: self
didEndTagWithName: name
prefix: prefix
namespace: ns];
[pool release];
[name release];
[prefix release];
name = prefix = nil;
|
|
|
|
|
|
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
ns = namespace_for_prefix(prefix, namespaces);
if (prefix != nil && ns == nil)
@throw [OFUnboundNamespaceException
newWithClass: isa
prefix: prefix];
[namespaces removeNObjects: 1];
[delegate parser: self
didEndElement: name
withPrefix: prefix
namespace: ns];
[pool release];
[name release];
[prefix release];
name = prefix = nil;
|
︙ | | | ︙ | |
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
ns = namespace_for_prefix(prefix, namespaces);
if (prefix != nil && ns == nil)
@throw [OFUnboundNamespaceException
newWithClass: isa
prefix: prefix];
[delegate xmlParser: self
didStartTagWithName: name
prefix: prefix
namespace: ns
attributes: attrs];
if (buf[i] == '/') {
[delegate xmlParser: self
didEndTagWithName: name
prefix: prefix
namespace: ns];
[namespaces removeNObjects: 1];
} else if (prefix != nil) {
OFString *str = [OFString
stringWithFormat: @"%s:%s",
[prefix cString],
[name cString]];
[previous addObject: str];
|
|
|
|
|
|
|
|
|
|
|
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
ns = namespace_for_prefix(prefix, namespaces);
if (prefix != nil && ns == nil)
@throw [OFUnboundNamespaceException
newWithClass: isa
prefix: prefix];
[delegate parser: self
didStartElement: name
withPrefix: prefix
namespace: ns
attributes: attrs];
if (buf[i] == '/') {
[delegate parser: self
didEndElement: name
withPrefix: prefix
namespace: ns];
[namespaces removeNObjects: 1];
} else if (prefix != nil) {
OFString *str = [OFString
stringWithFormat: @"%s:%s",
[prefix cString],
[name cString]];
[previous addObject: str];
|
︙ | | | ︙ | |
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
|
appendCStringWithoutUTF8Checking: buf + last
length: i - last];
cdata = [[cache mutableCopy] autorelease];
len = [cdata length];
[cdata removeCharactersFromIndex: len - 2
toIndex: len];
[delegate xmlParser: self
didFindString: cdata];
[pool release];
[cache setToCString: ""];
last = i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
} else if (buf[i] != ']')
|
|
|
|
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
|
appendCStringWithoutUTF8Checking: buf + last
length: i - last];
cdata = [[cache mutableCopy] autorelease];
len = [cdata length];
[cdata removeCharactersFromIndex: len - 2
toIndex: len];
[delegate parser: self
foundCDATA: cdata];
[pool release];
[cache setToCString: ""];
last = i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
} else if (buf[i] != ']')
|
︙ | | | ︙ | |
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
|
appendCStringWithoutUTF8Checking: buf + last
length: i - last];
comment = [[cache mutableCopy] autorelease];
len = [comment length];
[comment removeCharactersFromIndex: len - 2
toIndex: len];
[delegate xmlParser: self
didFindComment: comment];
[pool release];
[cache setToCString: ""];
last = i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
} else
|
|
|
|
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
|
appendCStringWithoutUTF8Checking: buf + last
length: i - last];
comment = [[cache mutableCopy] autorelease];
len = [comment length];
[comment removeCharactersFromIndex: len - 2
toIndex: len];
[delegate parser: self
foundComment: comment];
[pool release];
[cache setToCString: ""];
last = i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
} else
|
︙ | | | ︙ | |
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
|
len = size - last;
/* In OF_XMLPARSER_IN_TAG, there can be only spaces */
if (len > 0 && state != OF_XMLPARSER_IN_TAG)
[cache appendCStringWithoutUTF8Checking: buf + last
length: len];
}
- (OFString*)didFindUnknownEntityNamed: (OFString*)entity
{
return [delegate xmlParser: self
didFindUnknownEntityNamed: entity];
}
@end
@implementation OFObject (OFXMLParserDelegate)
- (void)xmlParser: (OFXMLParser*)parser
didStartTagWithName: (OFString*)name
prefix: (OFString*)prefix
namespace: (OFString*)ns
attributes: (OFArray*)attrs
{
}
- (void)xmlParser: (OFXMLParser*)parser
didEndTagWithName: (OFString*)name
prefix: (OFString*)prefix
namespace: (OFString*)ns
{
}
- (void)xmlParser: (OFXMLParser*)parser
didFindString: (OFString*)string
{
}
- (void)xmlParser: (OFXMLParser*)parser
didFindComment: (OFString*)comment
{
}
- (OFString*)xmlParser: (OFXMLParser*)parser
didFindUnknownEntityNamed: (OFString*)entity
{
return nil;
}
@end
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
|
|
|
|
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
|
len = size - last;
/* In OF_XMLPARSER_IN_TAG, there can be only spaces */
if (len > 0 && state != OF_XMLPARSER_IN_TAG)
[cache appendCStringWithoutUTF8Checking: buf + last
length: len];
}
- (OFString*)string: (OFString*)string
containsUnknownEntityNamed: (OFString*)entity
{
return [delegate parser: self
foundUnknownEntityNamed: entity];
}
@end
@implementation OFObject (OFXMLParserDelegate)
- (void)parser: (OFXMLParser*)parser
didStartElement: (OFString*)name
withPrefix: (OFString*)prefix
namespace: (OFString*)ns
attributes: (OFArray*)attrs
{
}
- (void)parser: (OFXMLParser*)parser
didEndElement: (OFString*)name
withPrefix: (OFString*)prefix
namespace: (OFString*)ns
{
}
- (void)parser: (OFXMLParser*)parser
foundCharacters: (OFString*)string
{
}
- (void)parser: (OFXMLParser*)parser
foundCDATA: (OFString*)cdata
{
}
- (void)parser: (OFXMLParser*)parser
foundComment: (OFString*)comment
{
}
- (OFString*)parser: (OFXMLParser*)parser
foundUnknownEntityNamed: (OFString*)entity
{
return nil;
}
@end
|