1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
-
+
-
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2008-2023 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* 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"
#import "OFXMLAttribute.h"
#import "OFXMLNode+Private.h"
#import "OFString.h"
#import "OFDictionary.h"
#import "OFXMLElement.h"
#import "OFInvalidArgumentException.h"
@implementation OFXMLAttribute
@synthesize name = _name, namespace = _namespace;
+ (instancetype)attributeWithName: (OFString *)name
|
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
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
_namespace = [namespace copy];
_stringValue = [stringValue copy];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
void *pool;
OFString *name, *namespace, *stringValue;
@try {
pool = objc_autoreleasePoolPush();
if (![element.name isEqual: self.className] ||
![element.namespace isEqual: OFSerializationNS])
@throw [OFInvalidArgumentException exception];
name = [element attributeForName: @"name"].stringValue;
namespace = [element attributeForName: @"namespace"]
.stringValue;
stringValue = [element attributeForName: @"stringValue"]
.stringValue;
} @catch (id e) {
[self release];
@throw e;
}
self = [self initWithName: name
namespace: namespace
stringValue: stringValue];
@try {
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_name release];
[_namespace release];
|
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
188
189
190
191
192
193
194
195
196
|
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
OFHashAddHash(&hash, _stringValue.hash);
OFHashFinalize(&hash);
return hash;
}
- (OFXMLElement *)XMLElementBySerializing
{
void *pool = objc_autoreleasePoolPush();
OFXMLElement *element;
element = [OFXMLElement elementWithName: self.className
namespace: OFSerializationNS];
[element addAttributeWithName: @"name" stringValue: _name];
if (_namespace != nil)
[element addAttributeWithName: @"namespace"
stringValue: _namespace];
[element addAttributeWithName: @"stringValue"
stringValue: _stringValue];
[element retain];
objc_autoreleasePoolPop(pool);
return [element autorelease];
}
- (OFString *)description
{
return [OFString stringWithFormat: @"<%@: name=%@, namespace=%@, "
@"stringValue=%@>",
self.class, _name, _namespace,
_stringValue];
}
@end
|