ObjFW  Diff

Differences From Artifact [b53cd466b1]:

To Artifact [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
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;
		}
		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
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);
	} @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);
		/* 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++] = '/';
				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++] = '>';
				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
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 = 1; strs[i] != NULL; i++)
			append(&ret, &len, &pos, strs[i], self);

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

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