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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
|
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
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
|
-
-
-
+
+
+
+
-
-
+
+
+
+
+
-
+
+
-
+
+
+
-
+
-
-
+
-
+
+
+
+
+
+
+
-
+
+
-
+
-
+
-
+
-
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
+
+
+
+
-
+
-
-
+
-
+
+
-
-
+
+
+
+
+
+
-
+
-
-
-
-
+
+
+
-
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
|
* file.
*/
#include "config.h"
#include <string.h>
#import "OFXMLProcessingInstructions.h"
#import "OFXMLNode+Private.h"
#import "OFString.h"
#import "OFXMLProcessingInstruction.h"
#import "OFString.h"
#import "OFXMLAttribute.h"
#import "OFXMLElement.h"
#import "OFXMLNode+Private.h"
#import "OFInvalidArgumentException.h"
@implementation OFXMLProcessingInstructions
+ (instancetype)processingInstructionsWithString: (OFString *)string
@implementation OFXMLProcessingInstruction
@synthesize target = _target, data = _data;
+ (instancetype)processingInstructionWithTarget: (OFString *)target
data: (OFString *)data
{
return [[[self alloc] initWithString: string] autorelease];
return [[[self alloc] initWithTarget: target
data: data] autorelease];
}
- (instancetype)initWithString: (OFString *)string
- (instancetype)initWithTarget: (OFString *)target
data: (OFString *)data
{
self = [super of_init];
@try {
_target = [target copy];
_processingInstructions = [string copy];
_data = [data copy];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
self = [super of_init];
@try {
void *pool = objc_autoreleasePoolPush();
OFXMLAttribute *targetAttr;
if (![element.name isEqual: self.className] ||
![element.namespace isEqual: OF_SERIALIZATION_NS])
![element.namespace isEqual: OFSerializationNS])
@throw [OFInvalidArgumentException exception];
targetAttr = [element attributeForName: @"target"
namespace: OFSerializationNS];
if (targetAttr.stringValue.length == 0)
@throw [OFInvalidArgumentException exception];
self = [self initWithTarget: targetAttr.stringValue
_processingInstructions = [element.stringValue copy];
data: element.stringValue];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_target release];
[_processingInstructions release];
[_data release];
[super dealloc];
}
- (bool)isEqual: (id)object
{
OFXMLProcessingInstructions *processingInstructions;
OFXMLProcessingInstruction *processingInstruction;
if (object == self)
return true;
if (![object isKindOfClass: [OFXMLProcessingInstructions class]])
if (![object isKindOfClass: [OFXMLProcessingInstruction class]])
return false;
processingInstructions = object;
processingInstruction = object;
if (![processingInstruction->_target isEqual: _target])
return false;
return [processingInstructions->_processingInstructions
isEqual: _processingInstructions];
if (processingInstruction->_data != _data &&
![processingInstruction->_data isEqual: _data])
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _target.hash);
OFHashAddHash(&hash, _data.hash);
OFHashFinalize(&hash);
return _processingInstructions.hash;
return hash;
}
- (OFString *)stringValue
{
return @"";
}
- (OFString *)XMLString
{
if (_data.length > 0)
return [OFString stringWithFormat: @"<?%@?>", _processingInstructions];
return [OFString stringWithFormat: @"<?%@ %@?>",
_target, _data];
else
return [OFString stringWithFormat: @"<?%@?>", _target];
}
- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
{
return [OFString stringWithFormat: @"<?%@?>", _processingInstructions];
return self.XMLString;
}
- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
level: (unsigned int)level
{
OFString *ret;
if (indentation > 0 && level > 0) {
OFString *ret;
char *whitespaces = of_alloc((level * indentation) + 1, 1);
char *whitespaces = OFAllocMemory((level * indentation) + 1, 1);
memset(whitespaces, ' ', level * indentation);
whitespaces[level * indentation] = 0;
@try {
if (_data.length > 0)
ret = [OFString stringWithFormat:
@"%s<?%@?>", whitespaces, _processingInstructions];
ret = [OFString stringWithFormat:
@"%s<?%@ %@?>", whitespaces,
_target, _data];
else
ret = [OFString stringWithFormat:
@"%s<?%@?>", whitespaces, _target];
} @finally {
free(whitespaces);
OFFreeMemory(whitespaces);
}
} else
ret = [OFString stringWithFormat: @"<?%@?>",
_processingInstructions];
return ret;
return ret;
} else
return self.XMLString;
}
- (OFString *)description
{
return [OFString stringWithFormat: @"<?%@?>", _processingInstructions];
return self.XMLString;
}
- (OFXMLElement *)XMLElementBySerializing
{
return [OFXMLElement elementWithName: self.className
namespace: OF_SERIALIZATION_NS
stringValue: _processingInstructions];
}
OFXMLElement *ret = [OFXMLElement elementWithName: self.className
namespace: OFSerializationNS
stringValue: _data];
void *pool = objc_autoreleasePoolPush();
[ret addAttribute: [OFXMLAttribute attributeWithName: @"target"
stringValue: _target]];
objc_autoreleasePoolPop(pool);
return ret;
}
@end
|