ObjFW  Diff

Differences From Artifact [f3d57089d4]:

To Artifact [a4955aa6db]:


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







-
+












-
+













-
+







		}
		memcpy(string, str, length + 1);
	}

	return self;
}

- initWithFormat: (const char*)fmt, ...
- initWithFormat: (OFString*)fmt, ...
{
	id ret;
	va_list args;

	va_start(args, fmt);
	ret = [self initWithFormat: fmt
		      andArguments: args];
	va_end(args);

	return ret;
}

- initWithFormat: (const char*)fmt
- initWithFormat: (OFString*)fmt
    andArguments: (va_list)args
{
	int t;
	Class c;

	self = [super init];

	if (fmt == NULL) {
		c = isa;
		[super dealloc];
		@throw [OFInvalidFormatException newWithClass: c];
	}

	if ((t = vasprintf(&string, fmt, args)) == -1) {
	if ((t = vasprintf(&string, [fmt cString], args)) == -1) {
		c = isa;
		[super dealloc];
		@throw [OFInitializationFailedException newWithClass: c];
	}
	length = t;

	switch (check_utf8(string, length)) {
255
256
257
258
259
260
261
262

263
264
265
266
267
268
269


270
271
272
273
274
275
276


277
278
279
280
281
282
283

284
285
286
287
288
289
290
255
256
257
258
259
260
261

262
263
264
265
266
267


268
269
270
271
272
273
274


275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290







-
+





-
-
+
+





-
-
+
+






-
+







			  toSize: length + strlength + 1];
	memcpy(string + length, str, strlength + 1);
	length += strlength;

	return self;
}

- appendWithFormatCString: (const char*)fmt, ...
- appendWithFormat: (OFString*)fmt, ...
{
	id ret;
	va_list args;

	va_start(args, fmt);
	ret = [self appendWithFormatCString: fmt
			       andArguments: args];
	ret = [self appendWithFormat: fmt
			andArguments: args];
	va_end(args);

	return ret;
}

- appendWithFormatCString: (const char*)fmt
	     andArguments: (va_list)args
- appendWithFormat: (OFString*)fmt
      andArguments: (va_list)args
{
	char *t;

	if (fmt == NULL)
		@throw [OFInvalidFormatException newWithClass: isa];

	if ((vasprintf(&t, fmt, args)) == -1)
	if ((vasprintf(&t, [fmt cString], args)) == -1)
		/*
		 * This is only the most likely error to happen.
		 * Unfortunately, as errno isn't always thread-safe, there's
		 * no good way for us to find out what really happened.
		 */
		@throw [OFNoMemException newWithClass: isa];