ObjFW  Diff

Differences From Artifact [75be1c56bd]:

To Artifact [ab9d9164f8]:


1045
1046
1047
1048
1049
1050
1051
1052

1053
1054
1055




1056
1057
1058
1059
1060
1061
1062
1063

		tmp[(size_t)fileSize] = '\0';
	} @catch (id e) {
		[self release];
		@throw e;
	}

	if (encoding == OF_STRING_ENCODING_UTF_8)

		self = [self initWithUTF8StringNoCopy: tmp
					       length: (size_t)fileSize
					 freeWhenDone: true];




	else {
		@try {
			self = [self initWithCString: tmp
					    encoding: encoding
					      length: (size_t)fileSize];
		} @finally {
			free(tmp);
		}







|
>
|
|
|
>
>
>
>
|







1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068

		tmp[(size_t)fileSize] = '\0';
	} @catch (id e) {
		[self release];
		@throw e;
	}

	if (encoding == OF_STRING_ENCODING_UTF_8) {
		@try {
			self = [self initWithUTF8StringNoCopy: tmp
						       length: (size_t)fileSize
						 freeWhenDone: true];
		} @catch (id e) {
			free(tmp);
			@throw e;
		}
	} else {
		@try {
			self = [self initWithCString: tmp
					    encoding: encoding
					      length: (size_t)fileSize];
		} @finally {
			free(tmp);
		}
1431
1432
1433
1434
1435
1436
1437

1438
1439
1440




1441
1442
1443
1444
1445
1446
1447
		}

		break;
	default:
		@throw [OFInvalidEncodingException exception];
	}


	return [OFData dataWithItemsNoCopy: cString
				     count: cStringLength + 1
			      freeWhenDone: true].items;




}

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







>
|
|
|
>
>
>
>







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

		break;
	default:
		@throw [OFInvalidEncodingException exception];
	}

	@try {
		return [OFData dataWithItemsNoCopy: cString
					     count: cStringLength + 1
				      freeWhenDone: true].items;
	} @catch (id e) {
		free(cString);
		@throw e;
	}
}

- (const char *)cStringWithEncoding: (of_string_encoding_t)encoding
{
	return [self of_cStringWithEncoding: encoding
				      lossy: false];
}
2501
2502
2503
2504
2505
2506
2507





2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
	size_t length = self.length;
	of_unichar_t *buffer;

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





	} @catch (id e) {
		free(buffer);
		@throw e;
	}

	return [OFData dataWithItemsNoCopy: buffer
				     count: length
				  itemSize: sizeof(of_unichar_t)
			      freeWhenDone: true].items;
}

- (const of_char16_t *)UTF16String
{
	return [self UTF16StringWithByteOrder: OF_BYTE_ORDER_NATIVE];
}








>
>
>
>
>




<
<
<
<
<







2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526





2527
2528
2529
2530
2531
2532
2533
	size_t length = self.length;
	of_unichar_t *buffer;

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

		return [OFData dataWithItemsNoCopy: buffer
					     count: length
					  itemSize: sizeof(of_unichar_t)
				      freeWhenDone: true].items;
	} @catch (id e) {
		free(buffer);
		@throw e;
	}





}

- (const of_char16_t *)UTF16String
{
	return [self UTF16StringWithByteOrder: OF_BYTE_ORDER_NATIVE];
}

2564
2565
2566
2567
2568
2569
2570

2571
2572
2573
2574




2575
2576
2577
2578
2579
2580
2581
		buffer = of_realloc(buffer, j + 1, sizeof(of_char16_t));
	} @catch (OFOutOfMemoryException *e) {
		/* We don't care, as we only tried to make it smaller */
	}

	objc_autoreleasePoolPop(pool);


	return [OFData dataWithItemsNoCopy: buffer
				     count: j + 1
				  itemSize: sizeof(of_char16_t)
			      freeWhenDone: true].items;




}

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








>
|
|
|
|
>
>
>
>







2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
		buffer = of_realloc(buffer, j + 1, sizeof(of_char16_t));
	} @catch (OFOutOfMemoryException *e) {
		/* We don't care, as we only tried to make it smaller */
	}

	objc_autoreleasePoolPop(pool);

	@try {
		return [OFData dataWithItemsNoCopy: buffer
					     count: j + 1
					  itemSize: sizeof(of_char16_t)
				      freeWhenDone: true].items;
	} @catch (id e) {
		free(buffer);
		@throw e;
	}
}

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

2599
2600
2601
2602
2603
2604
2605









2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
	of_char32_t *buffer;

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









	} @catch (id e) {
		free(buffer);
		@throw e;
	}

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

	return [OFData dataWithItemsNoCopy: buffer
				     count: length + 1
				  itemSize: sizeof(of_char32_t)
			      freeWhenDone: true].items;
}

- (OFData *)dataWithEncoding: (of_string_encoding_t)encoding
{
	void *pool = objc_autoreleasePoolPush();
	OFData *data =
	    [OFData dataWithItems: [self cStringWithEncoding: encoding]







>
>
>
>
>
>
>
>
>




<
<
<
<
<
<
<
<
<







2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633









2634
2635
2636
2637
2638
2639
2640
	of_char32_t *buffer;

	buffer = of_malloc(length + 1, sizeof(of_char32_t));
	@try {
		[self getCharacters: buffer
			    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
					     count: length + 1
					  itemSize: sizeof(of_char32_t)
				      freeWhenDone: true].items;
	} @catch (id e) {
		free(buffer);
		@throw e;
	}









}

- (OFData *)dataWithEncoding: (of_string_encoding_t)encoding
{
	void *pool = objc_autoreleasePoolPush();
	OFData *data =
	    [OFData dataWithItems: [self cStringWithEncoding: encoding]