66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
- (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' ||
|
|
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
- (OFString*)readLine
{
return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8];
}
- (OFString*)readLineWithEncoding: (enum of_string_encoding)encoding
{
size_t i, len, ret_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' ||
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
[self freeMemory: tmp];
@throw e;
}
/* Look if there's a newline or \0 */
for (i = 0; i < len; i++) {
if (OF_UNLIKELY(tmp[i] == '\n' || tmp[i] == '\0')) {
@try {
ret_c = [self
allocMemoryWithSize: cache_len + i];
} @catch (OFException *e) {
[self freeMemory: tmp];
@throw e;
}
if (cache != NULL)
memcpy(ret_c, cache, cache_len);
memcpy(ret_c + cache_len, tmp, i);
|
>
|
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
[self freeMemory: tmp];
@throw e;
}
/* Look if there's a newline or \0 */
for (i = 0; i < len; i++) {
if (OF_UNLIKELY(tmp[i] == '\n' || tmp[i] == '\0')) {
ret_len = cache_len + i;
@try {
ret_c = [self
allocMemoryWithSize: ret_len];
} @catch (OFException *e) {
[self freeMemory: tmp];
@throw e;
}
if (cache != NULL)
memcpy(ret_c, cache, cache_len);
memcpy(ret_c + cache_len, tmp, i);
|
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
}
[self freeMemory: tmp];
@try {
ret = [OFString
stringWithCString: ret_c
encoding: encoding
length: cache_len + i];
} @finally {
[self freeMemory: ret_c];
}
return ret;
}
}
|
|
|
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
}
[self freeMemory: tmp];
@try {
ret = [OFString
stringWithCString: ret_c
encoding: encoding
length: ret_len];
} @finally {
[self freeMemory: ret_c];
}
return ret;
}
}
|