ObjFW  Diff

Differences From Artifact [cc999ec09b]:

To Artifact [e6372d29b7]:


843
844
845
846
847
848
849
850

851
852
853
854
855
856
857
858
843
844
845
846
847
848
849

850

851
852
853
854
855
856
857







-
+
-







	return ret;
}

- (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String
				  length: (size_t)UTF8StringLength
			    freeWhenDone: (bool)freeWhenDone
{
	id ret = [self initWithUTF8String: UTF8String
	id ret = [self initWithUTF8String: UTF8String length: UTF8StringLength];
				   length: UTF8StringLength];

	if (freeWhenDone)
		free(UTF8String);

	return ret;
}

1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1017
1018
1019
1020
1021
1022
1023

1024
1025
1026
1027
1028
1029
1030







-







		 */
		if (SIZE_MAX - (size_t)fileSize < 1)
			@throw [OFOutOfRangeException exception];

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

			[file readIntoBuffer: tmp
				 exactLength: (size_t)fileSize];
		} @catch (id e) {
			free(tmp);
			@throw e;
		} @finally {
			[file release];
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
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







-
+
-





-
+
-






-
+
-






-
+
-

















-
+
-







	size_t length;

	length = self.UTF8StringLength;

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

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

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

		data = [OFMutableData dataWithItemSize: 1 capacity: length + 2];
		data = [OFMutableData dataWithCapacity: 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 capacity: length + 3];
		data = [OFMutableData dataWithCapacity: length + 3];

		[data addItem: &type];
		[data addItems: &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 capacity: length + 5];
		data = [OFMutableData dataWithCapacity: length + 5];

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

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

	return data;
}

- (of_range_t)rangeOfString: (OFString *)string
{
	return [self rangeOfString: string
			   options: 0
			     range: of_range(0, self.length)];
}

- (of_range_t)rangeOfString: (OFString *)string
- (of_range_t)rangeOfString: (OFString *)string options: (int)options
		    options: (int)options
{
	return [self rangeOfString: string
			   options: options
			     range: of_range(0, self.length)];
}

- (of_range_t)rangeOfString: (OFString *)string
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
2713
2714
2715
2716
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







-
+
-


-

-
+
-
-









-
+
-








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

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

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

	objc_autoreleasePoolPop(pool);
}
#endif

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

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

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