ObjFW  Diff

Differences From Artifact [97be60a350]:

To Artifact [06291ad3fb]:


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
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







-
+














-
+



-
+





-
-
+
+



-
+












-
+





-
+





-
+






-
+








-
+








-
+





-
+
-







-
+
-


-
+








static OFArray *
parseArrayElement(OFXMLElement *element)
{
	OFMutableArray *ret = [OFMutableArray array];
	void *pool = objc_autoreleasePoolPush();

	for (OFXMLElement *child in [element elements])
	for (OFXMLElement *child in element.elements)
		[ret addObject: parseElement(child)];

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
}

static OFDictionary *
parseDictElement(OFXMLElement *element)
{
	OFMutableDictionary *ret = [OFMutableDictionary dictionary];
	void *pool = objc_autoreleasePoolPush();
	OFArray OF_GENERIC(OFXMLElement *) *children = [element elements];
	OFArray OF_GENERIC(OFXMLElement *) *children = element.elements;
	OFEnumerator OF_GENERIC(OFXMLElement *) *enumerator;
	OFXMLElement *key, *object;

	if ([children count] % 2 != 0)
	if (children.count % 2 != 0)
		@throw [OFInvalidFormatException exception];

	enumerator = [children objectEnumerator];
	while ((key = [enumerator nextObject]) &&
	    (object = [enumerator nextObject])) {
		if ([key namespace] != nil || [[key attributes] count] != 0 ||
		    ![[key name] isEqual: @"key"])
		if (key.namespace != nil || key.attributes.count != 0 ||
		    ![key.name isEqual: @"key"])
			@throw [OFInvalidFormatException exception];

		[ret setObject: parseElement(object)
			forKey: [key stringValue]];
			forKey: key.stringValue];
	}

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
}

static OFString *
parseStringElement(OFXMLElement *element)
{
	return [element stringValue];
	return element.stringValue;
}

static OFData *
parseDataElement(OFXMLElement *element)
{
	return [OFData dataWithBase64EncodedString: [element stringValue]];
	return [OFData dataWithBase64EncodedString: element.stringValue];
}

static OFDate *
parseDateElement(OFXMLElement *element)
{
	return [OFDate dateWithDateString: [element stringValue]
	return [OFDate dateWithDateString: element.stringValue
				   format: @"%Y-%m-%dT%H:%M:%SZ"];
}

static OFNumber *
parseTrueElement(OFXMLElement *element)
{
	if ([[element children] count] != 0)
	if (element.children.count != 0)
		@throw [OFInvalidFormatException exception];

	return [OFNumber numberWithBool: true];
}

static OFNumber *
parseFalseElement(OFXMLElement *element)
{
	if ([[element children] count] != 0)
	if (element.children.count != 0)
		@throw [OFInvalidFormatException exception];

	return [OFNumber numberWithBool: false];
}

static OFNumber *
parseRealElement(OFXMLElement *element)
{
	return [OFNumber numberWithDouble: [[element stringValue] doubleValue]];
	return [OFNumber numberWithDouble: element.stringValue.doubleValue];
}

static OFNumber *
parseIntegerElement(OFXMLElement *element)
{
	return [OFNumber numberWithIntMax:
	return [OFNumber numberWithIntMax: element.stringValue.decimalValue];
	    [[element stringValue] decimalValue]];
}

static id
parseElement(OFXMLElement *element)
{
	OFString *elementName;

	if ([element namespace] != nil ||
	if (element.namespace != nil || element.attributes.count != 0)
	    [[element attributes] count] != 0)
		@throw [OFInvalidFormatException exception];

	elementName = [element name];
	elementName = element.name;

	if ([elementName isEqual: @"array"])
		return parseArrayElement(element);
	else if ([elementName isEqual: @"dict"])
		return parseDictElement(element);
	else if ([elementName isEqual: @"string"])
		return parseStringElement(element);
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
197
198
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







-
-
+
+







-
+



-
+

-
+


-
+






{
	void *pool = objc_autoreleasePoolPush();
	OFXMLElement *rootElement = [OFXMLElement elementWithXMLString: self];
	OFXMLAttribute *versionAttribute;
	OFArray OF_GENERIC(OFXMLElement *) *elements;
	id ret;

	if (![[rootElement name] isEqual: @"plist"] ||
	    [rootElement namespace] != nil)
	if (![rootElement.name isEqual: @"plist"] ||
	    rootElement.namespace != nil)
		@throw [OFInvalidFormatException exception];

	versionAttribute = [rootElement attributeForName: @"version"];

	if (versionAttribute == nil)
		@throw [OFInvalidFormatException exception];

	if (![[versionAttribute stringValue] isEqual: @"1.0"])
	if (![versionAttribute.stringValue isEqual: @"1.0"])
		@throw [OFUnsupportedVersionException
		    exceptionWithVersion: [versionAttribute stringValue]];

	elements = [rootElement elements];
	elements = rootElement.elements;

	if ([elements count] != 1)
	if (elements.count != 1)
		@throw [OFInvalidFormatException exception];

	ret = parseElement([elements firstObject]);
	ret = parseElement(elements.firstObject);

	[ret retain];
	objc_autoreleasePoolPop(pool);
	return [ret autorelease];
}
@end