ObjFW  Diff

Differences From Artifact [01349f1730]:

To Artifact [0662c30238]:


1
2
3
4

5
6
7
8
9
10
11
1



2
3
4
5
6
7
8
9

-
-
-
+







/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019, 2020
 *   Jonathan Schleifer <js@nil.im>
 * Copyright (c) 2008-2021 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.
 *
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137
120
121
122
123
124
125
126

127

128
129
130
131
132
133
134







-
+
-







		[self release];
		@throw e;
	}

	return self;
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer_
- (size_t)lowlevelReadIntoBuffer: (void *)buffer_ length: (size_t)length
			  length: (size_t)length
{
	void *pool = objc_autoreleasePoolPush();
	char *buffer = buffer_;
	of_char16_t *UTF16;
	size_t j = 0;

	if (length > UINT32_MAX)
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
203
185
186
187
188
189
190
191

192

193
194
195
196
197
198
199







-
+
-







			if (UTF8Len <= length) {
				memcpy(buffer, UTF8, UTF8Len);
				j += UTF8Len;
			} else {
				if (rest == nil)
					rest = [OFMutableData data];

				[rest addItems: UTF8
				[rest addItems: UTF8 count: UTF8Len];
					 count: UTF8Len];
			}

			_incompleteUTF16Surrogate = 0;
			i++;
		}

		for (; i < UTF16Len; i++) {
246
247
248
249
250
251
252
253

254
255
256
257
258
259

260
261
262
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278
242
243
244
245
246
247
248

249

250
251
252
253

254

255
256
257
258
259
260
261
262
263

264

265
266
267
268
269
270
271







-
+
-




-
+
-









-
+
-







			if (j + UTF8Len <= length) {
				memcpy(buffer + j, UTF8, UTF8Len);
				j += UTF8Len;
			} else {
				if (rest == nil)
					rest = [OFMutableData data];

				[rest addItems: UTF8
				[rest addItems: UTF8 count: UTF8Len];
					 count: UTF8Len];
			}
		}

		if (rest != nil)
			[self unreadFromBuffer: rest.items
			[self unreadFromBuffer: rest.items length: rest.count];
					length: rest.count];
	} @finally {
		free(UTF16);
	}

	objc_autoreleasePoolPop(pool);

	return j;
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer_
- (size_t)lowlevelWriteBuffer: (const void *)buffer_ length: (size_t)length
		       length: (size_t)length
{
	const char *buffer = buffer_;
	of_char16_t *tmp;
	size_t i = 0, j = 0;

	if (length > SIZE_MAX / 2)
		@throw [OFOutOfRangeException exception];
489
490
491
492
493
494
495
496

497
498
499
500
501
502
503
504
505
506
482
483
484
485
486
487
488

489



490
491
492
493
494
495
496







-
+
-
-
-








	if (!GetConsoleScreenBufferInfo(_handle, &csbi))
		return;

	csbi.wAttributes &= ~(FOREGROUND_RED | FOREGROUND_GREEN |
	    FOREGROUND_BLUE | FOREGROUND_INTENSITY);

	[color getRed: &red
	[color getRed: &red green: &green blue: &blue alpha: NULL];
		green: &green
		 blue: &blue
		alpha: NULL];

	if (red >= 0.25)
		csbi.wAttributes |= FOREGROUND_RED;
	if (green >= 0.25)
		csbi.wAttributes |= FOREGROUND_GREEN;
	if (blue >= 0.25)
		csbi.wAttributes |= FOREGROUND_BLUE;
518
519
520
521
522
523
524
525

526
527
528
529
530
531
532
533
534
535
508
509
510
511
512
513
514

515



516
517
518
519
520
521
522







-
+
-
-
-








	if (!GetConsoleScreenBufferInfo(_handle, &csbi))
		return;

	csbi.wAttributes &= ~(BACKGROUND_RED | BACKGROUND_GREEN |
	    BACKGROUND_BLUE | BACKGROUND_INTENSITY);

	[color getRed: &red
	[color getRed: &red green: &green blue: &blue alpha: NULL];
		green: &green
		 blue: &blue
		alpha: NULL];

	if (red >= 0.25)
		csbi.wAttributes |= BACKGROUND_RED;
	if (green >= 0.25)
		csbi.wAttributes |= BACKGROUND_GREEN;
	if (blue >= 0.25)
		csbi.wAttributes |= BACKGROUND_BLUE;