12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#include "config.h"
#include <string.h>
#import "OFXMLParser.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
int _OFXMLParser_reference;
@implementation OFXMLParser
+ xmlParser
{
return [[[self alloc] init] autorelease];
}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
12
13
14
15
16
17
18
19
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include "config.h"
#include <string.h>
#import "OFXMLParser.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "OFMacros.h"
int _OFXMLParser_reference;
static OF_INLINE OFString*
parse_numeric_entity(char *entity, size_t length)
{
uint32_t c;
size_t i;
char buf[4];
if (length == 1 || *entity != '#')
return nil;
c = 0;
entity++;
length--;
if (entity[0] == 'x') {
if (length == 1)
return nil;
entity++;
length--;
for (i = 0; i < length; i++) {
if (entity[i] >= '0' && entity[i] <= '9')
c = (c * 0x10) + (entity[i] - '0');
else if (entity[i] >= 'A' && entity[i] <= 'F')
c = (c * 0x10) + (entity[i] - 'A' + 10);
else if (entity[i] >= 'a' && entity[i] <= 'f')
c = (c * 0x10) + (entity[i] - 'A' + 10);
else
return nil;
}
} else {
for (i = 0; i < length; i++) {
if (entity[i] >= '0' && entity[i] <= '9')
c = (c * 10) + (entity[i] - '0');
else
return nil;
}
}
if ((i = of_string_unicode_to_utf8(c, buf)) == 0)
return nil;
return [OFString stringWithCString: buf
andLength: i];
}
@implementation OFXMLParser
+ xmlParser
{
return [[[self alloc] init] autorelease];
}
|
59
60
61
62
63
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
|
if (!in_entity && string[i] == '&') {
[ret appendCStringWithoutUTF8Checking: string + last
andLength: i - last];
last = i + 1;
in_entity = YES;
} else if (in_entity && string[i] == ';') {
size_t len = i - last;
if (len == 2 && !memcmp(string + last, "lt", 2))
[ret appendString: @"<"];
else if (len == 2 && !memcmp(string + last, "gt", 2))
[ret appendString: @">"];
else if (len == 4 && !memcmp(string + last, "quot", 4))
[ret appendString: @"\""];
else if (len == 4 && !memcmp(string + last, "apos", 4))
[ret appendString: @"'"];
else if (len == 3 && !memcmp(string + last, "amp", 3))
[ret appendString: @"&"];
else if (h != nil) {
OFAutoreleasePool *pool;
OFString *n, *tmp;
pool = [[OFAutoreleasePool alloc] init];
n = [OFString stringWithCString: string + last
andLength: len];
tmp = [h foundUnknownEntityNamed: n];
if (tmp == nil)
@throw [OFInvalidEncodingException
newWithClass: isa];
|
>
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
if (!in_entity && string[i] == '&') {
[ret appendCStringWithoutUTF8Checking: string + last
andLength: i - last];
last = i + 1;
in_entity = YES;
} else if (in_entity && string[i] == ';') {
char *entity = string + last;
size_t len = i - last;
if (len == 2 && !memcmp(entity, "lt", 2))
[ret appendString: @"<"];
else if (len == 2 && !memcmp(entity, "gt", 2))
[ret appendString: @">"];
else if (len == 4 && !memcmp(entity, "quot", 4))
[ret appendString: @"\""];
else if (len == 4 && !memcmp(entity, "apos", 4))
[ret appendString: @"'"];
else if (len == 3 && !memcmp(entity, "amp", 3))
[ret appendString: @"&"];
else if (entity[0] == '#') {
OFAutoreleasePool *pool;
OFString *tmp;
pool = [[OFAutoreleasePool alloc] init];
tmp = parse_numeric_entity(entity, len);
if (tmp == nil)
@throw [OFInvalidEncodingException
newWithClass: isa];
[ret appendString: tmp];
[pool release];
} else if (h != nil) {
OFAutoreleasePool *pool;
OFString *n, *tmp;
pool = [[OFAutoreleasePool alloc] init];
n = [OFString stringWithCString: entity
andLength: len];
tmp = [h foundUnknownEntityNamed: n];
if (tmp == nil)
@throw [OFInvalidEncodingException
newWithClass: isa];
|