ObjFW  Check-in [1421bc837b]

Overview
Comment:Make -[readLineWithEncoding:] compatible with \r\n linebreaks.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1421bc837b09ee23c482bd2a4806e7ab9bc7869c3b1acf8f3737929b8a2465a3
User & Date: js on 2010-01-23 11:25:43
Other Links: manifest | tags
Context
2010-01-24
18:54
Make retain/release atomic. check-in: b4a9924066 user: js tags: trunk
2010-01-23
11:25
Make -[readLineWithEncoding:] compatible with \r\n linebreaks. check-in: 1421bc837b user: js tags: trunk
2010-01-22
18:55
Apple allows BOOL copy to be 2 for mutableCopy on properties. check-in: 89db847794 user: js tags: trunk
Changes

Modified src/OFStream.m from [4d82bf6197] to [c12185893b].

115
116
117
118
119
120
121





122
123
124

125
126
127
128
129
130
131
115
116
117
118
119
120
121
122
123
124
125
126
127
128

129
130
131
132
133
134
135
136







+
+
+
+
+


-
+







	OFString *ret;

	/* Look if there's a line or \0 in our cache */
	if (cache != NULL) {
		for (i = 0; i < cache_len; i++) {
			if (OF_UNLIKELY(cache[i] == '\n' ||
			    cache[i] == '\0')) {
				ret_len = i;

				if (i > 0 && cache[i - 1] == '\r')
					ret_len--;

				ret = [OFString stringWithCString: cache
							 encoding: encoding
							   length: i];
							   length: ret_len];

				tmp = [self allocMemoryWithSize: cache_len -
								 i - 1];
				memcpy(tmp, cache + i + 1, cache_len - i - 1);

				[self freeMemory: cache];
				cache = tmp;
140
141
142
143
144
145
146





147
148
149
150

151
152
153
154
155
156
157
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

160
161
162
163
164
165
166
167







+
+
+
+
+



-
+







	tmp = [self allocMemoryWithSize: pagesize];

	@try {
		for (;;) {
			if ([self atEndOfStreamWithoutCache]) {
				if (cache == NULL)
					return nil;

				ret_len = cache_len;

				if (ret_len > 0 && cache[ret_len - 1] == '\r')
					ret_len--;

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

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

				return ret;
			}
166
167
168
169
170
171
172




173
174
175
176
177
178
179
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193







+
+
+
+







					ret_len = cache_len + i;
					ret_c = [self
					    allocMemoryWithSize: ret_len];

					if (cache != NULL)
						memcpy(ret_c, cache, cache_len);
					memcpy(ret_c + cache_len, tmp, i);

					if (ret_len > 0 &&
					    ret_c[ret_len - 1] == '\r')
						ret_len--;

					@try {
						ret = [OFString
						    stringWithCString: ret_c
							     encoding: encoding
							       length: ret_len];
					} @finally {