diff options
| author | Max Horn | 2008-09-03 17:53:25 +0000 |
|---|---|---|
| committer | Max Horn | 2008-09-03 17:53:25 +0000 |
| commit | 57e724bfc34508b7c43441e8d274e76ce17b6e19 (patch) | |
| tree | 95dcd8a5cd04d8f2ee1b122b20ca176f51e78198 /common | |
| parent | 5c72c2fca76d33633a91c7a4ea19886323f8694c (diff) | |
| download | scummvm-rg350-57e724bfc34508b7c43441e8d274e76ce17b6e19.tar.gz scummvm-rg350-57e724bfc34508b7c43441e8d274e76ce17b6e19.tar.bz2 scummvm-rg350-57e724bfc34508b7c43441e8d274e76ce17b6e19.zip | |
Renamed SeekableReadStream::readLine to SeekableReadStream::readLine_OLD; added a new alternate SeekableReadStream::readLine() instead
svn-id: r34315
Diffstat (limited to 'common')
| -rw-r--r-- | common/config-file.cpp | 2 | ||||
| -rw-r--r-- | common/stream.cpp | 16 | ||||
| -rw-r--r-- | common/stream.h | 32 |
3 files changed, 39 insertions, 11 deletions
diff --git a/common/config-file.cpp b/common/config-file.cpp index 42d67109fa..b01f759782 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -88,7 +88,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { while (!stream.eos()) { lineno++; - if (!stream.readLine(buf, MAXLINELEN)) + if (!stream.readLine_OLD(buf, MAXLINELEN)) break; if (buf[0] == '#') { diff --git a/common/stream.cpp b/common/stream.cpp index e06cc28415..1ca741483e 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -86,7 +86,7 @@ void MemoryReadStream::seek(int32 offs, int whence) { #define LF 0x0A #define CR 0x0D -char *SeekableReadStream::readLine(char *buf, size_t bufSize) { +char *SeekableReadStream::readLine_OLD(char *buf, size_t bufSize) { assert(buf && bufSize > 0); char *p = buf; size_t len = 0; @@ -202,6 +202,20 @@ char *SeekableReadStream::readLine_NEW(char *buf, size_t bufSize) { return buf; } +String SeekableReadStream::readLine() { + // Read a line + String line; + while (line.lastChar() != '\n') { + char buf[256]; + if (!readLine_NEW(buf, 256)) + break; + line += buf; + } + + return line; +} + + uint32 SubReadStream::read(void *dataPtr, uint32 dataSize) { dataSize = MIN(dataSize, _end - _pos); diff --git a/common/stream.h b/common/stream.h index 01a946e685..81bb3dc91a 100644 --- a/common/stream.h +++ b/common/stream.h @@ -320,9 +320,10 @@ public: * Read one line of text from a CR or CR/LF terminated plain text file. * This method is a rough analog of the (f)gets function. * - * @bug A main difference (and flaw) in this function is that there is no - * way to detect that a line exceeeds the length of the buffer. - * Code which needs this should use the new readLine_NEW() method instead. + * @deprecated This method has a major flaw: There is no way to detect + * whether a line exceeeds the length of the buffer, resulting in breakage + * when overlong lines are encountered. + * Use readLine_NEW() or readline() instead. * * @param buf the buffer to store into * @param bufSize the size of the buffer @@ -331,16 +332,16 @@ public: * @note The line terminator (CR or CR/LF) is stripped and not inserted * into the buffer. */ - virtual char *readLine(char *buf, size_t bufSize); + virtual char *readLine_OLD(char *buf, size_t bufSize); /** * Reads at most one less than the number of characters specified * by bufSize from the and stores them in the string buf. Reading - * stops when the end of a line is reached (CR, CR/LF or LF), at - * end-of-file or error. The newline, if any, is retained (CR and - * CR/LF are translated to LF = 0xA = '\n'). If any characters are - * read and there is no error, a `\0' character is appended to end - * the string. + * stops when the end of a line is reached (CR, CR/LF or LF), and + * at end-of-file or error. The newline, if any, is retained (CR + * and CR/LF are translated to LF = 0xA = '\n'). If any characters + * are read and there is no error, a `\0' character is appended + * to end the string. * * Upon successful completion, return a pointer to the string. If * end-of-file occurs before any characters are read, returns NULL @@ -354,6 +355,19 @@ public: * @return a pointer to the read string, or NULL if an error occurred */ virtual char *readLine_NEW(char *s, size_t bufSize); + + + /** + * Reads a full line and returns it as a Common::String. Reading + * stops when the end of a line is reached (CR, CR/LF or LF), and + * at end-of-file or error. + * + * Upon successful completion, return a string with the content + * of the line, *without* the end of a line marker. This method + * does not indicate whether an error occured. Callers muse use + * ioFailed() or eos() to determine whether an exception occurred. + */ + virtual String readLine(); }; /** |
