Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -46,10 +46,22 @@ * \return The line that was read, autoreleased, or nil if the end of the * stream has been reached. */ - (OFString*)readLine; +/** + * Read with the specified encoding until a newline, \\0 or end of stream + * occurs. + * + * If you want to use readNBytes afterwards again, you have to clear the cache + * before and optionally get the cache before clearing it! + * + * \return The line that was read, autoreleased, or nil if the end of the + * stream has been reached. + */ +- (OFString*)readLineWithEncoding: (enum of_string_encoding)encoding; + /** * Writes from a buffer into the stream. * * \param buf The buffer from which the data is written to the stream * \param size The size of the data that should be written Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -63,10 +63,15 @@ 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 */ @@ -73,10 +78,11 @@ 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); @@ -99,10 +105,11 @@ if (cache == NULL) return nil; ret = [OFString stringWithCString: cache + encoding: encoding length: cache_len]; [self freeMemory: cache]; cache = NULL; cache_len = 0; @@ -158,11 +165,12 @@ } [self freeMemory: tmp]; @try { ret = [OFString - stringWithCString: ret_c]; + stringWithCString: ret_c + encoding: encoding]; } @finally { [self freeMemory: ret_c]; } return ret; }