ObjFW  Diff

Differences From Artifact [e75a0d88c9]:

To Artifact [451d779be8]:


229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243







-
+







		@throw [OFOutOfRangeException exception];

	if (_incompleteUTF8SurrogateLen > 0) {
		of_unichar_t c;
		char16_t UTF16[2];
		ssize_t UTF8Len;
		size_t toCopy;
		DWORD UTF16Len, written;
		DWORD UTF16Len, bytesWritten;

		UTF8Len = -of_string_utf8_decode(
		    _incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c);

		OF_ENSURE(UTF8Len > 0);

		toCopy = UTF8Len - _incompleteUTF8SurrogateLen;
267
268
269
270
271
272
273
274
275









276
277
278

279

280
281
282
283
284
285
286
287
288

289
290
291
292
293
294
295
267
268
269
270
271
272
273


274
275
276
277
278
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295

296
297
298
299
300
301
302
303







-
-
+
+
+
+
+
+
+
+
+



+
-
+








-
+







				UTF16Len = 2;
			} else {
				UTF16[0] = c;
				UTF16Len = 1;
			}
		}

		if (!WriteConsoleW(_handle, UTF16, UTF16Len, &written, NULL) ||
		    written != UTF16Len)
		if (!WriteConsoleW(_handle, UTF16, UTF16Len, &bytesWritten,
		    NULL))
			@throw [OFWriteFailedException
			    exceptionWithObject: self
				requestedLength: UTF16Len * 2
				   bytesWritten: 0
					  errNo: EIO];

		if (bytesWritten != UTF16Len)
			@throw [OFWriteFailedException
			    exceptionWithObject: self
				requestedLength: UTF16Len * 2
				   bytesWritten: bytesWritten * 2
					  errNo: EIO];
					  errNo: 0];

		_incompleteUTF8SurrogateLen = 0;
		i += toCopy;
	}

	tmp = [self allocMemoryWithSize: sizeof(char16_t)
				  count: length * 2];
	@try {
		DWORD written;
		DWORD bytesWritten;

		while (i < length) {
			of_unichar_t c;
			ssize_t UTF8Len;

			UTF8Len = of_string_utf8_decode(buffer + i, length - i,
			    &c);
319
320
321
322
323
324
325
326
327








328
329
330

331

332
333
334
335
336
327
328
329
330
331
332
333


334
335
336
337
338
339
340
341
342
343
344
345

346
347
348
349
350
351







-
-
+
+
+
+
+
+
+
+



+
-
+






			i += UTF8Len;
		}

		if (j > UINT32_MAX)
			@throw [OFOutOfRangeException exception];

		if (!WriteConsoleW(_handle, tmp, (DWORD)j, &written, NULL) ||
		    written != j)
		if (!WriteConsoleW(_handle, tmp, (DWORD)j, &bytesWritten, NULL))
			@throw [OFWriteFailedException
			    exceptionWithObject: self
				requestedLength: j * 2
				   bytesWritten: 0
					  errNo: EIO];

		if (bytesWritten != j)
			@throw [OFWriteFailedException
			    exceptionWithObject: self
				requestedLength: j * 2
				   bytesWritten: bytesWritten * 2
					  errNo: EIO];
					  errNo: 0];
	} @finally {
		[self freeMemory: tmp];
	}
}
@end