ObjFW  Diff

Differences From Artifact [2c5ce7298e]:

To Artifact [dff3658c98]:


48
49
50
51
52
53
54








55
56
57
58
59
60
61






























62
63
64
65
66
67
68
#endif

	return self;
}

- (BOOL)atEndOfStream
{








	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- (size_t)readNBytes: (size_t)size
	  intoBuffer: (char*)buf
{






























	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

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







>
>
>
>
>
>
>
>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







48
49
50
51
52
53
54
55
56
57
58
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
96
97
98
99
100
101
102
103
104
105
106
#endif

	return self;
}

- (BOOL)atEndOfStream
{
	if (cache != NULL)
		return NO;

	return [self atEndOfStreamWithoutCache];
}

- (BOOL)atEndOfStreamWithoutCache
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- (size_t)readNBytes: (size_t)size
	  intoBuffer: (char*)buf
{
	if (cache == NULL)
		return [self readNBytesWithoutCache: size
					 intoBuffer: buf];

	if (size >= cache_len) {
		size_t ret = cache_len;
		memcpy(buf, cache, cache_len);

		[self freeMemory: cache];
		cache = NULL;
		cache_len = 0;

		return ret;
	} else {
		char *tmp = [self allocMemoryWithSize: cache_len - size];
		memcpy(tmp, cache + size, cache_len - size);

		memcpy(buf, cache, size);

		[self freeMemory: cache];
		cache = tmp;
		cache_len -= size;

		return size;
	}
}

- (size_t)readNBytesWithoutCache: (size_t)size
		      intoBuffer: (char*)buf
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- (OFString*)readLine
{
	return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8];
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
		}
	}

	/* Read until we get a newline or \0 */
	tmp = [self allocMemoryWithSize: pagesize];

	for (;;) {
		if ([self atEndOfStream]) {
			[self freeMemory: tmp];

			if (cache == NULL)
				return nil;

			ret = [OFString stringWithCString: cache
						 encoding: encoding
						   length: cache_len];

			[self freeMemory: cache];
			cache = NULL;
			cache_len = 0;

			return ret;
		}

		@try {
			len = [self readNBytes: pagesize - 1
				    intoBuffer: tmp];
		} @catch (OFException *e) {
			[self freeMemory: tmp];
			@throw e;
		}

		/* Look if there's a newline or \0 */
		for (i = 0; i < len; i++) {







|

















|
|







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

	/* Read until we get a newline or \0 */
	tmp = [self allocMemoryWithSize: pagesize];

	for (;;) {
		if ([self atEndOfStreamWithoutCache]) {
			[self freeMemory: tmp];

			if (cache == NULL)
				return nil;

			ret = [OFString stringWithCString: cache
						 encoding: encoding
						   length: cache_len];

			[self freeMemory: cache];
			cache = NULL;
			cache_len = 0;

			return ret;
		}

		@try {
			len = [self readNBytesWithoutCache: pagesize
						intoBuffer: tmp];
		} @catch (OFException *e) {
			[self freeMemory: tmp];
			@throw e;
		}

		/* Look if there's a newline or \0 */
		for (i = 0; i < len; i++) {
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

- (size_t)writeString: (OFString*)str
{
	return [self writeNBytes: [str cStringLength]
		      fromBuffer: [str cString]];
}

- (size_t)getCache: (char**)ptr
{
	if (ptr != NULL)
		*ptr = cache;

	return cache_len;
}

- clearCache
{
	[self freeMemory: cache];

	cache = NULL;
	cache_len = 0;

	return self;
}

- close
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}
@end







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






241
242
243
244
245
246
247


















248
249
250
251
252
253

- (size_t)writeString: (OFString*)str
{
	return [self writeNBytes: [str cStringLength]
		      fromBuffer: [str cString]];
}



















- close
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}
@end