ObjFW  Diff

Differences From Artifact [7e32841415]:

To Artifact [7e08799ba0]:


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







-
+



-
+















-
+







	[data makeImmutable];
	return data;
}

- (OFString *)readStringWithLength: (size_t)length
{
	return [self readStringWithLength: length
				 encoding: OF_STRING_ENCODING_UTF_8];
				 encoding: OFStringEncodingUTF8];
}

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

	@try {
		[self readIntoBuffer: buffer exactLength: length];
		ret = [OFString stringWithCString: buffer encoding: encoding];
	} @finally {
		free(buffer);
	}

	return ret;
}

- (OFString *)tryReadLineWithEncoding: (of_string_encoding_t)encoding
- (OFString *)tryReadLineWithEncoding: (OFStringEncoding)encoding
{
	size_t pageSize, bufferLength;
	char *buffer, *readBuffer;
	OFString *ret;

	/* Look if there's a line or \0 in our buffer */
	if (!_waitingForDelimiter && _readBuffer != NULL) {
787
788
789
790
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
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
876
877
878
879
880
881
787
788
789
790
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
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
876
877
878
879
880
881







-
+


-
+













-
+



-
+





-
+

















-
+




-
+







-
+

















-
+



-
+








	_waitingForDelimiter = true;
	return nil;
}

- (OFString *)readLine
{
	return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8];
	return [self readLineWithEncoding: OFStringEncodingUTF8];
}

- (OFString *)readLineWithEncoding: (of_string_encoding_t)encoding
- (OFString *)readLineWithEncoding: (OFStringEncoding)encoding
{
	OFString *line = nil;

	while ((line = [self tryReadLineWithEncoding: encoding]) == nil)
		if (self.atEndOfStream)
			return nil;

	return line;
}

#ifdef OF_HAVE_SOCKETS
- (void)asyncReadLine
{
	[self asyncReadLineWithEncoding: OF_STRING_ENCODING_UTF_8
	[self asyncReadLineWithEncoding: OFStringEncodingUTF8
			    runLoopMode: of_run_loop_mode_default];
}

- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding
{
	[self asyncReadLineWithEncoding: encoding
			    runLoopMode: of_run_loop_mode_default];
}

- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding
		      runLoopMode: (of_run_loop_mode_t)runLoopMode
{
	OFStream <OFReadyForReadingObserving> *stream =
	    (OFStream <OFReadyForReadingObserving> *)self;

	[OFRunLoop of_addAsyncReadLineForStream: stream
				       encoding: encoding
					   mode: runLoopMode
# ifdef OF_HAVE_BLOCKS
					  block: NULL
# endif
				       delegate: _delegate];
}

# ifdef OF_HAVE_BLOCKS
- (void)asyncReadLineWithBlock: (of_stream_async_read_line_block_t)block
{
	[self asyncReadLineWithEncoding: OF_STRING_ENCODING_UTF_8
	[self asyncReadLineWithEncoding: OFStringEncodingUTF8
			    runLoopMode: of_run_loop_mode_default
				  block: block];
}

- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding
			    block: (of_stream_async_read_line_block_t)block
{
	[self asyncReadLineWithEncoding: encoding
			    runLoopMode: of_run_loop_mode_default
				  block: block];
}

- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding
		      runLoopMode: (of_run_loop_mode_t)runLoopMode
			    block: (of_stream_async_read_line_block_t)block
{
	OFStream <OFReadyForReadingObserving> *stream =
	    (OFStream <OFReadyForReadingObserving> *)self;

	[OFRunLoop of_addAsyncReadLineForStream: stream
				       encoding: encoding
					   mode: runLoopMode
					  block: block
				       delegate: nil];
}
# endif
#endif

- (OFString *)tryReadLine
{
	return [self tryReadLineWithEncoding: OF_STRING_ENCODING_UTF_8];
	return [self tryReadLineWithEncoding: OFStringEncodingUTF8];
}

- (OFString *)tryReadTillDelimiter: (OFString *)delimiter
			  encoding: (of_string_encoding_t)encoding
			  encoding: (OFStringEncoding)encoding
{
	const char *delimiterCString;
	size_t j, delimiterLength, pageSize, bufferLength;
	char *buffer, *readBuffer;
	OFString *ret;

	delimiterCString = [delimiter cStringWithEncoding: encoding];
1030
1031
1032
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
1030
1031
1032
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







-
+



-
+














-
+







	return nil;
}


- (OFString *)readTillDelimiter: (OFString *)delimiter
{
	return [self readTillDelimiter: delimiter
			      encoding: OF_STRING_ENCODING_UTF_8];
			      encoding: OFStringEncodingUTF8];
}

- (OFString *)readTillDelimiter: (OFString *)delimiter
		       encoding: (of_string_encoding_t)encoding
		       encoding: (OFStringEncoding)encoding
{
	OFString *ret = nil;

	while ((ret = [self tryReadTillDelimiter: delimiter
					encoding: encoding]) == nil)
		if (self.atEndOfStream)
			return nil;

	return ret;
}

- (OFString *)tryReadTillDelimiter: (OFString *)delimiter
{
	return [self tryReadTillDelimiter: delimiter
				 encoding: OF_STRING_ENCODING_UTF_8];
				 encoding: OFStringEncodingUTF8];
}

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

1113
1114
1115
1116
1117
1118
1119
1120

1121
1122
1123
1124
1125

1126
1127
1128
1129
1130
1131
1132
1133

1134
1135
1136
1137
1138
1139
1140
1113
1114
1115
1116
1117
1118
1119

1120
1121
1122
1123
1124

1125
1126
1127
1128
1129
1130
1131
1132

1133
1134
1135
1136
1137
1138
1139
1140







-
+




-
+







-
+







# endif
				    delegate: _delegate];
}

- (void)asyncWriteString: (OFString *)string
{
	[self asyncWriteString: string
		      encoding: OF_STRING_ENCODING_UTF_8
		      encoding: OFStringEncodingUTF8
		   runLoopMode: of_run_loop_mode_default];
}

- (void)asyncWriteString: (OFString *)string
		encoding: (of_string_encoding_t)encoding
		encoding: (OFStringEncoding)encoding
{
	[self asyncWriteString: string
		      encoding: encoding
		   runLoopMode: of_run_loop_mode_default];
}

- (void)asyncWriteString: (OFString *)string
		encoding: (of_string_encoding_t)encoding
		encoding: (OFStringEncoding)encoding
	     runLoopMode: (of_run_loop_mode_t)runLoopMode
{
	OFStream <OFReadyForWritingObserving> *stream =
	    (OFStream <OFReadyForWritingObserving> *)self;

	[OFRunLoop of_addAsyncWriteForStream: stream
				      string: string
1169
1170
1171
1172
1173
1174
1175
1176

1177
1178
1179
1180
1181
1182

1183
1184
1185
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195
1196
1197
1198
1199
1169
1170
1171
1172
1173
1174
1175

1176
1177
1178
1179
1180
1181

1182
1183
1184
1185
1186
1187
1188
1189
1190
1191

1192
1193
1194
1195
1196
1197
1198
1199







-
+





-
+









-
+







				    delegate: nil];
}

- (void)asyncWriteString: (OFString *)string
		   block: (of_stream_async_write_string_block_t)block
{
	[self asyncWriteString: string
		      encoding: OF_STRING_ENCODING_UTF_8
		      encoding: OFStringEncodingUTF8
		   runLoopMode: of_run_loop_mode_default
			 block: block];
}

- (void)asyncWriteString: (OFString *)string
		encoding: (of_string_encoding_t)encoding
		encoding: (OFStringEncoding)encoding
		   block: (of_stream_async_write_string_block_t)block
{
	[self asyncWriteString: string
		      encoding: encoding
		   runLoopMode: of_run_loop_mode_default
			 block: block];
}

- (void)asyncWriteString: (OFString *)string
		encoding: (of_string_encoding_t)encoding
		encoding: (OFStringEncoding)encoding
	     runLoopMode: (of_run_loop_mode_t)runLoopMode
		   block: (of_stream_async_write_string_block_t)block
{
	OFStream <OFReadyForWritingObserving> *stream =
	    (OFStream <OFReadyForWritingObserving> *)self;

	[OFRunLoop of_addAsyncWriteForStream: stream
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
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







-
+


-
+
-




















-
+


-
+







	objc_autoreleasePoolPop(pool);

	return length;
}

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

- (size_t)writeString: (OFString *)string
- (size_t)writeString: (OFString *)string encoding: (OFStringEncoding)encoding
	     encoding: (of_string_encoding_t)encoding
{
	void *pool;
	size_t length;

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

	pool = objc_autoreleasePoolPush();
	length = [string cStringLengthWithEncoding: encoding];

	[self writeBuffer: [string cStringWithEncoding: encoding]
		   length: length];

	objc_autoreleasePoolPop(pool);

	return length;
}

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

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

	buffer = of_alloc(stringLength + 1, 1);

	@try {