ObjFW  Check-in [a0fd103a0b]

Overview
Comment:Style change: Allow more than 1 argument per line

This is only migrating some places, others will be migrated as they are
touched.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a0fd103a0b249026bf013c8d984ab961f4d20efbfe4844a6b6aa5c620baac250
User & Date: js on 2021-03-07 02:36:04
Other Links: manifest | tags
Context
2021-03-07
15:07
*.h: Fold methods into one line where it fits check-in: 1948e7e972 user: js tags: trunk
02:36
Style change: Allow more than 1 argument per line check-in: a0fd103a0b user: js tags: trunk
01:53
Remove useless *Value from selector names check-in: b0b5eff396 user: js tags: trunk
Changes

Modified src/OFApplication.m from [8bb94e9bd1] to [84a11f1539].

256
257
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
256
257
258
259
260
261
262


263

264
265
266
267
268
269
270







-
-
+
-







					    "Warning: Invalid environment "
					    "variable: %s\n", tmp.UTF8String);
					continue;
				}

				key = [tmp substringToIndex: pos];
				value = [tmp substringFromIndex: pos + 1];

				[_environment setObject: value
				[_environment setObject: value forKey: key];
						 forKey: key];

				objc_autoreleasePoolPop(pool);
			}

			FreeEnvironmentStringsW(env0);
		} else {
			char *env, *env0;
300
301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
316
298
299
300
301
302
303
304


305

306
307
308
309
310
311
312







-
-
+
-







					    "Warning: Invalid environment "
					    "variable: %s\n", tmp.UTF8String);
					continue;
				}

				key = [tmp substringToIndex: pos];
				value = [tmp substringFromIndex: pos + 1];

				[_environment setObject: value
				[_environment setObject: value forKey: key];
						 forKey: key];

				objc_autoreleasePoolPop(pool);
			}

			FreeEnvironmentStringsA(env0);
		}
#elif defined(OF_AMIGAOS)
336
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351
332
333
334
335
336
337
338

339

340
341
342
343
344
345
346







-
+
-







				continue;

			file = [OFFile fileWithPath: path
					       mode: @"r"];

			value = [file readLineWithEncoding: encoding];
			if (value != nil)
				[_environment setObject: value
				[_environment setObject: value forKey: name];
						 forKey: name];

			objc_autoreleasePoolPop(pool2);
		}

		/* Local variables override global variables */
		proc = (struct Process *)FindTask(NULL);
		firstLocalVar = (struct LocalVar *)proc->pr_LocalVars.mlh_Head;
370
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386
365
366
367
368
369
370
371


372

373
374
375
376
377
378
379







-
-
+
-








			key = [OFString stringWithCString: iter->lv_Node.ln_Name
						 encoding: encoding];
			value = [OFString
			    stringWithCString: (const char *)iter->lv_Value
				     encoding: encoding
				       length: length];

			[_environment setObject: value
			[_environment setObject: value forKey: key];
					 forKey: key];
		}

		objc_autoreleasePoolPop(pool);
#elif !defined(OF_IOS)
# ifndef OF_MACOS
		char **env = environ;
# else
405
406
407
408
409
410
411
412
413

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434

435
436
437
438
439
440
441

442
443
444
445
446
447
448

449
450
451
452
453
454
455

456
457
458
459
460
461
462

463
464
465
466
467
468
469
470
398
399
400
401
402
403
404


405

406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424

425

426
427
428
429
430

431

432
433
434
435
436

437

438
439
440
441
442

443

444
445
446
447
448

449

450
451
452
453
454
455
456







-
-
+
-



















-
+
-





-
+
-





-
+
-





-
+
-





-
+
-







				key = [OFString
				    stringWithCString: *env
					     encoding: encoding
					       length: sep - *env];
				value = [OFString
				    stringWithCString: sep + 1
					     encoding: encoding];

				[_environment setObject: value
				[_environment setObject: value forKey: key];
						 forKey: key];

				objc_autoreleasePoolPop(pool);
			}
		}
#else
		/*
		 * iOS does not provide environ and Apple does not allow using
		 * _NSGetEnviron on iOS. Therefore, we just get a few common
		 * variables from the environment which applications might
		 * expect.
		 */

		void *pool = objc_autoreleasePoolPush();
		char *env;

		if ((env = getenv("HOME")) != NULL) {
			OFString *home = [[[OFString alloc]
			    initWithUTF8StringNoCopy: env
					freeWhenDone: false] autorelease];
			[_environment setObject: home
			[_environment setObject: home forKey: @"HOME"];
					 forKey: @"HOME"];
		}
		if ((env = getenv("PATH")) != NULL) {
			OFString *path = [[[OFString alloc]
			    initWithUTF8StringNoCopy: env
					freeWhenDone: false] autorelease];
			[_environment setObject: path
			[_environment setObject: path forKey: @"PATH"];
					 forKey: @"PATH"];
		}
		if ((env = getenv("SHELL")) != NULL) {
			OFString *shell = [[[OFString alloc]
			    initWithUTF8StringNoCopy: env
					freeWhenDone: false] autorelease];
			[_environment setObject: shell
			[_environment setObject: shell forKey: @"SHELL"];
					 forKey: @"SHELL"];
		}
		if ((env = getenv("TMPDIR")) != NULL) {
			OFString *tmpdir = [[[OFString alloc]
			    initWithUTF8StringNoCopy: env
					freeWhenDone: false] autorelease];
			[_environment setObject: tmpdir
			[_environment setObject: tmpdir forKey: @"TMPDIR"];
					 forKey: @"TMPDIR"];
		}
		if ((env = getenv("USER")) != NULL) {
			OFString *user = [[[OFString alloc]
			    initWithUTF8StringNoCopy: env
					freeWhenDone: false] autorelease];
			[_environment setObject: user
			[_environment setObject: user forKey: @"USER"];
					 forKey: @"USER"];
		}

		objc_autoreleasePoolPop(pool);
#endif

		[_environment makeImmutable];
	} @catch (id e) {

Modified src/OFArray.h from [a47af03a06] to [134eddeab8].

250
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265
250
251
252
253
254
255
256

257

258
259
260
261
262
263
264







-
+
-







 * @ref setValue:forKey: is called for each object in the array.
 *
 * @note A @ref OFNull value is translated to nil!
 *
 * @param value The value for the specified key
 * @param key The key of the value to set
 */
- (void)setValue: (nullable id)value
- (void)setValue: (nullable id)value forKey: (OFString *)key;
	  forKey: (OFString *)key;

/**
 * @brief Copies the objects at the specified range to the specified buffer.
 *
 * @param buffer The buffer to copy the objects to
 * @param range The range to copy
 */

Modified src/OFArray.m from [1f1150d009] to [e8aa9a3165].

191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206
191
192
193
194
195
196
197

198

199
200
201
202
203
204
205







-
+
-








- (instancetype)initWithObjects: (id)firstObject, ...
{
	id ret;
	va_list arguments;

	va_start(arguments, firstObject);
	ret = [self initWithObject: firstObject
	ret = [self initWithObject: firstObject arguments: arguments];
			 arguments: arguments];
	va_end(arguments);

	return ret;
}

- (instancetype)initWithObject: (id)firstObject
		     arguments: (va_list)arguments
238
239
240
241
242
243
244
245

246
247
248
249
250
251
252
253
237
238
239
240
241
242
243

244

245
246
247
248
249
250
251







-
+
-








- (id const *)objects
{
	size_t count = self.count;
	id *buffer = of_alloc(count, sizeof(id));

	@try {
		[self getObjects: buffer
		[self getObjects: buffer inRange: of_range(0, count)];
			 inRange: of_range(0, count)];

		return [[OFData dataWithItemsNoCopy: buffer
					      count: count
					   itemSize: sizeof(id)
				       freeWhenDone: true] items];
	} @catch (id e) {
		free(buffer);
294
295
296
297
298
299
300
301

302
303
304
305

306
307
308
309
310
311
312
313
292
293
294
295
296
297
298

299

300
301

302

303
304
305
306
307
308
309







-
+
-


-
+
-







	}

	[ret makeImmutable];

	return ret;
}

- (void)setValue: (id)value
- (void)setValue: (id)value forKey: (OFString *)key
	  forKey: (OFString *)key
{
	for (id object in self)
		[object setValue: value
		[object setValue: value forKey: key];
			  forKey: key];
}

- (size_t)indexOfObject: (id)object
{
	size_t i = 0;

	if (object == nil)
374
375
376
377
378
379
380
381

382
383
384
385
386

387
388
389

390
391
392
393
394
395
396
397
370
371
372
373
374
375
376

377

378
379
380

381

382

383

384
385
386
387
388
389
390







-
+
-



-
+
-

-
+
-







	id *buffer;

	if (range.length > SIZE_MAX - range.location ||
	    range.location + range.length < self.count)
		@throw [OFOutOfRangeException exception];

	if (![self isKindOfClass: [OFMutableArray class]])
		return [OFSubarray arrayWithArray: self
		return [OFSubarray arrayWithArray: self range: range];
					    range: range];

	buffer = of_alloc(range.length, sizeof(*buffer));
	@try {
		[self getObjects: buffer
		[self getObjects: buffer inRange: range];
			 inRange: range];

		ret = [OFArray arrayWithObjects: buffer
		ret = [OFArray arrayWithObjects: buffer count: range.length];
					  count: range.length];
	} @finally {
		free(buffer);
	}

	return ret;
}

536
537
538
539
540
541
542
543

544
545
546
547
548
549
550
551
529
530
531
532
533
534
535

536

537
538
539
540
541
542
543







-
+
-







		return @"()";

	pool = objc_autoreleasePoolPush();
	ret = [[self componentsJoinedByString: @",\n"] mutableCopy];

	@try {
		[ret prependString: @"(\n"];
		[ret replaceOccurrencesOfString: @"\n"
		[ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"];
				     withString: @"\n\t"];
		[ret appendString: @"\n)"];
	} @catch (id e) {
		[ret release];
		@throw e;
	}

	objc_autoreleasePoolPop(pool);
580
581
582
583
584
585
586
587

588
589
590
591
592
593

594
595
596
597
598
599
600
601
572
573
574
575
576
577
578

579

580
581
582
583

584

585
586
587
588
589
590
591







-
+
-




-
+
-







	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}

- (OFString *)JSONRepresentation
{
	return [self of_JSONRepresentationWithOptions: 0
	return [self of_JSONRepresentationWithOptions: 0 depth: 0];
						depth: 0];
}

- (OFString *)JSONRepresentationWithOptions: (int)options
{
	return [self of_JSONRepresentationWithOptions: options
	return [self of_JSONRepresentationWithOptions: options depth: 0];
						depth: 0];
}

- (OFString *)of_JSONRepresentationWithOptions: (int)options
					 depth: (size_t)depth
{
	OFMutableString *JSON = [OFMutableString stringWithString: @"["];
	void *pool = objc_autoreleasePoolPush();
665
666
667
668
669
670
671
672

673
674
675
676
677
678
679

680
681
682
683
684
685
686
687
688
689
690
691
692
693
694

695
696
697
698
699
700
701
702
655
656
657
658
659
660
661

662

663
664
665
666
667

668

669
670
671
672
673
674
675
676
677
678
679
680
681

682

683
684
685
686
687
688
689







-
+
-





-
+
-













-
+
-







		uint8_t tmp = 0x90 | ((uint8_t)count & 0xF);
		[data addItem: &tmp];
	} else if (count <= UINT16_MAX) {
		uint8_t type = 0xDC;
		uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)count);

		[data addItem: &type];
		[data addItems: &tmp
		[data addItems: &tmp count: sizeof(tmp)];
			 count: sizeof(tmp)];
	} else if (count <= UINT32_MAX) {
		uint8_t type = 0xDD;
		uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)count);

		[data addItem: &type];
		[data addItems: &tmp
		[data addItems: &tmp count: sizeof(tmp)];
			 count: sizeof(tmp)];
	} else
		@throw [OFOutOfRangeException exception];

	pool = objc_autoreleasePoolPush();

	i = 0;
	for (id object in self) {
		void *pool2 = objc_autoreleasePoolPush();
		OFData *child;

		i++;

		child = [object messagePackRepresentation];
		[data addItems: child.items
		[data addItems: child.items count: child.count];
			 count: child.count];

		objc_autoreleasePoolPop(pool2);
	}

	assert(i == count);

	[data makeImmutable];
712
713
714
715
716
717
718
719

720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739

740
741
742
743
744
745
746
747
748
749
750
751
752
753

754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785

786
787
788
789
790
791
792
793
699
700
701
702
703
704
705

706

707
708
709
710
711

712

713

714
715
716
717
718
719
720


721


722

723
724
725
726
727
728
729
730


731


732

733
734
735
736
737
738
739

740

741

742
743
744
745
746
747
748
749
750
751
752
753
754
755
756

757

758
759
760
761
762
763
764







-
+
-





-

-

-







-
-
+
-
-

-








-
-
+
-
-

-







-

-

-















-
+
-







		[object performSelector: selector];
}

- (void)makeObjectsPerformSelector: (SEL)selector
			withObject: (id)object
{
	for (id objectIter in self)
		[objectIter performSelector: selector
		[objectIter performSelector: selector withObject: object];
				 withObject: object];
}

- (OFArray *)sortedArray
{
	OFMutableArray *new = [[self mutableCopy] autorelease];

	[new sort];

	[new makeImmutable];

	return new;
}

- (OFArray *)sortedArrayUsingSelector: (SEL)selector
			      options: (int)options
{
	OFMutableArray *new = [[self mutableCopy] autorelease];

	[new sortUsingSelector: selector
	[new sortUsingSelector: selector options: options];
		       options: options];

	[new makeImmutable];

	return new;
}

#ifdef OF_HAVE_BLOCKS
- (OFArray *)sortedArrayUsingComparator: (of_comparator_t)comparator
				options: (int)options
{
	OFMutableArray *new = [[self mutableCopy] autorelease];

	[new sortUsingComparator: comparator
	[new sortUsingComparator: comparator options: options];
			 options: options];

	[new makeImmutable];

	return new;
}
#endif

- (OFArray *)reversedArray
{
	OFMutableArray *new = [[self mutableCopy] autorelease];

	[new reverse];

	[new makeImmutable];

	return new;
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state
			   objects: (id *)objects
			     count: (int)count
{
	of_range_t range = of_range(state->state, count);

	if (range.length > SIZE_MAX - range.location)
		@throw [OFOutOfRangeException exception];

	if (range.location + range.length > self.count)
		range.length = self.count - range.location;

	[self getObjects: objects
	[self getObjects: objects inRange: range];
		 inRange: range];

	if (range.location + range.length > ULONG_MAX)
		@throw [OFOutOfRangeException exception];

	state->state = (unsigned long)(range.location + range.length);
	state->itemsPtr = objects;
	state->mutationsPtr = (unsigned long *)self;
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867

868
869
870
871
872
873
874
875
791
792
793
794
795
796
797

798
799
800
801
802
803
804
805
806

807
808
809
810
811
812
813
814
815

816
817

818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833

834

835
836
837
838
839
840
841







-









-









-


-
















-
+
-







{
	OFMutableArray *ret;

	if (object == nil)
		@throw [OFInvalidArgumentException exception];

	ret = [[self mutableCopy] autorelease];

	[ret addObject: object];
	[ret makeImmutable];

	return ret;
}

- (OFArray *)arrayByAddingObjectsFromArray: (OFArray *)array
{
	OFMutableArray *ret = [[self mutableCopy] autorelease];

	[ret addObjectsFromArray: array];
	[ret makeImmutable];

	return ret;
}

- (OFArray *)arrayByRemovingObject: (id)object
{
	OFMutableArray *ret = [[self mutableCopy] autorelease];

	[ret removeObject: object];
	[ret makeImmutable];

	return ret;
}

#ifdef OF_HAVE_BLOCKS
- (OFArray *)mappedArrayUsingBlock: (of_array_map_block_t)block
{
	OFArray *ret;
	size_t count = self.count;
	id *tmp = of_alloc(count, sizeof(id));

	@try {
		[self enumerateObjectsUsingBlock: ^ (id object, size_t idx,
		    bool *stop) {
			tmp[idx] = block(object, idx);
		}];

		ret = [OFArray arrayWithObjects: tmp
		ret = [OFArray arrayWithObjects: tmp count: count];
					  count: count];
	} @finally {
		free(tmp);
	}

	return ret;
}

884
885
886
887
888
889
890
891

892
893
894
895
896
897
898
899
850
851
852
853
854
855
856

857

858
859
860
861
862
863
864







-
+
-








		[self enumerateObjectsUsingBlock: ^ (id object, size_t idx,
		    bool *stop) {
			if (block(object, idx))
				tmp[i++] = object;
		}];

		ret = [OFArray arrayWithObjects: tmp
		ret = [OFArray arrayWithObjects: tmp count: i];
					  count: i];
	} @finally {
		free(tmp);
	}

	return ret;
}

Modified src/OFCountedMapTableSet.m from [5101deac28] to [dc614750e5].

189
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
189
190
191
192
193
194
195

196

197
198
199
200
201
202
203
204
205
206
207
208

209

210
211
212
213
214
215
216
217
218
219
220
221
222







-
+
-












-
+
-













- (void)addObject: (id)object
{
	size_t count = (size_t)(uintptr_t)[_mapTable objectForKey: object];

	if (SIZE_MAX - count < 1 || UINTPTR_MAX - count < 1)
		@throw [OFOutOfRangeException exception];

	[_mapTable setObject: (void *)(uintptr_t)(count + 1)
	[_mapTable setObject: (void *)(uintptr_t)(count + 1) forKey: object];
		      forKey: object];
}

- (void)removeObject: (id)object
{
	size_t count = (size_t)(uintptr_t)[_mapTable objectForKey: object];

	if (count == 0)
		return;

	count--;

	if (count > 0)
		[_mapTable setObject: (void *)(uintptr_t)count
		[_mapTable setObject: (void *)(uintptr_t)count forKey: object];
			      forKey: object];
	else
		[_mapTable removeObjectForKey: object];
}

- (void)removeAllObjects
{
	[_mapTable removeAllObjects];
}

- (void)makeImmutable
{
}
@end

Modified src/OFDNSResolver.m from [9c1e2cde9e] to [46f2a3f0a5].

449
450
451
452
453
454
455
456

457
458
459
460
461
462
463
464
449
450
451
452
453
454
455

456

457
458
459
460
461
462
463







-
+
-







		    buffer, length, *i, dataLength);
		*i += dataLength;

		array = [ret objectForKey: name];

		if (array == nil) {
			array = [OFMutableArray array];
			[ret setObject: array
			[ret setObject: array forKey: name];
				forKey: name];
		}

		[array addObject: record];
	}

	objectEnumerator = [ret objectEnumerator];
	while ((array = [objectEnumerator nextObject]) != nil)
712
713
714
715
716
717
718
719

720
721
722
723
724
725
726
727
711
712
713
714
715
716
717

718

719
720
721
722
723
724
725







-
+
-








- (void)of_sendQueryForContext: (OFDNSResolverContext *)context
		   runLoopMode: (of_run_loop_mode_t)runLoopMode
{
	OFUDPSocket *sock;
	OFString *nameServer;

	[_queries setObject: context
	[_queries setObject: context forKey: context->_ID];
		     forKey: context->_ID];

	[context->_cancelTimer invalidate];
	[context->_cancelTimer release];
	context->_cancelTimer = nil;
	context->_cancelTimer = [[OFTimer alloc]
	    initWithFireDate: [OFDate dateWithTimeIntervalSinceNow:
				  context->_settings->_timeout]
736
737
738
739
740
741
742
743

744
745
746
747
748
749
750
751
734
735
736
737
738
739
740

741

742
743
744
745
746
747
748







-
+
-







	nameServer = [context->_settings->_nameServers
	    objectAtIndex: context->_nameServersIndex];

	if (context->_settings->_usesTCP) {
		OF_ENSURE(context->_TCPSocket == nil);

		context->_TCPSocket = [[OFTCPSocket alloc] init];
		[_TCPQueries setObject: context
		[_TCPQueries setObject: context forKey: context->_TCPSocket];
				forKey: context->_TCPSocket];

		context->_TCPSocket.delegate = self;
		[context->_TCPSocket asyncConnectToHost: nameServer
						   port: 53
					    runLoopMode: runLoopMode];
		return;
	}

Modified src/OFDNSResolverSettings.m from [85c752af7f] to [ace801f6de].

284
285
286
287
288
289
290
291

292
293
294
295
296
297
298
299
284
285
286
287
288
289
290

291

292
293
294
295
296
297
298







-
+
-








		for (OFString *host in hosts) {
			OFMutableArray *addresses =
			    [staticHosts objectForKey: host];

			if (addresses == nil) {
				addresses = [OFMutableArray array];
				[staticHosts setObject: addresses
				[staticHosts setObject: addresses forKey: host];
						forKey: host];
			}

			[addresses addObject: address];
		}
	}
	for (OFMutableArray *addresses in [staticHosts objectEnumerator])
		[addresses makeImmutable];
488
489
490
491
492
493
494
495

496
497
498
499
500
501
502
503
487
488
489
490
491
492
493

494

495
496
497
498
499
500
501







-
+
-








		for (OFString *host in hosts) {
			OFMutableArray *addresses =
			    [staticHosts objectForKey: host];

			if (addresses == nil) {
				addresses = [OFMutableArray array];
				[staticHosts setObject: addresses
				[staticHosts setObject: addresses forKey: host];
						forKey: host];
			}

			[addresses addObject: address];
		}
	}
	for (OFMutableArray *addresses in [staticHosts objectEnumerator])
		[addresses makeImmutable];

Modified src/OFData+MessagePackParsing.m from [0f8a367f42] to [f67dfe7d8e].

114
115
116
117
118
119
120
121

122
123
124
125
126
127
128
129
114
115
116
117
118
119
120

121

122
123
124
125
126
127
128







-
+
-







		pool = objc_autoreleasePoolPush();

		pos += parseObject(buffer + pos, length - pos, &key,
		    depthLimit);
		pos += parseObject(buffer + pos, length - pos, &value,
		    depthLimit);

		[*object setObject: value
		[*object setObject: value forKey: key];
			    forKey: key];

		objc_autoreleasePoolPop(pool);
	}

	return pos;
}

Modified src/OFDictionary.h from [c87704d4fa] to [72e24e9365].

94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
94
95
96
97
98
99
100

101

102
103
104
105
106
107
108







-
+
-







/**
 * @brief Creates a new OFDictionary with the specified key and object.
 *
 * @param key The key
 * @param object The object
 * @return A new autoreleased OFDictionary
 */
+ (instancetype)dictionaryWithObject: (ObjectType)object
+ (instancetype)dictionaryWithObject: (ObjectType)object forKey: (KeyType)key;
			      forKey: (KeyType)key;

/**
 * @brief Creates a new OFDictionary with the specified keys and objects.
 *
 * @param keys An array of keys
 * @param objects An array of objects
 * @return A new autoreleased OFDictionary
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
163
147
148
149
150
151
152
153

154

155
156
157
158
159
160
161







-
+
-







 * @brief Initializes an already allocated OFDictionary with the specified key
 *	  and object.
 *
 * @param key The key
 * @param object The object
 * @return An initialized OFDictionary
 */
- (instancetype)initWithObject: (ObjectType)object
- (instancetype)initWithObject: (ObjectType)object forKey: (KeyType)key;
			forKey: (KeyType)key;

/**
 * @brief Initializes an already allocated OFDictionary with the specified keys
 *	  and objects.
 *
 * @param keys An array of keys
 * @param objects An array of objects
192
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
190
191
192
193
194
195
196

197

198
199
200
201
202
203
204







-
+
-







 * @brief Initializes an already allocated OFDictionary with the specified key
 *	  and va_list.
 *
 * @param firstKey The first key
 * @param arguments A va_list of the other arguments
 * @return An initialized OFDictionary
 */
- (instancetype)initWithKey: (KeyType)firstKey
- (instancetype)initWithKey: (KeyType)firstKey arguments: (va_list)arguments;
		  arguments: (va_list)arguments;

/**
 * @brief Returns the object for the given key or `nil` if the key was not
 *	  found.
 *
 * @warning The returned object is *not* retained and autoreleased for
 *	    performance reasons!
230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245
227
228
229
230
231
232
233

234

235
236
237
238
239
240
241







-
+
-







 *
 * This is equivalent to OFMutableDictionary#setObject:forKey:. If the
 * dictionary is immutable, an @ref OFUndefinedKeyException is thrown.
 *
 * @param key The key to set
 * @param value The value to set the key to
 */
- (void)setValue: (nullable id)value
- (void)setValue: (nullable id)value forKey: (OFString *)key;
	  forKey: (OFString *)key;

/**
 * @brief Checks whether the dictionary contains an object equal to the
 *	  specified object.
 *
 * @param object The object which is checked for being in the dictionary
 * @return A boolean whether the dictionary contains the specified object

Modified src/OFDictionary.m from [acad8576d1] to [dca613f5bc].

290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305
290
291
292
293
294
295
296

297

298
299
300
301
302
303
304







-
+
-







{
	if (key == nil || object == nil)
		@throw [OFInvalidArgumentException exception];

	return [self initWithKeysAndObjects: key, object, nil];
}

- (instancetype)initWithObjects: (OFArray *)objects_
- (instancetype)initWithObjects: (OFArray *)objects_ forKeys: (OFArray *)keys_
			forKeys: (OFArray *)keys_
{
	id const *objects, *keys;
	size_t count;

	@try {
		count = objects_.count;

334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
349
333
334
335
336
337
338
339

340

341
342
343
344
345
346
347







-
+
-







	ret = [self initWithKey: firstKey
		      arguments: arguments];
	va_end(arguments);

	return ret;
}

- (instancetype)initWithKey: (id)firstKey
- (instancetype)initWithKey: (id)firstKey arguments: (va_list)arguments
		  arguments: (va_list)arguments
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	OF_INVALID_INIT_METHOD
363
364
365
366
367
368
369
370

371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386
361
362
363
364
365
366
367

368

369
370
371
372
373
374

375

376
377
378
379
380
381
382







-
+
-






-
+
-







{
	if ([key isEqual: @"@count"])
		return [super valueForKey: @"count"];

	return [self objectForKey: key];
}

- (void)setValue: (id)value
- (void)setValue: (id)value forKey: (OFString *)key
	  forKey: (OFString *)key
{
	if (![self isKindOfClass: [OFMutableDictionary class]])
		@throw [OFUndefinedKeyException exceptionWithObject: self
								key: key
							      value: value];

	[(OFMutableDictionary *)self setObject: value
	[(OFMutableDictionary *)self setObject: value forKey: key];
					forKey: key];
}

- (size_t)count
{
	OF_UNRECOGNIZED_SELECTOR
}

564
565
566
567
568
569
570
571

572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588

589
590
591
592
593
594
595
596
560
561
562
563
564
565
566

567

568
569
570
571
572
573
574
575
576
577
578
579
580
581
582

583

584
585
586
587
588
589
590







-
+
-















-
+
-








- (OFDictionary *)mappedDictionaryUsingBlock: (of_dictionary_map_block_t)block
{
	OFMutableDictionary *new = [OFMutableDictionary dictionary];

	[self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object,
	    bool *stop) {
		[new setObject: block(key, object)
		[new setObject: block(key, object) forKey: key];
			forKey: key];
	}];

	[new makeImmutable];

	return new;
}

- (OFDictionary *)filteredDictionaryUsingBlock:
    (of_dictionary_filter_block_t)block
{
	OFMutableDictionary *new = [OFMutableDictionary dictionary];

	[self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object,
	    bool *stop) {
		if (block(key, object))
			[new setObject: object
			[new setObject: object forKey: key];
				forKey: key];
	}];

	[new makeImmutable];

	return new;
}
#endif
640
641
642
643
644
645
646
647

648
649
650
651
652
653
654
655
634
635
636
637
638
639
640

641

642
643
644
645
646
647
648







-
+
-







		[ret appendString: object.description];

		if (++i < count)
			[ret appendString: @";\n"];

		objc_autoreleasePoolPop(pool2);
	}
	[ret replaceOccurrencesOfString: @"\n"
	[ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"];
			     withString: @"\n\t"];
	[ret appendString: @";\n}"];

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
729
730
731
732
733
734
735
736

737
738
739
740
741
742

743
744
745
746
747
748
749
750
722
723
724
725
726
727
728

729

730
731
732
733

734

735
736
737
738
739
740
741







-
+
-




-
+
-







	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}

- (OFString *)JSONRepresentation
{
	return [self of_JSONRepresentationWithOptions: 0
	return [self of_JSONRepresentationWithOptions: 0 depth: 0];
						depth: 0];
}

- (OFString *)JSONRepresentationWithOptions: (int)options
{
	return [self of_JSONRepresentationWithOptions: options
	return [self of_JSONRepresentationWithOptions: options depth: 0];
						depth: 0];
}

- (OFString *)of_JSONRepresentationWithOptions: (int)options
					 depth: (size_t)depth
{
	OFMutableString *JSON = [OFMutableString stringWithString: @"{"];
	void *pool = objc_autoreleasePoolPush();
864
865
866
867
868
869
870
871

872
873
874
875

876
877
878
879
880
881
882
883
855
856
857
858
859
860
861

862

863
864

865

866
867
868
869
870
871
872







-
+
-


-
+
-







	    (object = [objectEnumerator nextObject]) != nil) {
		void *pool2 = objc_autoreleasePoolPush();
		OFData *child;

		i++;

		child = key.messagePackRepresentation;
		[data addItems: child.items
		[data addItems: child.items count: child.count];
			 count: child.count];

		child = object.messagePackRepresentation;
		[data addItems: child.items
		[data addItems: child.items count: child.count];
			 count: child.count];

		objc_autoreleasePoolPop(pool2);
	}

	assert(i == count);

	[data makeImmutable];

Modified src/OFFile.h from [7be975c2e8] to [0d44e2d4f4].

59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95
59
60
61
62
63
64
65

66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

86

87
88
89
90
91
92
93







-
+
-



















-
+
-







 *	       `wx`           | Write-only, create or fail, exclusive
 *	       `w+`           | Read-write, create or truncate
 *	       `w+x`          | Read-write, create or fail, exclusive
 *	       `a`            | Write-only, create or append
 *	       `a+`           | Read-write, create or append
 * @return A new autoreleased OFFile
 */
+ (instancetype)fileWithPath: (OFString *)path
+ (instancetype)fileWithPath: (OFString *)path mode: (OFString *)mode;
			mode: (OFString *)mode;

/**
 * @brief Creates a new OFFile with the specified URL and mode.
 *
 * @param URL The URL to the file to open
 * @param mode The mode in which the file should be opened.@n
 *	       Possible modes are:
 *	       Mode           | Description
 *	       ---------------|-------------------------------------
 *	       `r`            | Read-only
 *	       `r+`           | Read-write
 *	       `w`            | Write-only, create or truncate
 *	       `wx`           | Write-only, create or fail, exclusive
 *	       `w+`           | Read-write, create or truncate
 *	       `w+x`          | Read-write, create or fail, exclusive
 *	       `a`            | Write-only, create or append
 *	       `a+`           | Read-write, create or append
 * @return A new autoreleased OFFile
 */
+ (instancetype)fileWithURL: (OFURL *)URL
+ (instancetype)fileWithURL: (OFURL *)URL mode: (OFString *)mode;
		       mode: (OFString *)mode;

/**
 * @brief Creates a new OFFile with the specified native file handle.
 *
 * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this
 *		 is a file descriptor. The handle is closed when the OFFile
 *		 object is deallocated!
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
115
116
117
118
119
120
121

122

123
124
125
126
127
128
129







-
+
-







 *	       `wb+` or `w+b` | read-write, create, truncate, binary
 *	       `a`            | write-only, create, append
 *	       `ab`           | write-only, create, append, binary
 *	       `a+`           | read-write, create, append
 *	       `ab+` or `a+b` | read-write, create, append, binary
 * @return An initialized OFFile
 */
- (instancetype)initWithPath: (OFString *)path
- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode;
			mode: (OFString *)mode;

/**
 * @brief Initializes an already allocated OFFile.
 *
 * @param URL The URL to the file to open
 * @param mode The mode in which the file should be opened.@n
 *	       Possible modes are:
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
139
140
141
142
143
144
145

146

147
148
149
150
151
152
153







-
+
-







 *	       `wb+` or `w+b` | read-write, create, truncate, binary
 *	       `a`            | write-only, create, append
 *	       `ab`           | write-only, create, append, binary
 *	       `a+`           | read-write, create, append
 *	       `ab+` or `a+b` | read-write, create, append, binary
 * @return An initialized OFFile
 */
- (instancetype)initWithURL: (OFURL *)URL
- (instancetype)initWithURL: (OFURL *)URL mode: (OFString *)mode;
		       mode: (OFString *)mode;

/**
 * @brief Initializes an already allocated OFFile.
 *
 * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this
 *		 is a file descriptor. The handle is closed when the OFFile
 *		 object is deallocated!

Modified src/OFFile.m from [6c6cb9f3db] to [1933c9d596].

178
179
180
181
182
183
184
185

186
187
188

189
190
191
192

193
194
195

196
197
198
199
200
201
202
203
204
205
206
207
208
209

210
211
212
213
214
215
216
217
178
179
180
181
182
183
184

185

186

187

188
189

190

191

192

193
194
195
196
197
198
199
200
201
202
203
204

205

206
207
208
209
210
211
212







-
+
-

-
+
-


-
+
-

-
+
-












-
+
-







#ifdef OF_NINTENDO_DS
	if (!nitroFSInit(NULL))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
#endif
}

+ (instancetype)fileWithPath: (OFString *)path
+ (instancetype)fileWithPath: (OFString *)path mode: (OFString *)mode
			mode: (OFString *)mode
{
	return [[[self alloc] initWithPath: path
	return [[[self alloc] initWithPath: path mode: mode] autorelease];
				      mode: mode] autorelease];
}

+ (instancetype)fileWithURL: (OFURL *)URL
+ (instancetype)fileWithURL: (OFURL *)URL mode: (OFString *)mode
		       mode: (OFString *)mode
{
	return [[[self alloc] initWithURL: URL
	return [[[self alloc] initWithURL: URL mode: mode] autorelease];
				     mode: mode] autorelease];
}

+ (instancetype)fileWithHandle: (of_file_handle_t)handle
{
	return [[[self alloc] initWithHandle: handle] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithPath: (OFString *)path
- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode
			mode: (OFString *)mode
{
	of_file_handle_t handle;

	@try {
		void *pool = objc_autoreleasePoolPush();
		int flags;

322
323
324
325
326
327
328
329

330
331
332
333
334
335
336
337
338
339
340
341
342

343
344
345
346
347
348
349
350
317
318
319
320
321
322
323

324

325
326
327
328
329
330
331
332
333
334
335

336

337
338
339
340
341
342
343







-
+
-











-
+
-







		closeHandle(handle);
		@throw e;
	}

	return self;
}

- (instancetype)initWithURL: (OFURL *)URL
- (instancetype)initWithURL: (OFURL *)URL mode: (OFString *)mode
		       mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFString *fileSystemRepresentation;

	@try {
		fileSystemRepresentation = URL.fileSystemRepresentation;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initWithPath: fileSystemRepresentation
	self = [self initWithPath: fileSystemRepresentation mode: mode];
			     mode: mode];

	objc_autoreleasePoolPop(pool);

	return self;
}

- (instancetype)initWithHandle: (of_file_handle_t)handle
360
361
362
363
364
365
366
367

368
369
370
371
372
373
374
375
353
354
355
356
357
358
359

360

361
362
363
364
365
366
367







-
+
-







{
	if (_handle == OF_INVALID_FILE_HANDLE)
		@throw [OFNotOpenException exceptionWithObject: self];

	return _atEndOfStream;
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer
- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length
			  length: (size_t)length
{
	ssize_t ret;

	if (_handle == OF_INVALID_FILE_HANDLE)
		@throw [OFNotOpenException exceptionWithObject: self];

#if defined(OF_WINDOWS)
397
398
399
400
401
402
403
404

405
406
407
408
409
410
411
412
389
390
391
392
393
394
395

396

397
398
399
400
401
402
403







-
+
-








	if (ret == 0)
		_atEndOfStream = true;

	return ret;
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer
- (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length
		       length: (size_t)length
{
	if (_handle == OF_INVALID_FILE_HANDLE)
		@throw [OFNotOpenException exceptionWithObject: self];

#if defined(OF_WINDOWS)
	int bytesWritten;

456
457
458
459
460
461
462
463

464
465
466
467
468
469
470
471
447
448
449
450
451
452
453

454

455
456
457
458
459
460
461







-
+
-







						      bytesWritten: 0
							     errNo: errno];
#endif

	return (size_t)bytesWritten;
}

- (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset
- (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset whence: (int)whence
			     whence: (int)whence
{
	of_offset_t ret;

	if (_handle == OF_INVALID_FILE_HANDLE)
		@throw [OFNotOpenException exceptionWithObject: self];

#ifndef OF_AMIGAOS

Modified src/OFFileURLHandler.m from [852391ef43] to [1adfb51735].

479
480
481
482
483
484
485
486

487
488
489
490
491
492
493
494
479
480
481
482
483
484
485

486

487
488
489
490
491
492
493







-
+
-







			       errNo: errno];

	destination = [OFString stringWithCString: destinationC
					 encoding: encoding
					   length: length];

	key = of_file_attribute_key_symbolic_link_destination;
	[attributes setObject: destination
	[attributes setObject: destination forKey: key];
		       forKey: key];
# else
	HANDLE handle;
	OFString *destination;

	if (func_CreateSymbolicLinkW == NULL)
		return;

528
529
530
531
532
533
534
535

536
537
538
539
540
541
542
543
527
528
529
530
531
532
533

534

535
536
537
538
539
540
541







-
+
-







		    stringWithUTF16String: tmp
				   length: slrb.SubstituteNameLength /
					   sizeof(wchar_t)];

		[attributes setObject: of_file_type_symbolic_link
			       forKey: of_file_attribute_key_type];
		key = of_file_attribute_key_symbolic_link_destination;
		[attributes setObject: destination
		[attributes setObject: destination forKey: key];
			       forKey: key];
#  undef slrb
	} @finally {
		CloseHandle(handle);
	}
# endif
}
#endif

Modified src/OFHTTPClient.m from [392b01fde8] to [4079ebb727].

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
187
188
189
190

191
192
193
194
195
196
197
198
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

187

188
189
190
191
192
193
194







-
+
-

-
-
+
















-
+
-










-
+
-







	if ([headers objectForKey: @"Host"] == nil) {
		OFNumber *port = URL.port;

		if (port != nil) {
			OFString *host = [OFString stringWithFormat:
			    @"%@:%@", URL.URLEncodedHost, port];

			[headers setObject: host
			[headers setObject: host forKey: @"Host"];
				    forKey: @"Host"];
		} else
			[headers setObject: [URL URLEncodedHost]
				    forKey: @"Host"];
			[headers setObject: URL.URLEncodedHost forKey: @"Host"];
	}

	if ((user.length > 0 || password.length > 0) &&
	    [headers objectForKey: @"Authorization"] == nil) {
		OFMutableData *authorizationData = [OFMutableData data];
		OFString *authorization;

		[authorizationData addItems: user.UTF8String
				      count: user.UTF8StringLength];
		[authorizationData addItem: ":"];
		[authorizationData addItems: password.UTF8String
				      count: password.UTF8StringLength];

		authorization = [OFString stringWithFormat:
		    @"Basic %@", authorizationData.stringByBase64Encoding];

		[headers setObject: authorization
		[headers setObject: authorization forKey: @"Authorization"];
			    forKey: @"Authorization"];
	}

	if ([headers objectForKey: @"User-Agent"] == nil)
		[headers setObject: @"Something using ObjFW "
				    @"<https://objfw.nil.im/>"
			    forKey: @"User-Agent"];

	if (request.protocolVersion.major == 1 &&
	    request.protocolVersion.minor == 0 &&
	    [headers objectForKey: @"Connection"] == nil)
		[headers setObject: @"keep-alive"
		[headers setObject: @"keep-alive" forKey: @"Connection"];
			    forKey: @"Connection"];

	hasContentLength = ([headers objectForKey: @"Content-Length"] != nil);
	chunked = [[headers objectForKey: @"Transfer-Encoding"]
	    isEqual: @"chunked"];

	if ((hasContentLength || chunked) &&
	    [headers objectForKey: @"Content-Type"] == nil)
532
533
534
535
536
537
538
539

540
541
542
543
544
545
546
547
528
529
530
531
532
533
534

535

536
537
538
539
540
541
542







-
+
-








	value = [OFString stringWithUTF8String: tmp];

	old = [_serverHeaders objectForKey: key];
	if (old != nil)
		value = [old stringByAppendingFormat: @",%@", value];

	[_serverHeaders setObject: value
	[_serverHeaders setObject: value forKey: key];
			   forKey: key];

	return true;
}

- (bool)stream: (OFStream *)sock
   didReadLine: (OFString *)line
     exception: (id)exception

Modified src/OFHTTPServer.m from [93f1451d06] to [038308e952].

192
193
194
195
196
197
198
199
200

201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
192
193
194
195
196
197
198


199

200
201
202
203
204
205

206

207
208
209
210
211
212
213







-
-
+
-






-
+
-







			      of_http_status_code_to_string(_statusCode)];

	headers = [[_headers mutableCopy] autorelease];

	if ([headers objectForKey: @"Date"] == nil) {
		OFString *date = [[OFDate date]
		    dateStringWithFormat: @"%a, %d %b %Y %H:%M:%S GMT"];

		[headers setObject: date
		[headers setObject: date forKey: @"Date"];
			    forKey: @"Date"];
	}

	if ([headers objectForKey: @"Server"] == nil) {
		OFString *name = _server.name;

		if (name != nil)
			[headers setObject: name
			[headers setObject: name forKey: @"Server"];
				    forKey: @"Server"];
	}

	keyEnumerator = [headers keyEnumerator];
	valueEnumerator = [headers objectEnumerator];
	while ((key = [keyEnumerator nextObject]) != nil &&
	    (value = [valueEnumerator nextObject]) != nil)
		[_socket writeFormat: @"%@: %@\r\n", key, value];
461
462
463
464
465
466
467
468

469
470
471
472
473
474
475
476
458
459
460
461
462
463
464

465

466
467
468
469
470
471
472







-
+
-







	key = normalizedKey(key.stringByDeletingTrailingWhitespaces);
	value = value.stringByDeletingLeadingWhitespaces;

	old = [_headers objectForKey: key];
	if (old != nil)
		value = [old stringByAppendingFormat: @",%@", value];

	[_headers setObject: value
	[_headers setObject: value forKey: key];
		     forKey: key];

	if ([key isEqual: @"Host"]) {
		pos = [value
		    rangeOfString: @":"
			  options: OF_STRING_SEARCH_BACKWARDS].location;

		if (pos != OF_NOT_FOUND) {

Modified src/OFLocale.m from [640d1c188f] to [f919bded41].

567
568
569
570
571
572
573
574

575
576
577
578
579
580
581
582
567
568
569
570
571
572
573

574

575
576
577
578
579
580
581







-
+
-







	OFConstantString *name;
	const char *UTF8String = NULL;
	size_t last, UTF8StringLength;
	int state = 0;

	variables = [OFMutableDictionary dictionary];
	while ((name = va_arg(arguments, OFConstantString *)) != nil)
		[variables setObject: va_arg(arguments, id)
		[variables setObject: va_arg(arguments, id) forKey: name];
			      forKey: name];

	for (OFDictionary *strings in _localizedStrings) {
		id string = [strings objectForKey: ID];

		if (string == nil)
			continue;

Modified src/OFMapTable.h from [aaa3a8b0bc] to [428b0aea8c].

158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173
158
159
160
161
162
163
164

165

166
167
168
169
170
171
172







-
+
-








/**
 * @brief Sets an object for a key.
 *
 * @param key The key to set
 * @param object The object to set the key to
 */
- (void)setObject: (nullable void *)object
- (void)setObject: (nullable void *)object forKey: (nullable void *)key;
	   forKey: (nullable void *)key;

/**
 * @brief Removes the object for the specified key from the map table.
 *
 * @param key The key whose object should be removed
 */
- (void)removeObjectForKey: (nullable void *)key;

Modified src/OFMapTable.m from [b3889238ba] to [9ddf5a7d27].

438
439
440
441
442
443
444
445

446
447
448

449
450
451
452
453
454
455
456
457
438
439
440
441
442
443
444

445

446

447


448
449
450
451
452
453
454







-
+
-

-
+
-
-







	}

	old = _buckets[i]->object;
	_buckets[i]->object = _objectFunctions.retain(object);
	_objectFunctions.release(old);
}

- (void)setObject: (void *)object
- (void)setObject: (void *)object forKey: (void *)key
	   forKey: (void *)key
{
	[self of_setObject: object
	[self of_setObject: object forKey: key hash: _keyFunctions.hash(key)];
		    forKey: key
		      hash: _keyFunctions.hash(key)];
}

- (void)removeObjectForKey: (void *)key
{
	unsigned long i, hash, last;

	if (key == NULL)

Modified src/OFMapTableDictionary.m from [300d637d78] to [0842a7ed65].

133
134
135
136
137
138
139
140

141
142
143
144
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
133
134
135
136
137
138
139

140

141
142
143
144
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







-
+
-










-
+
-




-
+
-


















-
+
-







		OFEnumerator *keyEnumerator, *objectEnumerator;
		id key, object;

		keyEnumerator = [dictionary keyEnumerator];
		objectEnumerator = [dictionary objectEnumerator];
		while ((key = [keyEnumerator nextObject]) != nil &&
		    (object = [objectEnumerator nextObject]) != nil)
			[_mapTable setObject: object
			[_mapTable setObject: object forKey: key];
				      forKey: key];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)initWithObject: (id)object
- (instancetype)initWithObject: (id)object forKey: (id)key
			forKey: (id)key
{
	self = [self initWithCapacity: 1];

	@try {
		[_mapTable setObject: object
		[_mapTable setObject: object forKey: key];
			      forKey: key];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)initWithObjects: (id const *)objects
			forKeys: (id const *)keys
			  count: (size_t)count
{
	self = [self initWithCapacity: count];

	@try {
		size_t i;

		for (i = 0; i < count; i++)
			[_mapTable setObject: objects[i]
			[_mapTable setObject: objects[i] forKey: keys[i]];
				      forKey: keys[i]];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230
231

232
233
234
235
236
237
238
239
210
211
212
213
214
215
216

217

218
219
220
221
222
223
224
225

226

227
228
229
230
231
232
233







-
+
-








-
+
-







		count /= 2;

		_mapTable = [[OFMapTable alloc]
		    initWithKeyFunctions: keyFunctions
			 objectFunctions: objectFunctions
				capacity: count];

		[_mapTable setObject: object
		[_mapTable setObject: object forKey: key];
			      forKey: key];

		for (i = 1; i < count; i++) {
			key = va_arg(arguments, id);
			object = va_arg(arguments, id);

			if (key == nil || object == nil)
				@throw [OFInvalidArgumentException exception];

			[_mapTable setObject: object
			[_mapTable setObject: object forKey: key];
				      forKey: key];
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;

Modified src/OFMapTableSet.m from [d8234d4e2f] to [61aefc4e65].

96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
111
96
97
98
99
100
101
102

103

104
105
106
107
108
109
110







-
+
-







		@throw e;
	}

	self = [self initWithCapacity: count];

	@try {
		for (id object in set)
			[_mapTable setObject: (void *)1
			[_mapTable setObject: (void *)1 forKey: object];
				      forKey: object];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
124
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
156
123
124
125
126
127
128
129

130

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

146

147
148
149
150
151
152
153







-
+
-















-
+
-







		@throw e;
	}

	self = [self initWithCapacity: count];

	@try {
		for (id object in array)
			[_mapTable setObject: (void *)1
			[_mapTable setObject: (void *)1 forKey: object];
				      forKey: object];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)initWithObjects: (id const *)objects
			  count: (size_t)count
{
	self = [self initWithCapacity: count];

	@try {
		for (size_t i = 0; i < count; i++)
			[_mapTable setObject: (void *)1
			[_mapTable setObject: (void *)1 forKey: objects[i]];
				      forKey: objects[i]];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
170
171
172
173
174
175
176
177

178
179
180
181

182
183
184
185
186
187
188
189
167
168
169
170
171
172
173

174

175
176

177

178
179
180
181
182
183
184







-
+
-


-
+
-







		for (count = 1; va_arg(argumentsCopy, id) != nil; count++);

		_mapTable = [[OFMapTable alloc]
		    initWithKeyFunctions: keyFunctions
			 objectFunctions: objectFunctions
				capacity: count];

		[_mapTable setObject: (void *)1
		[_mapTable setObject: (void *)1 forKey: firstObject];
			      forKey: firstObject];

		while ((object = va_arg(arguments, id)) != nil)
			[_mapTable setObject: (void *)1
			[_mapTable setObject: (void *)1 forKey: object];
				      forKey: object];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

Modified src/OFMutableArray.h from [55375a9442] to [16603a1ba8].

78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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
130
131
132
133
134
78
79
80
81
82
83
84

85

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

103

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
130







-
+
-

















-
+
-







-
+
-











-
+
-








/**
 * @brief Inserts an object to the OFArray at the specified index.
 *
 * @param object An object to add
 * @param index The index where the object should be inserted
 */
- (void)insertObject: (ObjectType)object
- (void)insertObject: (ObjectType)object atIndex: (size_t)index;
	     atIndex: (size_t)index;

/**
 * @brief Inserts the objects from the specified OFArray at the specified index.
 *
 * @param array An array of objects
 * @param index The index where the objects should be inserted
 */
- (void)insertObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array
		       atIndex: (size_t)index;

/**
 * @brief Replaces the first object equivalent to the specified object with the
 *	  other specified object.
 *
 * @param oldObject The object to replace
 * @param newObject The replacement object
 */
- (void)replaceObject: (ObjectType)oldObject
- (void)replaceObject: (ObjectType)oldObject withObject: (ObjectType)newObject;
	   withObject: (ObjectType)newObject;

/**
 * @brief Replaces the object at the specified index with the specified object.
 *
 * @param index The index of the object to replace
 * @param object The replacement object
 */
- (void)replaceObjectAtIndex: (size_t)index
- (void)replaceObjectAtIndex: (size_t)index withObject: (ObjectType)object;
		  withObject: (ObjectType)object;

/**
 * @brief Replaces the object at the specified index with the specified object.
 *
 * This method is the same as @ref replaceObjectAtIndex:withObject:.
 *
 * This method is also used by the subscripting syntax.
 *
 * @param index The index of the object to replace
 * @param object The replacement object
 */
-    (void)setObject: (ObjectType)object
- (void)setObject: (ObjectType)object atIndexedSubscript: (size_t)index;
  atIndexedSubscript: (size_t)index;

/**
 * @brief Replaces the first object that has the same address as the specified
 *	  object with the other specified object.
 *
 * @param oldObject The object to replace
 * @param newObject The replacement object
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

213
214
215
216
217
218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
234
182
183
184
185
186
187
188

189

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

207

208
209
210
211
212
213
214
215
216
217
218
219

220

221
222
223
224
225
226
227







-
+
-

















-
+
-












-
+
-








/**
 * @brief Exchange the objects at the specified indices.
 *
 * @param index1 The index of the first object to exchange
 * @param index2 The index of the second object to exchange
 */
- (void)exchangeObjectAtIndex: (size_t)index1
- (void)exchangeObjectAtIndex: (size_t)index1 withObjectAtIndex: (size_t)index2;
	    withObjectAtIndex: (size_t)index2;

/**
 * @brief Sorts the array in ascending order.
 */
- (void)sort;

/**
 * @brief Sorts the array using the specified selector and options.
 *
 * @param selector The selector to use to sort the array. It's signature
 *		   should be the same as that of -[compare:].
 * @param options The options to use when sorting the array.@n
 *		  Possible values are:
 *		  Value                      | Description
 *		  ---------------------------|-------------------------
 *		  `OF_ARRAY_SORT_DESCENDING` | Sort in descending order
 */
- (void)sortUsingSelector: (SEL)selector
- (void)sortUsingSelector: (SEL)selector options: (int)options;
		  options: (int)options;

#ifdef OF_HAVE_BLOCKS
/**
 * @brief Sorts the array using the specified comparator and options.
 *
 * @param comparator The comparator to use to sort the array
 * @param options The options to use when sorting the array.@n
 *		  Possible values are:
 *		  Value                      | Description
 *		  ---------------------------|-------------------------
 *		  `OF_ARRAY_SORT_DESCENDING` | Sort in descending order
 */
- (void)sortUsingComparator: (of_comparator_t)comparator
- (void)sortUsingComparator: (of_comparator_t)comparator options: (int)options;
		    options: (int)options;
#endif

/**
 * @brief Reverts the order of the objects in the array.
 */
- (void)reverse;

Modified src/OFMutableArray.m from [78bab359a3] to [72ac5c5c33].

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
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
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318

319
320
321
322
323
324
325
326
327
328
329
330

331
332
333
334
335
336
337
338
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

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
304
305
306
307

308

309
310
311
312
313
314
315
316
317
318

319

320
321
322
323
324
325
326







-
+
-




-
+
-


-
+
-




-
+
-




-
+
-


-
+
-




-
-
+

-
+
-


-
+
-










-
+
-





-
+
-










-
+
-







- (id)copy
{
	return [[OFArray alloc] initWithArray: self];
}

- (void)addObject: (id)object
{
	[self insertObject: object
	[self insertObject: object atIndex: self.count];
		   atIndex: self.count];
}

- (void)addObjectsFromArray: (OFArray *)array
{
	[self insertObjectsFromArray: array
	[self insertObjectsFromArray: array atIndex: self.count];
			     atIndex: self.count];
}

- (void)insertObject: (id)object
- (void)insertObject: (id)object atIndex: (size_t)idx
	     atIndex: (size_t)idx
{
	OF_UNRECOGNIZED_SELECTOR
}

- (void)insertObjectsFromArray: (OFArray *)array
- (void)insertObjectsFromArray: (OFArray *)array atIndex: (size_t)idx
		       atIndex: (size_t)idx
{
	size_t i = 0;

	for (id object in array)
		[self insertObject: object
		[self insertObject: object atIndex: idx + i++];
			   atIndex: idx + i++];
}

- (void)replaceObjectAtIndex: (size_t)idx
- (void)replaceObjectAtIndex: (size_t)idx withObject: (id)object
		  withObject: (id)object
{
	OF_UNRECOGNIZED_SELECTOR
}

-    (void)setObject: (id)object
  atIndexedSubscript: (size_t)idx
- (void)setObject: (id)object atIndexedSubscript: (size_t)idx
{
	[self replaceObjectAtIndex: idx
	[self replaceObjectAtIndex: idx withObject: object];
			withObject: object];
}

- (void)replaceObject: (id)oldObject
- (void)replaceObject: (id)oldObject withObject: (id)newObject
	   withObject: (id)newObject
{
	size_t count;

	if (oldObject == nil || newObject == nil)
		@throw [OFInvalidArgumentException exception];

	count = self.count;

	for (size_t i = 0; i < count; i++) {
		if ([[self objectAtIndex: i] isEqual: oldObject]) {
			[self replaceObjectAtIndex: i
			[self replaceObjectAtIndex: i withObject: newObject];
					withObject: newObject];
			return;
		}
	}
}

- (void)replaceObjectIdenticalTo: (id)oldObject
- (void)replaceObjectIdenticalTo: (id)oldObject withObject: (id)newObject
		      withObject: (id)newObject
{
	size_t count;

	if (oldObject == nil || newObject == nil)
		@throw [OFInvalidArgumentException exception];

	count = self.count;

	for (size_t i = 0; i < count; i++) {
		if ([self objectAtIndex: i] == oldObject) {
			[self replaceObjectAtIndex: i
			[self replaceObjectAtIndex: i withObject: newObject];
					withObject: newObject];

			return;
		}
	}
}

- (void)removeObjectAtIndex: (size_t)idx
401
402
403
404
405
406
407
408

409
410
411
412
413
414

415
416
417
418
419
420
421
422

423
424

425
426
427
428
429
430
431
432
433

434
435
436
437
438
439
440
441
389
390
391
392
393
394
395

396

397
398
399
400

401

402
403
404
405
406
407

408


409

410
411
412
413
414
415
416

417

418
419
420
421
422
423
424







-
+
-




-
+
-






-
+
-
-
+
-







-
+
-







- (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block
{
	[self enumerateObjectsUsingBlock: ^ (id object, size_t idx,
	    bool *stop) {
		id new = block(object, idx);

		if (new != object)
			[self replaceObjectAtIndex: idx
			[self replaceObjectAtIndex: idx withObject: new];
					withObject: new];
	}];
}
#endif

- (void)exchangeObjectAtIndex: (size_t)idx1
- (void)exchangeObjectAtIndex: (size_t)idx1 withObjectAtIndex: (size_t)idx2
	    withObjectAtIndex: (size_t)idx2
{
	id object1 = [self objectAtIndex: idx1];
	id object2 = [self objectAtIndex: idx2];

	[object1 retain];
	@try {
		[self replaceObjectAtIndex: idx1
		[self replaceObjectAtIndex: idx1 withObject: object2];
				withObject: object2];
		[self replaceObjectAtIndex: idx2
		[self replaceObjectAtIndex: idx2 withObject: object1];
				withObject: object1];
	} @finally {
		[object1 release];
	}
}

- (void)sort
{
	[self sortUsingSelector: @selector(compare:)
	[self sortUsingSelector: @selector(compare:) options: 0];
			options: 0];
}

- (void)sortUsingSelector: (SEL)selector
		  options: (int)options
{
	size_t count = self.count;

462
463
464
465
466
467
468
469

470
471
472
473
474
475
476
445
446
447
448
449
450
451

452

453
454
455
456
457
458







-
+
-






{
	size_t i, j, count = self.count;

	if (count == 0 || count == 1)
		return;

	for (i = 0, j = count - 1; i < j; i++, j--)
		[self exchangeObjectAtIndex: i
		[self exchangeObjectAtIndex: i withObjectAtIndex: j];
			  withObjectAtIndex: j];
}

- (void)makeImmutable
{
}
@end

Modified src/OFMutableDictionary.h from [995b885913] to [d0bf1761a1].

67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
67
68
69
70
71
72
73

74

75
76
77
78
79
80
81
82
83
84
85
86

87

88
89
90
91
92
93
94







-
+
-












-
+
-







 * @brief Sets an object for a key.
 *
 * A key can be any object that conforms to the OFCopying protocol.
 *
 * @param key The key to set
 * @param object The object to set the key to
 */
- (void)setObject: (ObjectType)object
- (void)setObject: (ObjectType)object forKey: (KeyType)key;
	   forKey: (KeyType)key;

/**
 * @brief Sets an object for a key.
 *
 * A key can be any object that conforms to the OFCopying protocol.
 *
 * This method is also used by the subscripting syntax.
 *
 * @param key The key to set
 * @param object The object to set the key to. If it is nil, this is equal to
 *		 calling @ref removeObjectForKey:.
 */
-   (void)setObject: (nullable ObjectType)object
- (void)setObject: (nullable ObjectType)object forKeyedSubscript: (KeyType)key;
  forKeyedSubscript: (KeyType)key;

/**
 * @brief Removes the object for the specified key from the dictionary.
 *
 * @param key The key whose object should be removed
 */
- (void)removeObjectForKey: (KeyType)key;

Modified src/OFMutableDictionary.m from [258a8f4b24] to [6a9ceedcaa].

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
152
153
154
155
156
157
158

159

160
161
162
163

164

165
166

167

168
169
170
171
172
173
174







-
+
-




-
+
-


-
+
-







}

- (instancetype)initWithCapacity: (size_t)capacity
{
	OF_INVALID_INIT_METHOD
}

- (void)setObject: (id)object
- (void)setObject: (id)object forKey: (id)key
	   forKey: (id)key
{
	OF_UNRECOGNIZED_SELECTOR
}

-   (void)setObject: (id)object
- (void)setObject: (id)object forKeyedSubscript: (id)key
  forKeyedSubscript: (id)key
{
	if (object != nil)
		[self setObject: object
		[self setObject: object forKey: key];
			 forKey: key];
	else
		[self removeObjectForKey: key];
}

- (void)removeObjectForKey: (id)key
{
	OF_UNRECOGNIZED_SELECTOR
197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
194
195
196
197
198
199
200

201

202
203
204
205
206
207
208
209
210
211
212
213

214

215
216
217
218
219
220
221
222
223







-
+
-












-
+
-









	void *pool = objc_autoreleasePoolPush();
	OFEnumerator *keyEnumerator = [dictionary keyEnumerator];
	OFEnumerator *objectEnumerator = [dictionary objectEnumerator];
	id key, object;

	while ((key = [keyEnumerator nextObject]) != nil &&
	    (object = [objectEnumerator nextObject]) != nil)
		[self setObject: object
		[self setObject: object forKey: key];
			 forKey: key];

	objc_autoreleasePoolPop(pool);
}

#ifdef OF_HAVE_BLOCKS
- (void)replaceObjectsUsingBlock: (of_dictionary_replace_block_t)block
{
	[self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object,
	    bool *stop) {
		id new = block(key, object);

		if (new != object) {
			[self setObject: block(key, object)
			[self setObject: block(key, object) forKey: key];
				 forKey: key];
		}
	}];
}
#endif

- (void)makeImmutable
{
}
@end

Modified src/OFMutableMapTableDictionary.m from [01b0a38e38] to [b27a83ce2f].

27
28
29
30
31
32
33
34

35
36
37

38
39
40
41
42
43
44
45
27
28
29
30
31
32
33

34

35

36

37
38
39
40
41
42
43







-
+
-

-
+
-







@implementation OFMutableMapTableDictionary
+ (void)initialize
{
	if (self == [OFMutableMapTableDictionary class])
		[self inheritMethodsFromClass: [OFMapTableDictionary class]];
}

- (void)setObject: (id)object
- (void)setObject: (id)object forKey: (id)key
	   forKey: (id)key
{
	[_mapTable setObject: object
	[_mapTable setObject: object forKey: key];
		      forKey: key];
}

- (void)removeObjectForKey: (id)key
{
	[_mapTable removeObjectForKey: key];
}

Modified src/OFMutableMapTableSet.m from [ece4193cc3] to [6bd4d296b2].

24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
24
25
26
27
28
29
30

31

32
33
34
35
36
37
38







-
+
-







{
	if (self == [OFMutableMapTableSet class])
		[self inheritMethodsFromClass: [OFMapTableSet class]];
}

- (void)addObject: (id)object
{
	[_mapTable setObject: (void *)1
	[_mapTable setObject: (void *)1 forKey: object];
		      forKey: object];
}

- (void)removeObject: (id)object
{
	[_mapTable removeObjectForKey: object];
}

Modified src/OFRunLoop.m from [b43754d684] to [a843dfe040].

1033
1034
1035
1036
1037
1038
1039
1040

1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059

1060
1061
1062
1063
1064
1065
1066
1067
1033
1034
1035
1036
1037
1038
1039

1040

1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057

1058

1059
1060
1061
1062
1063
1064
1065







-
+
-

















-
+
-







	OFRunLoopState *state = [runLoop of_stateForMode: mode		\
						  create: true];	\
	OFList *queue = [state->_readQueues objectForKey: object];	\
	type *queueItem;						\
									\
	if (queue == nil) {						\
		queue = [OFList list];					\
		[state->_readQueues setObject: queue			\
		[state->_readQueues setObject: queue forKey: object];	\
				       forKey: object];			\
	}								\
									\
	if (queue.count == 0)						\
		[state->_kernelEventObserver				\
		    addObjectForReading: object];			\
									\
	queueItem = [[[type alloc] init] autorelease];
# define NEW_WRITE(type, object, mode)					\
	void *pool = objc_autoreleasePoolPush();			\
	OFRunLoop *runLoop = [self currentRunLoop];			\
	OFRunLoopState *state = [runLoop of_stateForMode: mode		\
						  create: true];	\
	OFList *queue = [state->_writeQueues objectForKey: object];	\
	type *queueItem;						\
									\
	if (queue == nil) {						\
		queue = [OFList list];					\
		[state->_writeQueues setObject: queue			\
		[state->_writeQueues setObject: queue forKey: object];	\
					  forKey: object];		\
	}								\
									\
	if (queue.count == 0)						\
		[state->_kernelEventObserver				\
		    addObjectForWriting: object];			\
									\
	queueItem = [[[type alloc] init] autorelease];
1380
1381
1382
1383
1384
1385
1386
1387

1388
1389
1390
1391
1392
1393
1394
1395
1378
1379
1380
1381
1382
1383
1384

1385

1386
1387
1388
1389
1390
1391
1392







-
+
-







	@try {
#endif
		state = [_states objectForKey: mode];

		if (create && state == nil) {
			state = [[OFRunLoopState alloc] init];
			@try {
				[_states setObject: state
				[_states setObject: state forKey: mode];
					    forKey: mode];
			} @finally {
				[state release];
			}
		}
#ifdef OF_HAVE_THREADS
	} @finally {
		[_statesMutex unlock];

Modified src/OFSeekableStream.h from [5d719e292c] to [5e97908a2c].

67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
67
68
69
70
71
72
73

74

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94

95
96
97







-
+
-



















-
+
-



 *		 Value      | Description
 *		 -----------|---------------------------------------
 *		 `SEEK_SET` | Seek to the specified byte
 *		 `SEEK_CUR` | Seek to the current location + offset
 *		 `SEEK_END` | Seek to the end of the stream + offset
 * @return The new offset form the start of the file
 */
- (of_offset_t)seekToOffset: (of_offset_t)offset
- (of_offset_t)seekToOffset: (of_offset_t)offset whence: (int)whence;
		     whence: (int)whence;

/**
 * @brief Seek the stream on the lowlevel.
 *
 * @warning Do not call this directly!
 *
 * @note Override this method with your actual seek implementation when
 *	 subclassing!
 *
 * @param offset The offset to seek to
 * @param whence From where to seek.@n
 *		 Possible values are:
 *		 Value      | Description
 *		 -----------|---------------------------------------
 *		 `SEEK_SET` | Seek to the specified byte
 *		 `SEEK_CUR` | Seek to the current location + offset
 *		 `SEEK_END` | Seek to the end of the stream + offset
 * @return The new offset from the start of the file
 */
- (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset
- (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset whence: (int)whence;
			     whence: (int)whence;
@end

OF_ASSUME_NONNULL_END

Modified src/OFSeekableStream.m from [e6908a8ef1] to [4e1737f5f5].

34
35
36
37
38
39
40
41

42
43
44
45
46
47

48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
34
35
36
37
38
39
40

41

42
43
44
45

46

47
48
49
50

51

52
53
54
55
56
57
58
59







-
+
-




-
+
-




-
+
-








			@throw e;
		}
	}

	return [super init];
}

- (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset
- (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset whence: (int)whence
			     whence: (int)whence
{
	OF_UNRECOGNIZED_SELECTOR
}

- (of_offset_t)seekToOffset: (of_offset_t)offset
- (of_offset_t)seekToOffset: (of_offset_t)offset whence: (int)whence
		     whence: (int)whence
{
	if (whence == SEEK_CUR)
		offset -= _readBufferLength;

	offset = [self lowlevelSeekToOffset: offset
	offset = [self lowlevelSeekToOffset: offset whence: whence];
				     whence: whence];

	free(_readBufferMemory);
	_readBuffer = _readBufferMemory = NULL;
	_readBufferLength = 0;

	return offset;
}
@end

Modified src/OFStream.h from [d7b8ceded5] to [7fe1e202cf].

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
272
273
274
275
276
277
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
272
273
274
275







-
+
-
















-
+
-







 * result of 0 bytes.
 *
 * @param buffer The buffer into which the data is read
 * @param length The length of the data that should be read at most.
 *		 The buffer *must* be *at least* this big!
 * @return The number of bytes read
 */
- (size_t)readIntoBuffer: (void *)buffer
- (size_t)readIntoBuffer: (void *)buffer length: (size_t)length;
		  length: (size_t)length;

/**
 * @brief Reads exactly the specified length bytes from the stream into a
 *	  buffer.
 *
 * Unlike @ref readIntoBuffer:length:, this method does not return when less
 * than the specified length has been read - instead, it waits until it got
 * exactly the specified length.
 *
 * @warning Only call this when you know that specified amount of data is
 *	    available! Otherwise you will get an exception!
 *
 * @param buffer The buffer into which the data is read
 * @param length The length of the data that should be read.
 *		 The buffer *must* be *at least* this big!
 */
 - (void)readIntoBuffer: (void *)buffer
 - (void)readIntoBuffer: (void *)buffer exactLength: (size_t)length;
	    exactLength: (size_t)length;

#ifdef OF_HAVE_SOCKETS
/**
 * @brief Asynchronously reads *at most* size bytes from the stream into a
 *	  buffer.
 *
 * On network streams, this might read less than the specified number of bytes.
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
301
284
285
286
287
288
289
290

291

292
293
294
295
296
297
298







-
+
-







 *	 for this to work!
 *
 * @param buffer The buffer into which the data is read.
 *		 The buffer must not be freed before the async read completed!
 * @param length The length of the data that should be read at most.
 *		 The buffer *must* be *at least* this big!
 */
- (void)asyncReadIntoBuffer: (void *)buffer
- (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length;
		     length: (size_t)length;

/**
 * @brief Asynchronously reads *at most* size bytes from the stream into a
 *	  buffer.
 *
 * On network streams, this might read less than the specified number of bytes.
 * If you want to read exactly the specified number of bytes, use
330
331
332
333
334
335
336
337

338
339
340
341
342
343
344
345
327
328
329
330
331
332
333

334

335
336
337
338
339
340
341







-
+
-







 * @note The stream must conform to @ref OFReadyForReadingObserving in order
 *	 for this to work!
 *
 * @param buffer The buffer into which the data is read
 * @param length The length of the data that should be read.
 *		 The buffer *must* be *at least* this big!
 */
- (void)asyncReadIntoBuffer: (void *)buffer
- (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length;
		exactLength: (size_t)length;

/**
 * @brief Asynchronously reads exactly the specified length bytes from the
 *	  stream into a buffer.
 *
 * Unlike @ref asyncReadIntoBuffer:length:, this method does not call the
 * method when less than the specified length has been read - instead, it waits
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601
602
603
604
605
606
607
608

609
610
611
612
613
614
615
616
582
583
584
585
586
587
588

589

590
591
592
593
594
595
596
597
598
599
600
601
602

603

604
605
606
607
608
609
610







-
+
-













-
+
-







 *	    Otherwise you will get an exception!
 *
 * @param buffer A buffer of sufficient size to store the specified number of
 *		 floats
 * @param count The number of floats to read
 * @return The number of bytes read
 */
- (size_t)readBigEndianFloatsIntoBuffer: (float *)buffer
- (size_t)readBigEndianFloatsIntoBuffer: (float *)buffer count: (size_t)count;
				  count: (size_t)count;

/**
 * @brief Reads the specified number of doubles from the stream which are
 *	  encoded in big endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @param buffer A buffer of sufficient size to store the specified number of
 *		 doubles
 * @param count The number of doubles to read
 * @return The number of bytes read
 */
- (size_t)readBigEndianDoublesIntoBuffer: (double *)buffer
- (size_t)readBigEndianDoublesIntoBuffer: (double *)buffer count: (size_t)count;
				   count: (size_t)count;

/**
 * @brief Reads a uint16_t from the stream which is encoded in little endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
752
753
754
755
756
757
758
759

760
761
762
763
764
765
766
767
746
747
748
749
750
751
752

753

754
755
756
757
758
759
760







-
+
-







 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @param itemSize The size of each item
 * @param count The number of items to read
 * @return OFData with count items.
 */
- (OFData *)readDataWithItemSize: (size_t)itemSize
- (OFData *)readDataWithItemSize: (size_t)itemSize count: (size_t)count;
			   count: (size_t)count;

/**
 * @brief Returns OFData with all the remaining data of the stream.
 *
 * @return OFData with an item size of 1 with all the data of the stream until
 *	   the end of the stream is reached.
 */
982
983
984
985
986
987
988
989

990
991
992
993
994
995
996
997
975
976
977
978
979
980
981

982

983
984
985
986
987
988
989







-
+
-







 * @brief Writes from a buffer into the stream.
 *
 * @param buffer The buffer from which the data is written into the stream
 * @param length The length of the data that should be written
 * @return The number of bytes written. This can only differ from the specified
 *	   length in non-blocking mode.
 */
- (size_t)writeBuffer: (const void *)buffer
- (size_t)writeBuffer: (const void *)buffer length: (size_t)length;
	       length: (size_t)length;

#ifdef OF_HAVE_SOCKETS
/**
 * @brief Asynchronously writes data into the stream.
 *
 * @note The stream must conform to @ref OFReadyForWritingObserving in order
 *	 for this to work!
1184
1185
1186
1187
1188
1189
1190
1191

1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203

1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215

1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227

1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239

1240
1241
1242
1243
1244
1245
1246
1247
1176
1177
1178
1179
1180
1181
1182

1183

1184
1185
1186
1187
1188
1189
1190
1191
1192
1193

1194

1195
1196
1197
1198
1199
1200
1201
1202
1203
1204

1205

1206
1207
1208
1209
1210
1211
1212
1213
1214
1215

1216

1217
1218
1219
1220
1221
1222
1223
1224
1225
1226

1227

1228
1229
1230
1231
1232
1233
1234







-
+
-










-
+
-










-
+
-










-
+
-










-
+
-







 *	  big endian.
 *
 * @param buffer The buffer from which the data is written to the stream after
 *		 it has been byte swapped if necessary
 * @param count The number of uint16_ts to write
 * @return The number of bytes written to the stream
 */
- (size_t)writeBigEndianInt16s: (const uint16_t *)buffer
- (size_t)writeBigEndianInt16s: (const uint16_t *)buffer count: (size_t)count;
			 count: (size_t)count;

/**
 * @brief Writes the specified number of uint32_ts into the stream, encoded in
 *	  big endian.
 *
 * @param buffer The buffer from which the data is written to the stream after
 *		 it has been byte swapped if necessary
 * @param count The number of uint32_ts to write
 * @return The number of bytes written to the stream
 */
- (size_t)writeBigEndianInt32s: (const uint32_t *)buffer
- (size_t)writeBigEndianInt32s: (const uint32_t *)buffer count: (size_t)count;
			 count: (size_t)count;

/**
 * @brief Writes the specified number of uint64_ts into the stream, encoded in
 *	  big endian.
 *
 * @param buffer The buffer from which the data is written to the stream after
 *		 it has been byte swapped if necessary
 * @param count The number of uint64_ts to write
 * @return The number of bytes written to the stream
 */
- (size_t)writeBigEndianInt64s: (const uint64_t *)buffer
- (size_t)writeBigEndianInt64s: (const uint64_t *)buffer count: (size_t)count;
			 count: (size_t)count;

/**
 * @brief Writes the specified number of floats into the stream, encoded in big
 *	  endian.
 *
 * @param buffer The buffer from which the data is written to the stream after
 *		 it has been byte swapped if necessary
 * @param count The number of floats to write
 * @return The number of bytes written to the stream
 */
- (size_t)writeBigEndianFloats: (const float *)buffer
- (size_t)writeBigEndianFloats: (const float *)buffer count: (size_t)count;
			 count: (size_t)count;

/**
 * @brief Writes the specified number of doubles into the stream, encoded in
 *	  big endian.
 *
 * @param buffer The buffer from which the data is written to the stream after
 *		 it has been byte swapped if necessary
 * @param count The number of doubles to write
 * @return The number of bytes written to the stream
 */
- (size_t)writeBigEndianDoubles: (const double *)buffer
- (size_t)writeBigEndianDoubles: (const double *)buffer count: (size_t)count;
			  count: (size_t)count;

/**
 * @brief Writes a uint16_t into the stream, encoded in little endian.
 *
 * @param int16 A uint16_t
 */
- (void)writeLittleEndianInt16: (uint16_t)int16;
1315
1316
1317
1318
1319
1320
1321
1322

1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334

1335
1336
1337
1338
1339
1340
1341
1342
1302
1303
1304
1305
1306
1307
1308

1309

1310
1311
1312
1313
1314
1315
1316
1317
1318
1319

1320

1321
1322
1323
1324
1325
1326
1327







-
+
-










-
+
-







 *	  little endian.
 *
 * @param buffer The buffer from which the data is written to the stream after
 *		 it has been byte swapped if necessary
 * @param count The number of floats to write
 * @return The number of bytes written to the stream
 */
- (size_t)writeLittleEndianFloats: (const float *)buffer
- (size_t)writeLittleEndianFloats: (const float *)buffer count: (size_t)count;
			    count: (size_t)count;

/**
 * @brief Writes the specified number of doubles into the stream, encoded in
 *	  little endian.
 *
 * @param buffer The buffer from which the data is written to the stream after
 *		 it has been byte swapped if necessary
 * @param count The number of doubles to write
 * @return The number of bytes written to the stream
 */
- (size_t)writeLittleEndianDoubles: (const double *)buffer
- (size_t)writeLittleEndianDoubles: (const double *)buffer count: (size_t)count;
			     count: (size_t)count;

/**
 * @brief Writes OFData into the stream.
 *
 * @param data The OFData to write into the stream
 * @return The number of bytes written
 */
1399
1400
1401
1402
1403
1404
1405
1406

1407
1408
1409
1410
1411
1412
1413
1414
1384
1385
1386
1387
1388
1389
1390

1391

1392
1393
1394
1395
1396
1397
1398







-
+
-







 * format specifier for objects, `%C` for `of_unichar_t` and `%S` for
 * `const of_unichar_t *`.
 *
 * @param format A string used as format
 * @param arguments The arguments used in the format string
 * @return The number of bytes written
 */
- (size_t)writeFormat: (OFConstantString *)format
- (size_t)writeFormat: (OFConstantString *)format arguments: (va_list)arguments;
	    arguments: (va_list)arguments;

#ifdef OF_HAVE_SOCKETS
/**
 * @brief Cancels all pending asynchronous requests on the stream.
 */
- (void)cancelAsyncRequests;
#endif
1430
1431
1432
1433
1434
1435
1436
1437

1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459

1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474

1475
1476
1477
1478
1479
1480
1481
1482
1414
1415
1416
1417
1418
1419
1420

1421

1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441

1442

1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455

1456

1457
1458
1459
1460
1461
1462
1463







-
+
-




















-
+
-













-
+
-







 *
 * If the stream is seekable, a seek operation will discard any data which was
 * unread.
 *
 * @param buffer The buffer to unread
 * @param length The length of the buffer to unread
 */
- (void)unreadFromBuffer: (const void *)buffer
- (void)unreadFromBuffer: (const void *)buffer length: (size_t)length;
		  length: (size_t)length;

/**
 * @brief Closes the stream.
 *
 * @note If you override this, make sure to call `[super close]`!
 */
- (void)close;

/**
 * @brief Performs a lowlevel read.
 *
 * @warning Do not call this directly!
 *
 * @note Override this method with your actual read implementation when
 *	 subclassing!
 *
 * @param buffer The buffer for the data to read
 * @param length The length of the buffer
 * @return The number of bytes read
 */
- (size_t)lowlevelReadIntoBuffer: (void *)buffer
- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length;
			  length: (size_t)length;

/**
 * @brief Performs a lowlevel write.
 *
 * @warning Do not call this directly!
 *
 * @note Override this method with your actual write implementation when
 *	 subclassing!
 *
 * @param buffer The buffer with the data to write
 * @param length The length of the data to write
 * @return The number of bytes written
 */
- (size_t)lowlevelWriteBuffer: (const void *)buffer
- (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length;
		       length: (size_t)length;

/**
 * @brief Returns whether the lowlevel is at the end of the stream.
 *
 * @warning Do not call this directly!
 *
 * @note Override this method with your actual end of stream checking

Modified src/OFStream.m from [d41d938d85] to [0671a78655].

100
101
102
103
104
105
106
107

108
109
110
111
112
113

114
115
116
117
118
119
120
121
100
101
102
103
104
105
106

107

108
109
110
111

112

113
114
115
116
117
118
119







-
+
-




-
+
-







}

- (bool)lowlevelIsAtEndOfStream
{
	OF_UNRECOGNIZED_SELECTOR
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer
- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length
			  length: (size_t)length
{
	OF_UNRECOGNIZED_SELECTOR
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer
- (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length
		       length: (size_t)length
{
	OF_UNRECOGNIZED_SELECTOR
}

- (id)copy
{
	return [self retain];
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
157
158
159
160
161
162
163

164

165
166
167
168
169
170
171







-
+
-







				return length;
			} else {
				memcpy(buffer, tmp, bytesRead);
				return bytesRead;
			}
		}

		return [self lowlevelReadIntoBuffer: buffer
		return [self lowlevelReadIntoBuffer: buffer length: length];
					     length: length];
	}

	if (length >= _readBufferLength) {
		size_t ret = _readBufferLength;
		memcpy(buffer, _readBuffer, _readBufferLength);

		free(_readBufferMemory);
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
179
180
181
182
183
184
185

186

187
188
189
190
191
192
193
194
195
196
197
198
199

200

201
202
203
204
205
206
207







-
+
-













-
+
-







		_readBuffer += length;
		_readBufferLength -= length;

		return length;
	}
}

- (void)readIntoBuffer: (void *)buffer
- (void)readIntoBuffer: (void *)buffer exactLength: (size_t)length
	   exactLength: (size_t)length
{
	size_t readLength = 0;

	while (readLength < length) {
		if (self.atEndOfStream)
			@throw [OFTruncatedDataException exception];

		readLength += [self readIntoBuffer: (char *)buffer + readLength
					    length: length - readLength];
	}
}

#ifdef OF_HAVE_SOCKETS
- (void)asyncReadIntoBuffer: (void *)buffer
- (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length
		     length: (size_t)length
{
	[self asyncReadIntoBuffer: buffer
			   length: length
		      runLoopMode: of_run_loop_mode_default];
}

- (void)asyncReadIntoBuffer: (void *)buffer
222
223
224
225
226
227
228
229

230
231
232
233
234
235
236
237
217
218
219
220
221
222
223

224

225
226
227
228
229
230
231







-
+
-







				       mode: runLoopMode
# ifdef OF_HAVE_BLOCKS
				      block: NULL
# endif
				   delegate: _delegate];
}

- (void)asyncReadIntoBuffer: (void *)buffer
- (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length
		exactLength: (size_t)length
{
	[self asyncReadIntoBuffer: buffer
		      exactLength: length
		      runLoopMode: of_run_loop_mode_default];
}

- (void)asyncReadIntoBuffer: (void *)buffer
305
306
307
308
309
310
311
312
313

314
315
316
317
318
319
320
321
322
323

324
325
326
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
352
353

354
355
356
357
358
359
360
361
362
363

364
365
366
367
368
369

370
371
372
373
374
375
376
377
378
379

380
381
382
383
384
385
386
387
388
389
390

391
392
393
394
395
396
397
398
399
400

401
402
403
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418
419
420
421

422
423
424
425
426
427
428
429
430
431
432

433
434
435
436
437
438
439
440
441
442

443
444
445
446
447
448
449
450
451
452
453

454
455
456
457
458
459
460
461
462
463

464
465
466
467
468
469
470
471
472
473
474
475
476
477
478

479
480
481
482
483
484
485
486
487
488

489
490
491
492
493
494
495
496
497
498

499
500
501
502
503
504
505
506
507
508

509
510
511
512
513
514
515
516
517
518

519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555

556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576

577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597

598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618

619
620
621
622
623
624
625
626
627
628
629
630
631

632
633
634
635

636
637
638
639
640
641
642
643
644
645
646

647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669

670
671

672
673

674
675
676
677
678
679
680
681
299
300
301
302
303
304
305


306


307
308
309
310
311
312


313


314
315
316
317
318
319


320


321
322
323
324
325
326


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

354

355
356
357
358
359
360
361
362
363

364

365
366
367
368
369
370
371
372

373

374
375
376
377
378
379
380
381
382

383

384
385
386
387
388
389
390
391

392

393
394
395
396
397
398
399
400
401

402

403
404
405
406
407
408
409
410

411

412
413
414
415
416
417
418
419
420

421

422
423
424
425
426
427
428
429

430

431
432
433
434
435
436
437
438
439
440
441
442


443


444
445
446
447
448
449


450


451
452
453
454
455
456


457


458
459
460
461
462
463


464


465
466
467
468
469
470


471


472
473
474
475
476
477
478
479
480
481
482
483
484

485

486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504

505

506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524

525

526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544

545

546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564

565

566
567
568
569
570
571
572
573
574
575
576

577

578
579

580

581
582
583
584
585
586
587
588
589

590


591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610

611


612


613

614
615
616
617
618
619
620







-
-
+
-
-






-
-
+
-
-






-
-
+
-
-






-
-
+
-
-






-
-
+
-
-






-
-
+
-
-



-
+
-








-
+
-









-
+
-








-
+
-









-
+
-








-
+
-









-
+
-








-
+
-









-
+
-








-
+
-












-
-
+
-
-






-
-
+
-
-






-
-
+
-
-






-
-
+
-
-






-
-
+
-
-













-
+
-



















-
+
-



















-
+
-



















-
+
-



















-
+
-











-
+
-


-
+
-









-
+
-
-




















-
+
-
-
+
-
-
+
-







}
# endif
#endif

- (uint8_t)readInt8
{
	uint8_t ret;

	[self readIntoBuffer: (char *)&ret
	[self readIntoBuffer: (char *)&ret exactLength: 1];
		 exactLength: 1];

	return ret;
}

- (uint16_t)readBigEndianInt16
{
	uint16_t ret;

	[self readIntoBuffer: (char *)&ret
	[self readIntoBuffer: (char *)&ret exactLength: 2];
		 exactLength: 2];

	return OF_BSWAP16_IF_LE(ret);
}

- (uint32_t)readBigEndianInt32
{
	uint32_t ret;

	[self readIntoBuffer: (char *)&ret
	[self readIntoBuffer: (char *)&ret exactLength: 4];
		 exactLength: 4];

	return OF_BSWAP32_IF_LE(ret);
}

- (uint64_t)readBigEndianInt64
{
	uint64_t ret;

	[self readIntoBuffer: (char *)&ret
	[self readIntoBuffer: (char *)&ret exactLength: 8];
		 exactLength: 8];

	return OF_BSWAP64_IF_LE(ret);
}

- (float)readBigEndianFloat
{
	float ret;

	[self readIntoBuffer: (char *)&ret
	[self readIntoBuffer: (char *)&ret exactLength: 4];
		 exactLength: 4];

	return OF_BSWAP_FLOAT_IF_LE(ret);
}

- (double)readBigEndianDouble
{
	double ret;

	[self readIntoBuffer: (char *)&ret
	[self readIntoBuffer: (char *)&ret exactLength: 8];
		 exactLength: 8];

	return OF_BSWAP_DOUBLE_IF_LE(ret);
}

- (size_t)readBigEndianInt16sIntoBuffer: (uint16_t *)buffer
- (size_t)readBigEndianInt16sIntoBuffer: (uint16_t *)buffer count: (size_t)count
				  count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(uint16_t);

	[self readIntoBuffer: buffer
	[self readIntoBuffer: buffer exactLength: size];
		 exactLength: size];

#ifndef OF_BIG_ENDIAN
	for (size_t i = 0; i < count; i++)
		buffer[i] = OF_BSWAP16(buffer[i]);
#endif

	return size;
}

- (size_t)readBigEndianInt32sIntoBuffer: (uint32_t *)buffer
- (size_t)readBigEndianInt32sIntoBuffer: (uint32_t *)buffer count: (size_t)count
				  count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(uint32_t);

	[self readIntoBuffer: buffer
	[self readIntoBuffer: buffer exactLength: size];
		 exactLength: size];

#ifndef OF_BIG_ENDIAN
	for (size_t i = 0; i < count; i++)
		buffer[i] = OF_BSWAP32(buffer[i]);
#endif

	return size;
}

- (size_t)readBigEndianInt64sIntoBuffer: (uint64_t *)buffer
- (size_t)readBigEndianInt64sIntoBuffer: (uint64_t *)buffer count: (size_t)count
				  count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(uint64_t);

	[self readIntoBuffer: buffer
	[self readIntoBuffer: buffer exactLength: size];
		 exactLength: size];

#ifndef OF_BIG_ENDIAN
	for (size_t i = 0; i < count; i++)
		buffer[i] = OF_BSWAP64(buffer[i]);
#endif

	return size;
}

- (size_t)readBigEndianFloatsIntoBuffer: (float *)buffer
- (size_t)readBigEndianFloatsIntoBuffer: (float *)buffer count: (size_t)count
				  count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(float))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(float);

	[self readIntoBuffer: buffer
	[self readIntoBuffer: buffer exactLength: size];
		 exactLength: size];

#ifndef OF_FLOAT_BIG_ENDIAN
	for (size_t i = 0; i < count; i++)
		buffer[i] = OF_BSWAP_FLOAT(buffer[i]);
#endif

	return size;
}

- (size_t)readBigEndianDoublesIntoBuffer: (double *)buffer
- (size_t)readBigEndianDoublesIntoBuffer: (double *)buffer count: (size_t)count
				   count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(double))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(double);

	[self readIntoBuffer: buffer
	[self readIntoBuffer: buffer exactLength: size];
		 exactLength: size];

#ifndef OF_FLOAT_BIG_ENDIAN
	for (size_t i = 0; i < count; i++)
		buffer[i] = OF_BSWAP_DOUBLE(buffer[i]);
#endif

	return size;
}

- (uint16_t)readLittleEndianInt16
{
	uint16_t ret;

	[self readIntoBuffer: (char *)&ret
	[self readIntoBuffer: (char *)&ret exactLength: 2];
		 exactLength: 2];

	return OF_BSWAP16_IF_BE(ret);
}

- (uint32_t)readLittleEndianInt32
{
	uint32_t ret;

	[self readIntoBuffer: (char *)&ret
	[self readIntoBuffer: (char *)&ret exactLength: 4];
		 exactLength: 4];

	return OF_BSWAP32_IF_BE(ret);
}

- (uint64_t)readLittleEndianInt64
{
	uint64_t ret;

	[self readIntoBuffer: (char *)&ret
	[self readIntoBuffer: (char *)&ret exactLength: 8];
		 exactLength: 8];

	return OF_BSWAP64_IF_BE(ret);
}

- (float)readLittleEndianFloat
{
	float ret;

	[self readIntoBuffer: (char *)&ret
	[self readIntoBuffer: (char *)&ret exactLength: 4];
		 exactLength: 4];

	return OF_BSWAP_FLOAT_IF_BE(ret);
}

- (double)readLittleEndianDouble
{
	double ret;

	[self readIntoBuffer: (char *)&ret
	[self readIntoBuffer: (char *)&ret exactLength: 8];
		 exactLength: 8];

	return OF_BSWAP_DOUBLE_IF_BE(ret);
}

- (size_t)readLittleEndianInt16sIntoBuffer: (uint16_t *)buffer
				     count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(uint16_t);

	[self readIntoBuffer: buffer
	[self readIntoBuffer: buffer exactLength: size];
		 exactLength: size];

#ifdef OF_BIG_ENDIAN
	for (size_t i = 0; i < count; i++)
		buffer[i] = OF_BSWAP16(buffer[i]);
#endif

	return size;
}

- (size_t)readLittleEndianInt32sIntoBuffer: (uint32_t *)buffer
				     count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(uint32_t);

	[self readIntoBuffer: buffer
	[self readIntoBuffer: buffer exactLength: size];
		 exactLength: size];

#ifdef OF_BIG_ENDIAN
	for (size_t i = 0; i < count; i++)
		buffer[i] = OF_BSWAP32(buffer[i]);
#endif

	return size;
}

- (size_t)readLittleEndianInt64sIntoBuffer: (uint64_t *)buffer
				     count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(uint64_t);

	[self readIntoBuffer: buffer
	[self readIntoBuffer: buffer exactLength: size];
		 exactLength: size];

#ifdef OF_BIG_ENDIAN
	for (size_t i = 0; i < count; i++)
		buffer[i] = OF_BSWAP64(buffer[i]);
#endif

	return size;
}

- (size_t)readLittleEndianFloatsIntoBuffer: (float *)buffer
				     count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(float))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(float);

	[self readIntoBuffer: buffer
	[self readIntoBuffer: buffer exactLength: size];
		 exactLength: size];

#ifdef OF_FLOAT_BIG_ENDIAN
	for (size_t i = 0; i < count; i++)
		buffer[i] = OF_BSWAP_FLOAT(buffer[i]);
#endif

	return size;
}

- (size_t)readLittleEndianDoublesIntoBuffer: (double *)buffer
				      count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(double))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(double);

	[self readIntoBuffer: buffer
	[self readIntoBuffer: buffer exactLength: size];
		 exactLength: size];

#ifdef OF_FLOAT_BIG_ENDIAN
	for (size_t i = 0; i < count; i++)
		buffer[i] = OF_BSWAP_DOUBLE(buffer[i]);
#endif

	return size;
}

- (OFData *)readDataWithCount: (size_t)count
{
	return [self readDataWithItemSize: 1
	return [self readDataWithItemSize: 1 count: count];
				    count: count];
}

- (OFData *)readDataWithItemSize: (size_t)itemSize
- (OFData *)readDataWithItemSize: (size_t)itemSize count: (size_t)count
			   count: (size_t)count
{
	OFData *ret;
	char *buffer;

	if OF_UNLIKELY (count > SIZE_MAX / itemSize)
		@throw [OFOutOfRangeException exception];

	buffer = of_alloc(count, itemSize);
	@try {
		[self readIntoBuffer: buffer
		[self readIntoBuffer: buffer exactLength: count * itemSize];
			 exactLength: count * itemSize];

		ret = [OFData dataWithItemsNoCopy: buffer
					    count: count
					 itemSize: itemSize
				     freeWhenDone: true];
	} @catch (id e) {
		free(buffer);
		@throw e;
	}

	return ret;
}

- (OFData *)readDataUntilEndOfStream
{
	OFMutableData *data = [OFMutableData data];
	size_t pageSize = [OFSystemInfo pageSize];
	char *buffer = of_alloc(1, pageSize);

	@try {
		while (!self.atEndOfStream) {
			size_t length;
			size_t length =

			length = [self readIntoBuffer: buffer
			    [self readIntoBuffer: buffer length: pageSize];
					       length: pageSize];
			[data addItems: buffer
			[data addItems: buffer count: length];
				 count: length];
		}
	} @finally {
		free(buffer);
	}

	[data makeImmutable];

692
693
694
695
696
697
698
699

700
701
702

703
704
705
706
707
708
709
710
631
632
633
634
635
636
637

638



639

640
641
642
643
644
645
646







-
+
-
-
-
+
-







			  encoding: (of_string_encoding_t)encoding
{
	OFString *ret;
	char *buffer = of_alloc(length + 1, 1);
	buffer[length] = 0;

	@try {
		[self readIntoBuffer: buffer
		[self readIntoBuffer: buffer exactLength: length];
			 exactLength: length];

		ret = [OFString stringWithCString: buffer
		ret = [OFString stringWithCString: buffer encoding: encoding];
					 encoding: encoding];
	} @finally {
		free(buffer);
	}

	return ret;
}

1123
1124
1125
1126
1127
1128
1129
1130

1131
1132
1133
1134
1135
1136
1137
1138
1059
1060
1061
1062
1063
1064
1065

1066

1067
1068
1069
1070
1071
1072
1073







-
+
-







}

- (void)flushWriteBuffer
{
	if (_writeBuffer == NULL)
		return;

	[self lowlevelWriteBuffer: _writeBuffer
	[self lowlevelWriteBuffer: _writeBuffer length: _writeBufferLength];
			   length: _writeBufferLength];

	free(_writeBuffer);
	_writeBuffer = NULL;
	_writeBufferLength = 0;
}

- (size_t)writeBuffer: (const void *)buffer
1159
1160
1161
1162
1163
1164
1165
1166

1167
1168
1169
1170
1171
1172
1173
1174
1094
1095
1096
1097
1098
1099
1100

1101

1102
1103
1104
1105
1106
1107
1108







-
+
-







		return length;
	}
}

#ifdef OF_HAVE_SOCKETS
- (void)asyncWriteData: (OFData *)data
{
	[self asyncWriteData: data
	[self asyncWriteData: data runLoopMode: of_run_loop_mode_default];
		 runLoopMode: of_run_loop_mode_default];
}

- (void)asyncWriteData: (OFData *)data
	   runLoopMode: (of_run_loop_mode_t)runLoopMode
{
	OFStream <OFReadyForWritingObserving> *stream =
	    (OFStream <OFReadyForWritingObserving> *)self;
1272
1273
1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285
1286
1287

1288
1289
1290
1291
1292
1293
1294
1295

1296
1297
1298
1299
1300
1301
1302
1303

1304
1305
1306
1307
1308
1309
1310
1311

1312
1313
1314
1315
1316
1317
1318
1319

1320
1321
1322
1323

1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334

1335
1336
1337
1338
1339
1340
1341
1342
1343

1344
1345
1346
1347
1348
1349
1350
1351
1352
1353

1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364

1365
1366
1367
1368
1369
1370
1371
1372
1373

1374
1375
1376
1377
1378
1379
1380
1381
1382
1383

1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394

1395
1396
1397
1398
1399
1400
1401
1402
1403

1404
1405
1406
1407
1408
1409
1410
1411
1412
1413

1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424

1425
1426
1427
1428
1429
1430
1431
1432
1433

1434
1435
1436
1437
1438
1439
1440
1441
1442
1443

1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454

1455
1456
1457
1458
1459
1460
1461
1462
1463

1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477

1478
1479
1480
1481
1482
1483
1484
1485

1486
1487
1488
1489
1490
1491
1492
1493

1494
1495
1496
1497
1498
1499
1500
1501

1502
1503
1504
1505
1506
1507
1508
1509

1510
1511
1512
1513

1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524

1525
1526
1527
1528
1529
1530
1531
1532
1533

1534
1535
1536
1537
1538
1539
1540
1541
1542
1543

1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554

1555
1556
1557
1558
1559
1560
1561
1562
1563

1564
1565
1566
1567
1568
1569
1570
1571
1572
1573

1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584

1585
1586
1587
1588
1589
1590
1591
1592
1593

1594
1595
1596
1597
1598
1599
1600
1601
1602
1603

1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614

1615
1616
1617
1618
1619
1620
1621
1622
1623

1624
1625
1626
1627
1628
1629
1630
1631
1632
1633

1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644

1645
1646
1647
1648
1649
1650
1651
1652
1653

1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673

1674

1675
1676
1677
1678
1679
1680
1681
1682
1683
1684

1685
1686
1687
1688
1689
1690
1691
1692
1206
1207
1208
1209
1210
1211
1212

1213

1214
1215
1216
1217
1218


1219

1220
1221
1222
1223
1224


1225

1226
1227
1228
1229
1230


1231

1232
1233
1234
1235
1236


1237

1238
1239
1240
1241
1242


1243

1244
1245

1246

1247
1248
1249
1250
1251
1252
1253
1254
1255

1256

1257
1258
1259
1260
1261
1262
1263

1264

1265
1266
1267
1268
1269
1270
1271
1272

1273

1274
1275
1276
1277
1278
1279
1280
1281
1282

1283

1284
1285
1286
1287
1288
1289
1290

1291

1292
1293
1294
1295
1296
1297
1298
1299

1300

1301
1302
1303
1304
1305
1306
1307
1308
1309

1310

1311
1312
1313
1314
1315
1316
1317

1318

1319
1320
1321
1322
1323
1324
1325
1326

1327

1328
1329
1330
1331
1332
1333
1334
1335
1336

1337

1338
1339
1340
1341
1342
1343
1344

1345

1346
1347
1348
1349
1350
1351
1352
1353

1354

1355
1356
1357
1358
1359
1360
1361
1362
1363

1364

1365
1366
1367
1368
1369
1370
1371

1372

1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383


1384

1385
1386
1387
1388
1389


1390

1391
1392
1393
1394
1395


1396

1397
1398
1399
1400
1401


1402

1403
1404
1405
1406
1407


1408

1409
1410

1411

1412
1413
1414
1415
1416
1417
1418
1419
1420

1421

1422
1423
1424
1425
1426
1427
1428

1429

1430
1431
1432
1433
1434
1435
1436
1437

1438

1439
1440
1441
1442
1443
1444
1445
1446
1447

1448

1449
1450
1451
1452
1453
1454
1455

1456

1457
1458
1459
1460
1461
1462
1463
1464

1465

1466
1467
1468
1469
1470
1471
1472
1473
1474

1475

1476
1477
1478
1479
1480
1481
1482

1483

1484
1485
1486
1487
1488
1489
1490
1491

1492

1493
1494
1495
1496
1497
1498
1499
1500
1501

1502

1503
1504
1505
1506
1507
1508
1509

1510

1511
1512
1513
1514
1515
1516
1517
1518

1519

1520
1521
1522
1523
1524
1525
1526
1527
1528

1529

1530
1531
1532
1533
1534
1535
1536

1537

1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554

1555
1556

1557

1558
1559
1560
1561
1562
1563
1564
1565

1566

1567
1568
1569
1570
1571
1572
1573







-
+
-





-
-
+
-





-
-
+
-





-
-
+
-





-
-
+
-





-
-
+
-


-
+
-









-
+
-







-
+
-








-
+
-









-
+
-







-
+
-








-
+
-









-
+
-







-
+
-








-
+
-









-
+
-







-
+
-








-
+
-









-
+
-







-
+
-











-
-
+
-





-
-
+
-





-
-
+
-





-
-
+
-





-
-
+
-


-
+
-









-
+
-







-
+
-








-
+
-









-
+
-







-
+
-








-
+
-









-
+
-







-
+
-








-
+
-









-
+
-







-
+
-








-
+
-









-
+
-







-
+
-

















-

+
-
+
-








-
+
-







				    delegate: nil];
}
# endif
#endif

- (void)writeInt8: (uint8_t)int8
{
	[self writeBuffer: (char *)&int8
	[self writeBuffer: (char *)&int8 length: 1];
		   length: 1];
}

- (void)writeBigEndianInt16: (uint16_t)int16
{
	int16 = OF_BSWAP16_IF_LE(int16);

	[self writeBuffer: (char *)&int16
	[self writeBuffer: (char *)&int16 length: 2];
		   length: 2];
}

- (void)writeBigEndianInt32: (uint32_t)int32
{
	int32 = OF_BSWAP32_IF_LE(int32);

	[self writeBuffer: (char *)&int32
	[self writeBuffer: (char *)&int32 length: 4];
		   length: 4];
}

- (void)writeBigEndianInt64: (uint64_t)int64
{
	int64 = OF_BSWAP64_IF_LE(int64);

	[self writeBuffer: (char *)&int64
	[self writeBuffer: (char *)&int64 length: 8];
		   length: 8];
}

- (void)writeBigEndianFloat: (float)float_
{
	float_ = OF_BSWAP_FLOAT_IF_LE(float_);

	[self writeBuffer: (char *)&float_
	[self writeBuffer: (char *)&float_ length: 4];
		   length: 4];
}

- (void)writeBigEndianDouble: (double)double_
{
	double_ = OF_BSWAP_DOUBLE_IF_LE(double_);

	[self writeBuffer: (char *)&double_
	[self writeBuffer: (char *)&double_ length: 8];
		   length: 8];
}

- (size_t)writeBigEndianInt16s: (const uint16_t *)buffer
- (size_t)writeBigEndianInt16s: (const uint16_t *)buffer count: (size_t)count
			 count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(uint16_t);

#ifdef OF_BIG_ENDIAN
	[self writeBuffer: buffer
	[self writeBuffer: buffer length: size];
		   length: size];
#else
	uint16_t *tmp = of_alloc(count, sizeof(uint16_t));

	@try {
		for (size_t i = 0; i < count; i++)
			tmp[i] = OF_BSWAP16(buffer[i]);

		[self writeBuffer: tmp
		[self writeBuffer: tmp length: size];
			   length: size];
	} @finally {
		free(tmp);
	}
#endif

	return size;
}

- (size_t)writeBigEndianInt32s: (const uint32_t *)buffer
- (size_t)writeBigEndianInt32s: (const uint32_t *)buffer count: (size_t)count
			 count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(uint32_t);

#ifdef OF_BIG_ENDIAN
	[self writeBuffer: buffer
	[self writeBuffer: buffer length: size];
		   length: size];
#else
	uint32_t *tmp = of_alloc(count, sizeof(uint32_t));

	@try {
		for (size_t i = 0; i < count; i++)
			tmp[i] = OF_BSWAP32(buffer[i]);

		[self writeBuffer: tmp
		[self writeBuffer: tmp length: size];
			   length: size];
	} @finally {
		free(tmp);
	}
#endif

	return size;
}

- (size_t)writeBigEndianInt64s: (const uint64_t *)buffer
- (size_t)writeBigEndianInt64s: (const uint64_t *)buffer count: (size_t)count
			 count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(uint64_t);

#ifdef OF_BIG_ENDIAN
	[self writeBuffer: buffer
	[self writeBuffer: buffer length: size];
		   length: size];
#else
	uint64_t *tmp = of_alloc(count, sizeof(uint64_t));

	@try {
		for (size_t i = 0; i < count; i++)
			tmp[i] = OF_BSWAP64(buffer[i]);

		[self writeBuffer: tmp
		[self writeBuffer: tmp length: size];
			   length: size];
	} @finally {
		free(tmp);
	}
#endif

	return size;
}

- (size_t)writeBigEndianFloats: (const float *)buffer
- (size_t)writeBigEndianFloats: (const float *)buffer count: (size_t)count
			 count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(float))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(float);

#ifdef OF_FLOAT_BIG_ENDIAN
	[self writeBuffer: buffer
	[self writeBuffer: buffer length: size];
		   length: size];
#else
	float *tmp = of_alloc(count, sizeof(float));

	@try {
		for (size_t i = 0; i < count; i++)
			tmp[i] = OF_BSWAP_FLOAT(buffer[i]);

		[self writeBuffer: tmp
		[self writeBuffer: tmp length: size];
			   length: size];
	} @finally {
		free(tmp);
	}
#endif

	return size;
}

- (size_t)writeBigEndianDoubles: (const double *)buffer
- (size_t)writeBigEndianDoubles: (const double *)buffer count: (size_t)count
			  count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(double))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(double);

#ifdef OF_FLOAT_BIG_ENDIAN
	[self writeBuffer: buffer
	[self writeBuffer: buffer length: size];
		   length: size];
#else
	double *tmp = of_alloc(count, sizeof(double));

	@try {
		for (size_t i = 0; i < count; i++)
			tmp[i] = OF_BSWAP_DOUBLE(buffer[i]);

		[self writeBuffer: tmp
		[self writeBuffer: tmp length: size];
			   length: size];
	} @finally {
		free(tmp);
	}
#endif

	return size;
}

- (void)writeLittleEndianInt16: (uint16_t)int16
{
	int16 = OF_BSWAP16_IF_BE(int16);

	[self writeBuffer: (char *)&int16
	[self writeBuffer: (char *)&int16 length: 2];
		   length: 2];
}

- (void)writeLittleEndianInt32: (uint32_t)int32
{
	int32 = OF_BSWAP32_IF_BE(int32);

	[self writeBuffer: (char *)&int32
	[self writeBuffer: (char *)&int32 length: 4];
		   length: 4];
}

- (void)writeLittleEndianInt64: (uint64_t)int64
{
	int64 = OF_BSWAP64_IF_BE(int64);

	[self writeBuffer: (char *)&int64
	[self writeBuffer: (char *)&int64 length: 8];
		   length: 8];
}

- (void)writeLittleEndianFloat: (float)float_
{
	float_ = OF_BSWAP_FLOAT_IF_BE(float_);

	[self writeBuffer: (char *)&float_
	[self writeBuffer: (char *)&float_ length: 4];
		   length: 4];
}

- (void)writeLittleEndianDouble: (double)double_
{
	double_ = OF_BSWAP_DOUBLE_IF_BE(double_);

	[self writeBuffer: (char *)&double_
	[self writeBuffer: (char *)&double_ length: 8];
		   length: 8];
}

- (size_t)writeLittleEndianInt16s: (const uint16_t *)buffer
- (size_t)writeLittleEndianInt16s: (const uint16_t *)buffer count: (size_t)count
			    count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(uint16_t);

#ifndef OF_BIG_ENDIAN
	[self writeBuffer: buffer
	[self writeBuffer: buffer length: size];
		   length: size];
#else
	uint16_t *tmp = of_alloc(count, sizeof(uint16_t));

	@try {
		for (size_t i = 0; i < count; i++)
			tmp[i] = OF_BSWAP16(buffer[i]);

		[self writeBuffer: tmp
		[self writeBuffer: tmp length: size];
			   length: size];
	} @finally {
		free(tmp);
	}
#endif

	return size;
}

- (size_t)writeLittleEndianInt32s: (const uint32_t *)buffer
- (size_t)writeLittleEndianInt32s: (const uint32_t *)buffer count: (size_t)count
			    count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(uint32_t);

#ifndef OF_BIG_ENDIAN
	[self writeBuffer: buffer
	[self writeBuffer: buffer length: size];
		   length: size];
#else
	uint32_t *tmp = of_alloc(count, sizeof(uint32_t));

	@try {
		for (size_t i = 0; i < count; i++)
			tmp[i] = OF_BSWAP32(buffer[i]);

		[self writeBuffer: tmp
		[self writeBuffer: tmp length: size];
			   length: size];
	} @finally {
		free(tmp);
	}
#endif

	return size;
}

- (size_t)writeLittleEndianInt64s: (const uint64_t *)buffer
- (size_t)writeLittleEndianInt64s: (const uint64_t *)buffer count: (size_t)count
			    count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(uint64_t);

#ifndef OF_BIG_ENDIAN
	[self writeBuffer: buffer
	[self writeBuffer: buffer length: size];
		   length: size];
#else
	uint64_t *tmp = of_alloc(count, sizeof(uint64_t));

	@try {
		for (size_t i = 0; i < count; i++)
			tmp[i] = OF_BSWAP64(buffer[i]);

		[self writeBuffer: tmp
		[self writeBuffer: tmp length: size];
			   length: size];
	} @finally {
		free(tmp);
	}
#endif

	return size;
}

- (size_t)writeLittleEndianFloats: (const float *)buffer
- (size_t)writeLittleEndianFloats: (const float *)buffer count: (size_t)count
			    count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(float))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(float);

#ifndef OF_FLOAT_BIG_ENDIAN
	[self writeBuffer: buffer
	[self writeBuffer: buffer length: size];
		   length: size];
#else
	float *tmp = of_alloc(count, sizeof(float));

	@try {
		for (size_t i = 0; i < count; i++)
			tmp[i] = OF_BSWAP_FLOAT(buffer[i]);

		[self writeBuffer: tmp
		[self writeBuffer: tmp length: size];
			   length: size];
	} @finally {
		free(tmp);
	}
#endif

	return size;
}

- (size_t)writeLittleEndianDoubles: (const double *)buffer
- (size_t)writeLittleEndianDoubles: (const double *)buffer count: (size_t)count
			     count: (size_t)count
{
	size_t size;

	if OF_UNLIKELY (count > SIZE_MAX / sizeof(double))
		@throw [OFOutOfRangeException exception];

	size = count * sizeof(double);

#ifndef OF_FLOAT_BIG_ENDIAN
	[self writeBuffer: buffer
	[self writeBuffer: buffer length: size];
		   length: size];
#else
	double *tmp = of_alloc(count, sizeof(double));

	@try {
		for (size_t i = 0; i < count; i++)
			tmp[i] = OF_BSWAP_DOUBLE(buffer[i]);

		[self writeBuffer: tmp
		[self writeBuffer: tmp length: size];
			   length: size];
	} @finally {
		free(tmp);
	}
#endif

	return size;
}

- (size_t)writeData: (OFData *)data
{
	void *pool;
	size_t length;

	if (data == nil)
		@throw [OFInvalidArgumentException exception];

	pool = objc_autoreleasePoolPush();
	length = data.count * data.itemSize;

	length = data.count * data.itemSize;
	[self writeBuffer: data.items
	[self writeBuffer: data.items length: length];
		   length: length];

	objc_autoreleasePoolPop(pool);

	return length;
}

- (size_t)writeString: (OFString *)string
{
	return [self writeString: string
	return [self writeString: string encoding: OF_STRING_ENCODING_UTF_8];
			encoding: OF_STRING_ENCODING_UTF_8];
}

- (size_t)writeString: (OFString *)string
	     encoding: (of_string_encoding_t)encoding
{
	void *pool;
	size_t length;
1703
1704
1705
1706
1707
1708
1709
1710

1711
1712
1713
1714

1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727

1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742

1743
1744
1745
1746
1747
1748
1749

1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763

1764
1765
1766
1767
1768
1769
1770
1771
1584
1585
1586
1587
1588
1589
1590

1591

1592
1593

1594

1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605

1606

1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619

1620

1621
1622
1623
1624
1625

1626

1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638

1639

1640
1641
1642
1643
1644
1645
1646







-
+
-


-
+
-











-
+
-













-
+
-





-
+
-












-
+
-







	objc_autoreleasePoolPop(pool);

	return length;
}

- (size_t)writeLine: (OFString *)string
{
	return [self writeLine: string
	return [self writeLine: string encoding: OF_STRING_ENCODING_UTF_8];
		      encoding: OF_STRING_ENCODING_UTF_8];
}

- (size_t)writeLine: (OFString *)string
- (size_t)writeLine: (OFString *)string encoding: (of_string_encoding_t)encoding
	   encoding: (of_string_encoding_t)encoding
{
	size_t stringLength = [string cStringLengthWithEncoding: encoding];
	char *buffer;

	buffer = of_alloc(stringLength + 1, 1);

	@try {
		memcpy(buffer, [string cStringWithEncoding: encoding],
		    stringLength);
		buffer[stringLength] = '\n';

		[self writeBuffer: buffer
		[self writeBuffer: buffer length: stringLength + 1];
			   length: stringLength + 1];
	} @finally {
		free(buffer);
	}

	return stringLength + 1;
}

- (size_t)writeFormat: (OFConstantString *)format, ...
{
	va_list arguments;
	size_t ret;

	va_start(arguments, format);
	ret = [self writeFormat: format
	ret = [self writeFormat: format arguments: arguments];
		      arguments: arguments];
	va_end(arguments);

	return ret;
}

- (size_t)writeFormat: (OFConstantString *)format
- (size_t)writeFormat: (OFConstantString *)format arguments: (va_list)arguments
	    arguments: (va_list)arguments
{
	char *UTF8String;
	int length;

	if (format == nil)
		@throw [OFInvalidArgumentException exception];

	if ((length = of_vasprintf(&UTF8String, format.UTF8String,
	    arguments)) == -1)
		@throw [OFInvalidFormatException exception];

	@try {
		[self writeBuffer: UTF8String
		[self writeBuffer: UTF8String length: length];
			   length: length];
	} @finally {
		free(UTF8String);
	}

	return length;
}

1860
1861
1862
1863
1864
1865
1866
1867

1868
1869
1870
1871
1872
1873
1874
1875
1735
1736
1737
1738
1739
1740
1741

1742

1743
1744
1745
1746
1747
1748
1749







-
+
-







- (void)cancelAsyncRequests
{
	[OFRunLoop of_cancelAsyncRequestsForObject: self
					      mode: of_run_loop_mode_default];
}
#endif

- (void)unreadFromBuffer: (const void *)buffer
- (void)unreadFromBuffer: (const void *)buffer length: (size_t)length
		  length: (size_t)length
{
	char *readBuffer;

	if (length > SIZE_MAX - _readBufferLength)
		@throw [OFOutOfRangeException exception];

	readBuffer = of_alloc(_readBufferLength + length, 1);

Modified src/OFString+JSONParsing.m from [182fb0261b] to [0ac530152e].

500
501
502
503
504
505
506
507

508
509
510
511
512
513
514
515
500
501
502
503
504
505
506

507

508
509
510
511
512
513
514







-
+
-








		(*pointer)++;

		object = nextObject(pointer, stop, line, depthLimit);
		if (object == nil)
			return nil;

		[dictionary setObject: object
		[dictionary setObject: object forKey: key];
			       forKey: key];

		skipWhitespacesAndComments(pointer, stop, line);
		if (*pointer >= stop)
			return nil;

		if (**pointer == ',') {
			(*pointer)++;

Modified src/OFString+PropertyListParsing.m from [3a2aedc9eb] to [c7b4407cc2].

62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
62
63
64
65
66
67
68

69

70
71
72
73
74
75
76







-
+
-







	enumerator = [children objectEnumerator];
	while ((key = [enumerator nextObject]) &&
	    (object = [enumerator nextObject])) {
		if (key.namespace != nil || key.attributes.count != 0 ||
		    ![key.name isEqual: @"key"])
			@throw [OFInvalidFormatException exception];

		[ret setObject: parseElement(object)
		[ret setObject: parseElement(object) forKey: key.stringValue];
			forKey: key.stringValue];
	}

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;

Modified src/OFString.h from [c803b1d0df] to [8eb0a45d6e].

905
906
907
908
909
910
911
912

913
914
915
916
917
918
919
920
905
906
907
908
909
910
911

912

913
914
915
916
917
918
919







-
+
-







/**
 * @brief Copies the Unicode characters in the specified range to the specified
 *	  buffer.
 *
 * @param buffer The buffer to store the Unicode characters
 * @param range The range of the Unicode characters to copy
 */
- (void)getCharacters: (of_unichar_t *)buffer
- (void)getCharacters: (of_unichar_t *)buffer inRange: (of_range_t)range;
	      inRange: (of_range_t)range;

/**
 * @brief Returns the range of the first occurrence of the string.
 *
 * @param string The string to search
 * @return The range of the first occurrence of the string or a range with
 *	   `OF_NOT_FOUND` as start position if it was not found
929
930
931
932
933
934
935
936

937
938
939
940
941
942
943
944
928
929
930
931
932
933
934

935

936
937
938
939
940
941
942







-
+
-







 *		  Possible values are:
 *		  Value                        | Description
 *		  -----------------------------|-------------------------------
 *		  `OF_STRING_SEARCH_BACKWARDS` | Search backwards in the string
 * @return The range of the first occurrence of the string or a range with
 *	   `OF_NOT_FOUND` as start position if it was not found
 */
- (of_range_t)rangeOfString: (OFString *)string
- (of_range_t)rangeOfString: (OFString *)string options: (int)options;
		    options: (int)options;

/**
 * @brief Returns the range of the string in the specified range.
 *
 * @param string The string to search
 * @param options Options modifying search behaviour.@n
 *		  Possible values are:
1240
1241
1242
1243
1244
1245
1246
1247

1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264

1265
1266
1267
1268
1269
1270
1271
1272
1238
1239
1240
1241
1242
1243
1244

1245

1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260

1261

1262
1263
1264
1265
1266
1267
1268







-
+
-















-
+
-







/**
 * @brief Writes the string into the specified file using the specified
 *	  encoding.
 *
 * @param path The path of the file to write to
 * @param encoding The encoding to use to write the string into the file
 */
- (void)writeToFile: (OFString *)path
- (void)writeToFile: (OFString *)path encoding: (of_string_encoding_t)encoding;
	   encoding: (of_string_encoding_t)encoding;
# endif

/**
 * @brief Writes the string to the specified URL using UTF-8 encoding.
 *
 * @param URL The URL to write to
 */
- (void)writeToURL: (OFURL *)URL;

/**
 * @brief Writes the string to the specified URL using the specified encoding.
 *
 * @param URL The URL to write to
 * @param encoding The encoding to use to write the string to the URL
 */
- (void)writeToURL: (OFURL *)URL
- (void)writeToURL: (OFURL *)URL encoding: (of_string_encoding_t)encoding;
	  encoding: (of_string_encoding_t)encoding;

# ifdef OF_HAVE_BLOCKS
/**
 * Enumerates all lines in the receiver using the specified block.
 *
 * @brief block The block to call for each line
 */

Modified src/OFString.m from [f5bfcef342] to [cc999ec09b].

347
348
349
350
351
352
353
354

355
356
357
358
359
360
361
362
363

364
365
366
367
368
369
370
371
347
348
349
350
351
352
353

354

355
356
357
358
359
360
361

362

363
364
365
366
367
368
369







-
+
-







-
+
-







	size_t length = self.length;

	for (size_t i = 0; i < length; i++) {
		of_unichar_t c = characters[i];
		const char *const *page;

		if (c >= size) {
			[ret appendCharacters: &c
			[ret appendCharacters: &c length: 1];
				       length: 1];
			continue;
		}

		page = table[c >> 8];
		if (page != NULL && page[c & 0xFF] != NULL)
			[ret appendUTF8String: page[c & 0xFF]];
		else
			[ret appendCharacters: &c
			[ret appendCharacters: &c length: 1];
				       length: 1];
	}

	objc_autoreleasePoolPop(pool);

	return ret;
}
#endif
964
965
966
967
968
969
970
971

972
973
974
975
976
977
978
979
962
963
964
965
966
967
968

969

970
971
972
973
974
975
976







-
+
-








- (instancetype)initWithFormat: (OFConstantString *)format, ...
{
	id ret;
	va_list arguments;

	va_start(arguments, format);
	ret = [self initWithFormat: format
	ret = [self initWithFormat: format arguments: arguments];
			 arguments: arguments];
	va_end(arguments);

	return ret;
}

- (instancetype)initWithFormat: (OFConstantString *)format
		     arguments: (va_list)arguments
1020
1021
1022
1023
1024
1025
1026
1027

1028
1029
1030
1031
1032
1033
1034
1035
1017
1018
1019
1020
1021
1022
1023

1024

1025
1026
1027
1028
1029
1030
1031







-
+
-







		 * to use -[initWithUTF8StringNoCopy:length:freeWhenDone:].
		 */
		if (SIZE_MAX - (size_t)fileSize < 1)
			@throw [OFOutOfRangeException exception];

		tmp = of_alloc((size_t)fileSize + 1, 1);
		@try {
			file = [[OFFile alloc] initWithPath: path
			file = [[OFFile alloc] initWithPath: path mode: @"r"];
						       mode: @"r"];

			[file readIntoBuffer: tmp
				 exactLength: (size_t)fileSize];
		} @catch (id e) {
			free(tmp);
			@throw e;
		} @finally {
1441
1442
1443
1444
1445
1446
1447
1448

1449
1450
1451
1452
1453
1454

1455
1456
1457
1458
1459
1460
1461
1462
1437
1438
1439
1440
1441
1442
1443

1444

1445
1446
1447
1448

1449

1450
1451
1452
1453
1454
1455
1456







-
+
-




-
+
-







		free(cString);
		@throw e;
	}
}

- (const char *)cStringWithEncoding: (of_string_encoding_t)encoding
{
	return [self of_cStringWithEncoding: encoding
	return [self of_cStringWithEncoding: encoding lossy: false];
				      lossy: false];
}

- (const char *)lossyCStringWithEncoding: (of_string_encoding_t)encoding
{
	return [self of_cStringWithEncoding: encoding
	return [self of_cStringWithEncoding: encoding lossy: true];
				      lossy: true];
}

- (const char *)UTF8String
{
	return [self cStringWithEncoding: OF_STRING_ENCODING_UTF_8];
}

1718
1719
1720
1721
1722
1723
1724
1725

1726
1727
1728
1729
1730
1731

1732
1733
1734
1735
1736
1737
1738
1739
1740
1741

1742
1743

1744
1745

1746
1747

1748
1749

1750
1751

1752
1753
1754
1755

1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772

1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794

1795
1796
1797
1798
1799
1800
1801
1802

1803
1804
1805
1806
1807
1808
1809
1810
1811

1812
1813
1814
1815

1816
1817
1818
1819
1820
1821

1822
1823
1824
1825

1826
1827
1828
1829
1830

1831
1832
1833
1834
1835
1836
1837
1838
1712
1713
1714
1715
1716
1717
1718

1719

1720
1721
1722
1723

1724

1725
1726
1727
1728
1729
1730
1731
1732

1733


1734


1735


1736


1737


1738

1739
1740

1741

1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756

1757

1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777

1778

1779
1780
1781
1782
1783
1784

1785

1786
1787
1788
1789
1790
1791
1792

1793

1794
1795

1796

1797
1798
1799
1800

1801

1802
1803

1804

1805
1806
1807

1808

1809
1810
1811
1812
1813
1814
1815







-
+
-




-
+
-








-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-


-
+
-















-
+
-




















-
+
-






-
+
-







-
+
-


-
+
-




-
+
-


-
+
-



-
+
-







	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}

- (OFString *)JSONRepresentation
{
	return [self of_JSONRepresentationWithOptions: 0
	return [self of_JSONRepresentationWithOptions: 0 depth: 0];
						depth: 0];
}

- (OFString *)JSONRepresentationWithOptions: (int)options
{
	return [self of_JSONRepresentationWithOptions: options
	return [self of_JSONRepresentationWithOptions: options depth: 0];
						depth: 0];
}

- (OFString *)of_JSONRepresentationWithOptions: (int)options
					 depth: (size_t)depth
{
	OFMutableString *JSON = [[self mutableCopy] autorelease];

	/* FIXME: This is slow! Write it in pure C! */
	[JSON replaceOccurrencesOfString: @"\\"
	[JSON replaceOccurrencesOfString: @"\\" withString: @"\\\\"];
			      withString: @"\\\\"];
	[JSON replaceOccurrencesOfString: @"\""
	[JSON replaceOccurrencesOfString: @"\"" withString: @"\\\""];
			      withString: @"\\\""];
	[JSON replaceOccurrencesOfString: @"\b"
	[JSON replaceOccurrencesOfString: @"\b" withString: @"\\b"];
			      withString: @"\\b"];
	[JSON replaceOccurrencesOfString: @"\f"
	[JSON replaceOccurrencesOfString: @"\f" withString: @"\\f"];
			      withString: @"\\f"];
	[JSON replaceOccurrencesOfString: @"\r"
	[JSON replaceOccurrencesOfString: @"\r" withString: @"\\r"];
			      withString: @"\\r"];
	[JSON replaceOccurrencesOfString: @"\t"
	[JSON replaceOccurrencesOfString: @"\t" withString: @"\\t"];
			      withString: @"\\t"];

	if (options & OF_JSON_REPRESENTATION_JSON5) {
		[JSON replaceOccurrencesOfString: @"\n"
		[JSON replaceOccurrencesOfString: @"\n" withString: @"\\\n"];
				      withString: @"\\\n"];

		if (options & OF_JSON_REPRESENTATION_IDENTIFIER) {
			const char *cString = self.UTF8String;

			if ((!of_ascii_isalpha(cString[0]) &&
			    cString[0] != '_' && cString[0] != '$') ||
			    strpbrk(cString, " \n\r\t\b\f\\\"'") != NULL) {
				[JSON prependString: @"\""];
				[JSON appendString: @"\""];
			}
		} else {
			[JSON prependString: @"\""];
			[JSON appendString: @"\""];
		}
	} else {
		[JSON replaceOccurrencesOfString: @"\n"
		[JSON replaceOccurrencesOfString: @"\n" withString: @"\\n"];
				      withString: @"\\n"];

		[JSON prependString: @"\""];
		[JSON appendString: @"\""];
	}

	[JSON makeImmutable];

	return JSON;
}

- (OFData *)messagePackRepresentation
{
	OFMutableData *data;
	size_t length;

	length = self.UTF8StringLength;

	if (length <= 31) {
		uint8_t tmp = 0xA0 | ((uint8_t)length & 0x1F);

		data = [OFMutableData dataWithItemSize: 1
		data = [OFMutableData dataWithItemSize: 1 capacity: length + 1];
					      capacity: length + 1];

		[data addItem: &tmp];
	} else if (length <= UINT8_MAX) {
		uint8_t type = 0xD9;
		uint8_t tmp = (uint8_t)length;

		data = [OFMutableData dataWithItemSize: 1
		data = [OFMutableData dataWithItemSize: 1 capacity: length + 2];
					      capacity: length + 2];

		[data addItem: &type];
		[data addItem: &tmp];
	} else if (length <= UINT16_MAX) {
		uint8_t type = 0xDA;
		uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)length);

		data = [OFMutableData dataWithItemSize: 1
		data = [OFMutableData dataWithItemSize: 1 capacity: length + 3];
					      capacity: length + 3];

		[data addItem: &type];
		[data addItems: &tmp
		[data addItems: &tmp count: sizeof(tmp)];
			 count: sizeof(tmp)];
	} else if (length <= UINT32_MAX) {
		uint8_t type = 0xDB;
		uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)length);

		data = [OFMutableData dataWithItemSize: 1
		data = [OFMutableData dataWithItemSize: 1 capacity: length + 5];
					      capacity: length + 5];

		[data addItem: &type];
		[data addItems: &tmp
		[data addItems: &tmp count: sizeof(tmp)];
			 count: sizeof(tmp)];
	} else
		@throw [OFOutOfRangeException exception];

	[data addItems: self.UTF8String
	[data addItems: self.UTF8String count: length];
		 count: length];

	return data;
}

- (of_range_t)rangeOfString: (OFString *)string
{
	return [self rangeOfString: string
1868
1869
1870
1871
1872
1873
1874
1875

1876
1877
1878
1879
1880
1881
1882
1883
1845
1846
1847
1848
1849
1850
1851

1852

1853
1854
1855
1856
1857
1858
1859







-
+
-








	pool = objc_autoreleasePoolPush();

	searchCharacters = string.characters;

	characters = of_alloc(range.length, sizeof(of_unichar_t));
	@try {
		[self getCharacters: characters
		[self getCharacters: characters inRange: range];
			    inRange: range];

		if (options & OF_STRING_SEARCH_BACKWARDS) {
			for (size_t i = range.length - searchLength;; i--) {
				if (memcmp(characters + i, searchCharacters,
				    searchLength * sizeof(of_unichar_t)) == 0) {
					objc_autoreleasePoolPop(pool);
					return of_range(range.location + i,
1936
1937
1938
1939
1940
1941
1942
1943

1944
1945
1946
1947
1948
1949
1950
1951
1912
1913
1914
1915
1916
1917
1918

1919

1920
1921
1922
1923
1924
1925
1926







-
+
-







		return OF_NOT_FOUND;

	if (range.length > SIZE_MAX / sizeof(of_unichar_t))
		@throw [OFOutOfRangeException exception];

	characters = of_alloc(range.length, sizeof(of_unichar_t));
	@try {
		[self getCharacters: characters
		[self getCharacters: characters inRange: range];
			    inRange: range];

		if (options & OF_STRING_SEARCH_BACKWARDS) {
			for (size_t i = range.length - 1;; i--) {
				if (characterIsMember(characterSet,
				    @selector(characterIsMember:),
				    characters[i]))
					return range.location + i;
2040
2041
2042
2043
2044
2045
2046
2047

2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060


2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084

2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188

2189
2190
2191
2192
2193
2194
2195
2196
2015
2016
2017
2018
2019
2020
2021

2022

2023
2024
2025
2026
2027
2028
2029
2030




2031
2032


2033

2034
2035
2036
2037
2038
2039

2040

2041

2042
2043
2044
2045
2046
2047
2048


2049


2050

2051
2052
2053
2054
2055
2056
2057
2058
2059

2060
2061
2062
2063

2064

2065
2066
2067
2068
2069
2070

2071

2072

2073
2074
2075
2076
2077
2078

2079

2080

2081
2082
2083
2084
2085
2086

2087

2088

2089
2090
2091
2092
2093
2094

2095

2096

2097
2098
2099
2100
2101
2102

2103

2104

2105
2106
2107
2108
2109
2110

2111

2112

2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128

2129

2130
2131
2132
2133
2134
2135
2136







-
+
-








-
-
-
-
+
+
-
-

-






-

-

-







-
-
+
-
-

-









-




-

-






-

-

-






-

-

-






-

-

-






-

-

-






-

-

-






-

-

-
















-
+
-








- (OFString *)stringByAppendingFormat: (OFConstantString *)format, ...
{
	OFString *ret;
	va_list arguments;

	va_start(arguments, format);
	ret = [self stringByAppendingFormat: format
	ret = [self stringByAppendingFormat: format arguments: arguments];
				  arguments: arguments];
	va_end(arguments);

	return ret;
}

- (OFString *)stringByAppendingFormat: (OFConstantString *)format
			    arguments: (va_list)arguments
{
	OFMutableString *new;

	new = [OFMutableString stringWithString: self];
	[new appendFormat: format
	OFMutableString *new = [OFMutableString stringWithString: self];
	[new appendFormat: format arguments: arguments];
		arguments: arguments];

	[new makeImmutable];

	return new;
}

- (OFString *)stringByPrependingString: (OFString *)string
{
	OFMutableString *new = [[string mutableCopy] autorelease];

	[new appendString: self];

	[new makeImmutable];

	return new;
}

- (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string
					withString: (OFString *)replacement
{
	OFMutableString *new = [[self mutableCopy] autorelease];

	[new replaceOccurrencesOfString: string
	[new replaceOccurrencesOfString: string withString: replacement];
			     withString: replacement];

	[new makeImmutable];

	return new;
}

- (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string
					withString: (OFString *)replacement
					   options: (int)options
					     range: (of_range_t)range
{
	OFMutableString *new = [[self mutableCopy] autorelease];

	[new replaceOccurrencesOfString: string
			     withString: replacement
				options: options
				  range: range];

	[new makeImmutable];

	return new;
}

- (OFString *)uppercaseString
{
	OFMutableString *new = [[self mutableCopy] autorelease];

	[new uppercase];

	[new makeImmutable];

	return new;
}

- (OFString *)lowercaseString
{
	OFMutableString *new = [[self mutableCopy] autorelease];

	[new lowercase];

	[new makeImmutable];

	return new;
}

- (OFString *)capitalizedString
{
	OFMutableString *new = [[self mutableCopy] autorelease];

	[new capitalize];

	[new makeImmutable];

	return new;
}

- (OFString *)stringByDeletingLeadingWhitespaces
{
	OFMutableString *new = [[self mutableCopy] autorelease];

	[new deleteLeadingWhitespaces];

	[new makeImmutable];

	return new;
}

- (OFString *)stringByDeletingTrailingWhitespaces
{
	OFMutableString *new = [[self mutableCopy] autorelease];

	[new deleteTrailingWhitespaces];

	[new makeImmutable];

	return new;
}

- (OFString *)stringByDeletingEnclosingWhitespaces
{
	OFMutableString *new = [[self mutableCopy] autorelease];

	[new deleteEnclosingWhitespaces];

	[new makeImmutable];

	return new;
}

- (bool)hasPrefix: (OFString *)prefix
{
	of_unichar_t *tmp;
	size_t prefixLength;
	bool hasPrefix;

	if ((prefixLength = prefix.length) > self.length)
		return false;

	tmp = of_alloc(prefixLength, sizeof(of_unichar_t));
	@try {
		void *pool = objc_autoreleasePoolPush();

		[self getCharacters: tmp
		[self getCharacters: tmp inRange: of_range(0, prefixLength)];
			    inRange: of_range(0, prefixLength)];

		hasPrefix = (memcmp(tmp, prefix.characters,
		    prefixLength * sizeof(of_unichar_t)) == 0);

		objc_autoreleasePoolPop(pool);
	} @finally {
		free(tmp);
2229
2230
2231
2232
2233
2234
2235
2236

2237
2238
2239
2240
2241
2242
2243
2244
2169
2170
2171
2172
2173
2174
2175

2176

2177
2178
2179
2180
2181
2182
2183







-
+
-







	}

	return hasSuffix;
}

- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
{
	return [self componentsSeparatedByString: delimiter
	return [self componentsSeparatedByString: delimiter options: 0];
					 options: 0];
}

- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
				 options: (int)options
{
	void *pool;
	OFMutableArray *array;
2599
2600
2601
2602
2603
2604
2605
2606

2607
2608
2609
2610
2611
2612
2613
2614
2538
2539
2540
2541
2542
2543
2544

2545

2546
2547
2548
2549
2550
2551
2552







-
+
-







- (const of_unichar_t *)characters
{
	size_t length = self.length;
	of_unichar_t *buffer;

	buffer = of_alloc(length, sizeof(of_unichar_t));
	@try {
		[self getCharacters: buffer
		[self getCharacters: buffer inRange: of_range(0, length)];
			    inRange: of_range(0, length)];

		return [[OFData dataWithItemsNoCopy: buffer
					      count: length
					   itemSize: sizeof(of_unichar_t)
				       freeWhenDone: true] items];
	} @catch (id e) {
		free(buffer);
2701
2702
2703
2704
2705
2706
2707
2708

2709
2710
2711
2712
2713
2714
2715
2716
2639
2640
2641
2642
2643
2644
2645

2646

2647
2648
2649
2650
2651
2652
2653







-
+
-







- (const of_char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder
{
	size_t length = self.length;
	of_char32_t *buffer;

	buffer = of_alloc(length + 1, sizeof(of_char32_t));
	@try {
		[self getCharacters: buffer
		[self getCharacters: buffer inRange: of_range(0, length)];
			    inRange: of_range(0, length)];
		buffer[length] = 0;

		if (byteOrder != OF_BYTE_ORDER_NATIVE)
			for (size_t i = 0; i < length; i++)
				buffer[i] = OF_BSWAP32(buffer[i]);

		return [[OFData dataWithItemsNoCopy: buffer
2780
2781
2782
2783
2784
2785
2786
2787

2788
2789
2790
2791
2792
2793
2794
2795
2796
2797

2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808

2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822

2823
2824

2825
2826
2827
2828
2829
2830
2831
2832
2717
2718
2719
2720
2721
2722
2723

2724

2725
2726
2727
2728
2729
2730

2731

2732

2733
2734
2735
2736
2737
2738
2739
2740
2741

2742

2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754

2755


2756

2757
2758
2759
2760
2761
2762
2763







-
+
-






-

-
+
-









-
+
-












-
+
-
-
+
-







	}
}
#endif

#ifdef OF_HAVE_FILES
- (void)writeToFile: (OFString *)path
{
	[self writeToFile: path
	[self writeToFile: path encoding: OF_STRING_ENCODING_UTF_8];
		 encoding: OF_STRING_ENCODING_UTF_8];
}

- (void)writeToFile: (OFString *)path
	   encoding: (of_string_encoding_t)encoding
{
	void *pool = objc_autoreleasePoolPush();
	OFFile *file;

	file = [OFFile fileWithPath: path
	OFFile *file = [OFFile fileWithPath: path mode: @"w"];
			       mode: @"w"];
	[file writeString: self
		 encoding: encoding];

	objc_autoreleasePoolPop(pool);
}
#endif

- (void)writeToURL: (OFURL *)URL
{
	[self writeToURL: URL
	[self writeToURL: URL encoding: OF_STRING_ENCODING_UTF_8];
		encoding: OF_STRING_ENCODING_UTF_8];
}

- (void)writeToURL: (OFURL *)URL
	  encoding: (of_string_encoding_t)encoding
{
	void *pool = objc_autoreleasePoolPush();
	OFURLHandler *URLHandler;
	OFStream *stream;

	if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];

	stream = [URLHandler openItemAtURL: URL
	stream = [URLHandler openItemAtURL: URL mode: @"w"];
				      mode: @"w"];
	[stream writeString: self
	[stream writeString: self encoding: encoding];
		   encoding: encoding];

	objc_autoreleasePoolPop(pool);
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block
{

Modified src/OFURLHandler.m from [a30f3ee6ac] to [40d9847175].

78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
93
78
79
80
81
82
83
84

85

86
87
88
89
90
91
92







-
+
-







		OFURLHandler *handler;

		if ([handlers objectForKey: scheme] != nil)
			return false;

		handler = [[class alloc] initWithScheme: scheme];
		@try {
			[handlers setObject: handler
			[handlers setObject: handler forKey: scheme];
				     forKey: scheme];
		} @finally {
			[handler release];
		}
#ifdef OF_HAVE_THREADS
	} @finally {
		[mutex unlock];
	}

Modified src/OFXMLElement.m from [c1c758c150] to [96ecc2faed].

434
435
436
437
438
439
440
441

442
443
444
445
446
447
448
449
434
435
436
437
438
439
440

441

442
443
444
445
446
447
448







-
+
-







		OFMutableDictionary *tmp;
		OFString *key, *object;

		tmp = [[allNS mutableCopy] autorelease];

		while ((key = [keyEnumerator nextObject]) != nil &&
		    (object = [objectEnumerator nextObject]) != nil)
			[tmp setObject: object
			[tmp setObject: object forKey: key];
				forKey: key];

		allNS = tmp;
	} else
		allNS = _namespaces;

	prefix = [allNS objectForKey:
	    (_namespace != nil ? _namespace : (OFString *)@"")];
822
823
824
825
826
827
828
829

830
831
832
833
834
835
836
837
821
822
823
824
825
826
827

828

829
830
831
832
833
834
835







-
+
-







     forNamespace: (OFString *)namespace
{
	if (prefix.length == 0)
		@throw [OFInvalidArgumentException exception];
	if (namespace == nil)
		namespace = @"";

	[_namespaces setObject: prefix
	[_namespaces setObject: prefix forKey: namespace];
			forKey: namespace];
}

- (void)bindPrefix: (OFString *)prefix
      forNamespace: (OFString *)namespace
{
	[self setPrefix: prefix
	   forNamespace: namespace];

Modified src/OFZIPArchive.m from [f8c3fbc96e] to [c62bbdf049].

368
369
370
371
372
373
374
375

376
377
378
379
380
381
382
383
368
369
370
371
372
373
374

375

376
377
378
379
380
381
382







-
+
-







		OFZIPArchiveEntry *entry = [[[OFZIPArchiveEntry alloc]
		    of_initWithStream: _stream] autorelease];

		if ([_pathToEntryMap objectForKey: entry.fileName] != nil)
			@throw [OFInvalidFormatException exception];

		[_entries addObject: entry];
		[_pathToEntryMap setObject: entry
		[_pathToEntryMap setObject: entry forKey: entry.fileName];
				    forKey: entry.fileName];
	}

	objc_autoreleasePoolPop(pool);
}

- (OFArray *)entries
{