ObjFW  Check-in [e2a94b8f9d]

Overview
Comment:Better exception handling in OFXMLFactory.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e2a94b8f9dc62872cd42726cb3eb5e4c420d2cd068fd76087e560ab82fdbf158
User & Date: js on 2009-04-25 12:52:14
Other Links: manifest | tags
Context
2009-04-25
13:09
A few convenience methods for OFXMLFactory. check-in: 7fc221e592 user: js tags: trunk
12:52
Better exception handling in OFXMLFactory. check-in: e2a94b8f9d user: js tags: trunk
12:48
Update to latest rev of buildsys. check-in: 7b4aa35b8d user: js tags: trunk
Changes

Modified src/OFXMLFactory.m from [b53cd466b1] to [49b07c4eb9].

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
		@throw [OFOutOfRangeException newWithClass: self];

	len++;
	if ((ret = malloc(len)) == NULL)
		@throw [OFNoMemException newWithClass: self
					      andSize: len];


	for (i = 0; *s; s++) {
		switch (*s) {
		case '<':
			append(&ret, &len, &i, "&lt;", self);
			break;
		case '>':
			append(&ret, &len, &i, "&gt;", self);
			break;
		case '"':
			append(&ret, &len, &i, "&quot;", self);
			break;
		case '\'':
			append(&ret, &len, &i, "&apos;", self);
			break;
		case '&':
			append(&ret, &len, &i, "&amp;", self);
			break;
		default:
			ret[i++] = *s;
			break;
		}




	}

	ret[i] = 0;
	return ret;
}

+ (char*)createStanza: (const char*)name







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>







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
		@throw [OFOutOfRangeException newWithClass: self];

	len++;
	if ((ret = malloc(len)) == NULL)
		@throw [OFNoMemException newWithClass: self
					      andSize: len];

	@try {
		for (i = 0; *s; s++) {
			switch (*s) {
				case '<':
					append(&ret, &len, &i, "&lt;", self);
					break;
				case '>':
					append(&ret, &len, &i, "&gt;", self);
					break;
				case '"':
					append(&ret, &len, &i, "&quot;", self);
					break;
				case '\'':
					append(&ret, &len, &i, "&apos;", self);
					break;
				case '&':
					append(&ret, &len, &i, "&amp;", self);
					break;
				default:
					ret[i++] = *s;
					break;
			}
		}
	} @catch (OFException *e) {
		free(ret);
		@throw e;
	}

	ret[i] = 0;
	return ret;
}

+ (char*)createStanza: (const char*)name
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
188
189
190
191
192





193

194
195
196
197
198
199
200
			i += strlen(esc_val);
			xml[i++] = '\'';

			free(esc_val);
		}

		va_end(args);
	} @catch (OFException *e) {
		if (esc_val != NULL)
			free(esc_val);
		if (xml != NULL)
			free(xml);

		@throw e;
	}

	/* End of tag */
	if (close) {
		if (data == NULL) {
			resize(&xml, &len, 2 - 1, self);

			xml[i++] = '/';
			xml[i++] = '>';
		} else {
			resize(&xml, &len, 1 + strlen(data) + 2 + strlen(name) +
			    1 - 1, self);

			xml[i++] = '>';
			memcpy(xml + i, data, strlen(data));
			i += strlen(data);
			xml[i++] = '<';
			xml[i++] = '/';
			memcpy(xml + i, name, strlen(name));
			i += strlen(name);
			xml[i++] = '>';
		}
	} else
		xml[i++] = '>';







	xml[i] = 0;
	return xml;
}

+ (char*)concatAndFreeCStrings: (char**)strs
{
	char *ret;







<
<
<
<
<

<
<
<
|
|
|
|

|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
|
>







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
197
198
199
200
201
202
203
			i += strlen(esc_val);
			xml[i++] = '\'';

			free(esc_val);
		}

		va_end(args);









		/* End of tag */
		if (close) {
			if (data == NULL) {
				resize(&xml, &len, 2 - 1, self);

				xml[i++] = '/';
				xml[i++] = '>';
			} else {
				resize(&xml, &len, 1 + strlen(data) + 2 +
				    strlen(name) + 1 - 1, self);

				xml[i++] = '>';
				memcpy(xml + i, data, strlen(data));
				i += strlen(data);
				xml[i++] = '<';
				xml[i++] = '/';
				memcpy(xml + i, name, strlen(name));
				i += strlen(name);
				xml[i++] = '>';
			}
		} else
			xml[i++] = '>';
	} @catch (OFException *e) {
		if (esc_val != NULL)
			free(esc_val);
		free(xml);
		@throw e;
	}

	xml[i] = 0;
	return xml;
}

+ (char*)concatAndFreeCStrings: (char**)strs
{
	char *ret;
211
212
213
214
215
216
217

218
219
220
221
222




223
224
225
226
227
	if ((ret = malloc(len)) == NULL)
		@throw [OFNoMemException newWithClass: self
					      andSize: len];

	memcpy(ret, strs[0], len - 1);
	pos = len - 1;


	for (i = 1; strs[i] != NULL; i++)
		append(&ret, &len, &pos, strs[i], self);

	for (i = 0; strs[i] != NULL; i++)
		free(strs[i]);





	ret[pos] = 0;
	return ret;
}
@end







>
|
|

|
|
>
>
>
>





214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
	if ((ret = malloc(len)) == NULL)
		@throw [OFNoMemException newWithClass: self
					      andSize: len];

	memcpy(ret, strs[0], len - 1);
	pos = len - 1;

	@try {
		for (i = 1; strs[i] != NULL; i++)
			append(&ret, &len, &pos, strs[i], self);

		for (i = 0; strs[i] != NULL; i++)
			free(strs[i]);
	} @catch (OFException *e) {
		free(ret);
		@throw e;
	}

	ret[pos] = 0;
	return ret;
}
@end