︙ | | | ︙ | |
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#define OF_XML_PARSER_M
#include <string.h>
#include <sys/types.h>
#import "OFXMLParser.h"
#import "OFString.h"
#import "OFArray.h"
|
<
<
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#include <string.h>
#include <sys/types.h>
#import "OFXMLParser.h"
#import "OFString.h"
#import "OFArray.h"
|
︙ | | | ︙ | |
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
if ((length = *i - *last) > 0)
cache_append(cache, buffer + *last, encoding, length);
if ([cache count] > 0) {
void *pool = objc_autoreleasePoolPush();
OFString *characters = transform_string(cache, 0, YES, self);
[delegate parser: self
foundCharacters: characters];
objc_autoreleasePoolPop(pool);
}
[cache removeAllItems];
*last = *i + 1;
|
>
>
|
|
|
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
if ((length = *i - *last) > 0)
cache_append(cache, buffer + *last, encoding, length);
if ([cache count] > 0) {
void *pool = objc_autoreleasePoolPush();
OFString *characters = transform_string(cache, 0, YES, self);
if ([delegate respondsToSelector:
@selector(parser:foundCharacters:)])
[delegate parser: self
foundCharacters: characters];
objc_autoreleasePoolPop(pool);
}
[cache removeAllItems];
*last = *i + 1;
|
︙ | | | ︙ | |
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
|
[pi hasPrefix: @"xml\t"] || [pi hasPrefix: @"xml\r"] ||
[pi hasPrefix: @"xml\n"])
if (![self OF_parseXMLProcessingInstructions: pi])
@throw [OFMalformedXMLException
exceptionWithClass: [self class]
parser: self];
[delegate parser: self
foundProcessingInstructions: pi];
objc_autoreleasePoolPop(pool);
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
|
>
>
|
|
|
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
|
[pi hasPrefix: @"xml\t"] || [pi hasPrefix: @"xml\r"] ||
[pi hasPrefix: @"xml\n"])
if (![self OF_parseXMLProcessingInstructions: pi])
@throw [OFMalformedXMLException
exceptionWithClass: [self class]
parser: self];
if ([delegate respondsToSelector:
@selector(parser:foundProcessingInstructions:)])
[delegate parser: self
foundProcessingInstructions: pi];
objc_autoreleasePoolPop(pool);
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
|
︙ | | | ︙ | |
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
|
ns = namespace_for_prefix(prefix, namespaces);
if (prefix != nil && ns == nil)
@throw [OFUnboundNamespaceException
exceptionWithClass: [self class]
prefix: prefix];
[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];
[name release];
|
>
>
|
|
|
|
|
>
>
|
|
|
|
|
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
|
ns = namespace_for_prefix(prefix, namespaces);
if (prefix != nil && ns == nil)
@throw [OFUnboundNamespaceException
exceptionWithClass: [self class]
prefix: prefix];
if ([delegate respondsToSelector: @selector(parser:
didStartElement:prefix:namespace:attributes:)])
[delegate parser: self
didStartElement: name
prefix: prefix
namespace: ns
attributes: nil];
if (buffer[*i] == '/') {
if ([delegate respondsToSelector:
@selector(parser:didEndElement:prefix:namespace:)])
[delegate parser: self
didEndElement: name
prefix: prefix
namespace: ns];
if ([previous count] == 0)
finishedParsing = YES;
} else
[previous addObject: cacheString];
[name release];
|
︙ | | | ︙ | |
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
|
ns = namespace_for_prefix(prefix, namespaces);
if (prefix != nil && ns == nil)
@throw [OFUnboundNamespaceException
exceptionWithClass: [self class]
prefix: prefix];
[delegate parser: self
didEndElement: name
withPrefix: prefix
namespace: ns];
objc_autoreleasePoolPop(pool);
[namespaces removeLastObject];
[name release];
[prefix release];
name = prefix = nil;
|
>
>
|
|
|
|
|
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
|
ns = namespace_for_prefix(prefix, namespaces);
if (prefix != nil && ns == nil)
@throw [OFUnboundNamespaceException
exceptionWithClass: [self class]
prefix: prefix];
if ([delegate respondsToSelector:
@selector(parser:didEndElement:prefix:namespace:)])
[delegate parser: self
didEndElement: name
prefix: prefix
namespace: ns];
objc_autoreleasePoolPop(pool);
[namespaces removeLastObject];
[name release];
[prefix release];
name = prefix = nil;
|
︙ | | | ︙ | |
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
|
for (j = 0; j < attributesCount; j++)
resolve_attribute_namespace(attributesObjects[j], namespaces,
self);
pool = objc_autoreleasePoolPush();
[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: @"%@:%@",
|
>
>
|
|
|
|
|
>
>
|
|
|
|
|
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
|
for (j = 0; j < attributesCount; j++)
resolve_attribute_namespace(attributesObjects[j], namespaces,
self);
pool = objc_autoreleasePoolPush();
if ([delegate respondsToSelector:
@selector(parser:didStartElement:prefix:namespace:attributes:)])
[delegate parser: self
didStartElement: name
prefix: prefix
namespace: ns
attributes: attributes];
if (buffer[*i] == '/') {
if ([delegate respondsToSelector:
@selector(parser:didEndElement:prefix:namespace:)])
[delegate parser: self
didEndElement: name
prefix: prefix
namespace: ns];
if ([previous count] == 0)
finishedParsing = YES;
[namespaces removeLastObject];
} else if (prefix != nil) {
OFString *str = [OFString stringWithFormat: @"%@:%@",
|
︙ | | | ︙ | |
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
|
}
pool = objc_autoreleasePoolPush();
cache_append(cache, buffer + *last, encoding, *i - *last);
CDATA = transform_string(cache, 2, NO, nil);
[delegate parser: self
foundCDATA: CDATA];
objc_autoreleasePoolPop(pool);
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
|
>
|
|
|
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
|
}
pool = objc_autoreleasePoolPush();
cache_append(cache, buffer + *last, encoding, *i - *last);
CDATA = transform_string(cache, 2, NO, nil);
if ([delegate respondsToSelector: @selector(parser:foundCDATA:)])
[delegate parser: self
foundCDATA: CDATA];
objc_autoreleasePoolPop(pool);
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
|
︙ | | | ︙ | |
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
|
parser: self];
pool = objc_autoreleasePoolPush();
cache_append(cache, buffer + *last, encoding, *i - *last);
comment = transform_string(cache, 2, NO, nil);
[delegate parser: self
foundComment: comment];
objc_autoreleasePoolPop(pool);
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
|
>
|
|
|
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
|
parser: self];
pool = objc_autoreleasePoolPush();
cache_append(cache, buffer + *last, encoding, *i - *last);
comment = transform_string(cache, 2, NO, nil);
if ([delegate respondsToSelector: @selector(parser:foundComment:)])
[delegate parser: self
foundComment: comment];
objc_autoreleasePoolPop(pool);
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
|
︙ | | | ︙ | |
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
|
{
return finishedParsing;
}
- (OFString*)string: (OFString*)string
containsUnknownEntityNamed: (OFString*)entity
{
return [delegate parser: self
foundUnknownEntityNamed: entity];
}
@end
@implementation OFObject (OFXMLParserDelegate)
- (void)parser: (OFXMLParser*)parser
foundProcessingInstructions: (OFString*)pi
{
}
- (void)parser: (OFXMLParser*)parser
didStartElement: (OFString*)name
withPrefix: (OFString*)prefix
namespace: (OFString*)ns
attributes: (OFArray*)attributes
{
}
- (void)parser: (OFXMLParser*)parser
didEndElement: (OFString*)name
withPrefix: (OFString*)prefix
namespace: (OFString*)ns
{
}
- (void)parser: (OFXMLParser*)parser
foundCharacters: (OFString*)characters
{
}
- (void)parser: (OFXMLParser*)parser
foundCDATA: (OFString*)CDATA
{
}
- (void)parser: (OFXMLParser*)parser
foundComment: (OFString*)comment
{
}
- (OFString*)parser: (OFXMLParser*)parser
foundUnknownEntityNamed: (OFString*)entity
{
return nil;
}
@end
|
|
|
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
|
{
return finishedParsing;
}
- (OFString*)string: (OFString*)string
containsUnknownEntityNamed: (OFString*)entity
{
if ([delegate respondsToSelector:
@selector(parser:foundUnknownEntityNamed:)])
return [delegate parser: self
foundUnknownEntityNamed: entity];
return nil;
}
@end
|