1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
|
|
1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2023 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
* In order to not do this when redirecting input / output to a file (as the
* file would then be read / written in the wrong encoding and break reading /
* writing binary), it checks that the handle is indeed a console.
*/
#include "config.h"
#include <assert.h>
#include <errno.h>
#include <io.h>
#import "OFWin32ConsoleStdIOStream.h"
#import "OFColor.h"
#import "OFData.h"
#import "OFStdIOStream+Private.h"
|
<
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
* In order to not do this when redirecting input / output to a file (as the
* file would then be read / written in the wrong encoding and break reading /
* writing binary), it checks that the handle is indeed a console.
*/
#include "config.h"
#include <errno.h>
#include <io.h>
#import "OFWin32ConsoleStdIOStream.h"
#import "OFColor.h"
#import "OFData.h"
#import "OFStdIOStream+Private.h"
|
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
if (_incompleteUTF8SurrogateLen < (size_t)UTF8Len)
return 0;
UTF8Len = OFUTF8StringDecode(
_incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c);
if (UTF8Len <= 0 || c > 0x10FFFF) {
assert(UTF8Len == 0 || UTF8Len < -4);
UTF16[0] = 0xFFFD;
UTF16Len = 1;
} else {
if (c > 0xFFFF) {
c -= 0x10000;
UTF16[0] = 0xD800 | (c >> 10);
|
|
|
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
if (_incompleteUTF8SurrogateLen < (size_t)UTF8Len)
return 0;
UTF8Len = OFUTF8StringDecode(
_incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c);
if (UTF8Len <= 0 || c > 0x10FFFF) {
OFAssert(UTF8Len == 0 || UTF8Len < -4);
UTF16[0] = 0xFFFD;
UTF16Len = 1;
} else {
if (c > 0xFFFF) {
c -= 0x10000;
UTF16[0] = 0xD800 | (c >> 10);
|