ObjFW  Diff

Differences From Artifact [398b865989]:

To Artifact [351546f0a3]:


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







-
+
















-
+

-
+

-
+



-
+

-
+
















-
+







		return false;
	if (memcmp(data.items, _items, _count * _itemSize) != 0)
		return false;

	return true;
}

- (of_comparison_result_t)compare: (OFData *)data
- (OFComparisonResult)compare: (OFData *)data
{
	int comparison;
	size_t count, minCount;

	if (![data isKindOfClass: [OFData class]])
		@throw [OFInvalidArgumentException exception];

	if (data.itemSize != _itemSize)
		@throw [OFInvalidArgumentException exception];

	count = data.count;
	minCount = (_count > count ? count : _count);

	if ((comparison = memcmp(_items, data.items,
	    minCount * _itemSize)) == 0) {
		if (_count > count)
			return OF_ORDERED_DESCENDING;
			return OFOrderedDescending;
		if (_count < count)
			return OF_ORDERED_ASCENDING;
			return OFOrderedAscending;

		return OF_ORDERED_SAME;
		return OFOrderedSame;
	}

	if (comparison > 0)
		return OF_ORDERED_DESCENDING;
		return OFOrderedDescending;
	else
		return OF_ORDERED_ASCENDING;
		return OFOrderedAscending;
}

- (unsigned long)hash
{
	uint32_t hash;

	OF_HASH_INIT(hash);

	for (size_t i = 0; i < _count * _itemSize; i++)
		OF_HASH_ADD(hash, ((uint8_t *)_items)[i]);

	OF_HASH_FINALIZE(hash);

	return hash;
}

- (OFData *)subdataWithRange: (of_range_t)range
- (OFData *)subdataWithRange: (OFRange)range
{
	OFData *ret;

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

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







-
-
-
+
+
+












-
+


-
+







-
+










-
+


-
+







}

- (OFString *)stringByBase64Encoding
{
	return of_base64_encode(_items, _count * _itemSize);
}

- (of_range_t)rangeOfData: (OFData *)data
		  options: (int)options
		    range: (of_range_t)range
- (OFRange)rangeOfData: (OFData *)data
	       options: (int)options
		 range: (OFRange)range
{
	const char *search;
	size_t searchLength;

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

	if (data == nil || data.itemSize != _itemSize)
		@throw [OFInvalidArgumentException exception];

	if ((searchLength = data.count) == 0)
		return of_range(0, 0);
		return OFMakeRange(0, 0);

	if (searchLength > range.length)
		return of_range(OF_NOT_FOUND, 0);
		return OFMakeRange(OFNotFound, 0);

	search = data.items;

	if (options & OF_DATA_SEARCH_BACKWARDS) {
		for (size_t i = range.length - searchLength;; i--) {
			if (memcmp(_items + i * _itemSize, search,
			    searchLength * _itemSize) == 0)
				return of_range(i, searchLength);
				return OFMakeRange(i, searchLength);

			/* No match and we're at the last item */
			if (i == 0)
				break;
		}
	} else {
		for (size_t i = range.location;
		    i <= range.length - searchLength; i++)
			if (memcmp(_items + i * _itemSize, search,
			    searchLength * _itemSize) == 0)
				return of_range(i, searchLength);
				return OFMakeRange(i, searchLength);
	}

	return of_range(OF_NOT_FOUND, 0);
	return OFMakeRange(OFNotFound, 0);
}

#ifdef OF_HAVE_FILES
- (void)writeToFile: (OFString *)path
{
	OFFile *file = [[OFFile alloc] initWithPath: path mode: @"w"];
	@try {