104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
length: (size_t)length
{
void *pool = objc_autoreleasePoolPush();
char *buffer = buffer_;
of_char16_t *UTF16;
size_t j = 0;
UTF16 = [self allocMemoryWithSize: sizeof(of_char16_t)
count: length];
@try {
DWORD UTF16Len;
OFDataArray *rest = nil;
size_t i = 0;
if (!ReadConsoleW(_handle, UTF16, length, &UTF16Len, NULL))
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length * 2];
if (UTF16Len > 0 && _incompleteUTF16Surrogate != 0) {
of_unichar_t c =
(((_incompleteUTF16Surrogate & 0x3FF) << 10) |
|
>
>
>
|
>
|
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
|
length: (size_t)length
{
void *pool = objc_autoreleasePoolPush();
char *buffer = buffer_;
of_char16_t *UTF16;
size_t j = 0;
if (length > sizeof(UINT32_MAX))
@throw [OFOutOfRangeException exception];
UTF16 = [self allocMemoryWithSize: sizeof(of_char16_t)
count: length];
@try {
DWORD UTF16Len;
OFDataArray *rest = nil;
size_t i = 0;
if (!ReadConsoleW(_handle, UTF16, (DWORD)length, &UTF16Len,
NULL))
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length * 2];
if (UTF16Len > 0 && _incompleteUTF16Surrogate != 0) {
of_unichar_t c =
(((_incompleteUTF16Surrogate & 0x3FF) << 10) |
|
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
if (length > SIZE_MAX / 2)
@throw [OFOutOfRangeException exception];
if (_incompleteUTF8SurrogateLen > 0) {
of_unichar_t c;
of_char16_t UTF16[2];
ssize_t UTF8Len;
size_t toCopy, UTF16Len;
DWORD written;
UTF8Len = -of_string_utf8_decode(
_incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c);
OF_ENSURE(UTF8Len > 0);
toCopy = UTF8Len - _incompleteUTF8SurrogateLen;
|
|
|
|
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
if (length > SIZE_MAX / 2)
@throw [OFOutOfRangeException exception];
if (_incompleteUTF8SurrogateLen > 0) {
of_unichar_t c;
of_char16_t UTF16[2];
ssize_t UTF8Len;
size_t toCopy;
DWORD UTF16Len, written;
UTF8Len = -of_string_utf8_decode(
_incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c);
OF_ENSURE(UTF8Len > 0);
toCopy = UTF8Len - _incompleteUTF8SurrogateLen;
|
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
tmp[j++] = 0xDC00 | (c & 0x3FF);
} else
tmp[j++] = c;
i += UTF8Len;
}
if (!WriteConsoleW(_handle, tmp, j, &written, NULL) ||
written != j)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: j * 2];
} @finally {
[self freeMemory: tmp];
}
}
@end
|
>
>
>
|
|
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
tmp[j++] = 0xDC00 | (c & 0x3FF);
} else
tmp[j++] = c;
i += UTF8Len;
}
if (j > UINT32_MAX)
@throw [OFOutOfRangeException exception];
if (!WriteConsoleW(_handle, tmp, (DWORD)j, &written, NULL) ||
written != j)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: j * 2];
} @finally {
[self freeMemory: tmp];
}
}
@end
|