ObjFW  Diff

Differences From Artifact [a24c081951]:

To Artifact [4d39d4c3d2]:


61
62
63
64
65
66
67





68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- (OFString*)readLine
{





	size_t i, len;
	char *ret_c, *tmp, *tmp2;
	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 = [OFString stringWithCString: cache

							   length: i];

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

				[self freeMemory: cache];







>
>
>
>
>










>







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
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

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

- (OFString*)readLineWithEncoding: (enum of_string_encoding)encoding
{
	size_t i, len;
	char *ret_c, *tmp, *tmp2;
	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 = [OFString stringWithCString: cache
							 encoding: encoding
							   length: i];

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

				[self freeMemory: cache];
97
98
99
100
101
102
103

104
105
106
107
108
109
110
		if ([self atEndOfStream]) {
			[self freeMemory: tmp];

			if (cache == NULL)
				return nil;

			ret = [OFString stringWithCString: cache

						   length: cache_len];

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

			return ret;







>







103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
		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;
156
157
158
159
160
161
162
163

164
165
166
167
168
169
170
					cache = NULL;
					cache_len = 0;
				}
				[self freeMemory: tmp];

				@try {
					ret = [OFString
					    stringWithCString: ret_c];

				} @finally {
					[self freeMemory: ret_c];
				}
				return ret;
			}
		}








|
>







163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
					cache = NULL;
					cache_len = 0;
				}
				[self freeMemory: tmp];

				@try {
					ret = [OFString
					    stringWithCString: ret_c
						     encoding: encoding];
				} @finally {
					[self freeMemory: ret_c];
				}
				return ret;
			}
		}