diff options
author | Eugene Sandulenko | 2017-01-14 12:45:58 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2017-01-14 12:45:58 +0100 |
commit | 0b95b734b85219044fe817c0609d1d23d6203700 (patch) | |
tree | 550b9a02396d1239fc0b994be5eea1e5587582d5 | |
parent | 599184ab19e2ff6500c0c7fcbb314a5e7cd0e2b0 (diff) | |
download | scummvm-rg350-0b95b734b85219044fe817c0609d1d23d6203700.tar.gz scummvm-rg350-0b95b734b85219044fe817c0609d1d23d6203700.tar.bz2 scummvm-rg350-0b95b734b85219044fe817c0609d1d23d6203700.zip |
COMMON: Add ReadStream::readPascalString()
-rw-r--r-- | common/stream.cpp | 21 | ||||
-rw-r--r-- | common/stream.h | 8 |
2 files changed, 29 insertions, 0 deletions
diff --git a/common/stream.cpp b/common/stream.cpp index 08774312fd..8d93888020 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -39,6 +39,27 @@ SeekableReadStream *ReadStream::readStream(uint32 dataSize) { return new MemoryReadStream((byte *)buf, dataSize, DisposeAfterUse::YES); } +Common::String ReadStream::readPascalString(bool transformCR) { + Common::String s; + char *buf; + int len; + int i; + + len = readByte(); + buf = (char *)malloc(len + 1); + for (i = 0; i < len; i++) { + buf[i] = readByte(); + if (transformCR && buf[i] == 0x0d) + buf[i] = '\n'; + } + + buf[i] = 0; + + s = buf; + free(buf); + + return s; +} uint32 MemoryReadStream::read(void *dataPtr, uint32 dataSize) { // Read at most as many bytes as are still available... diff --git a/common/stream.h b/common/stream.h index 30107720dc..0ff430f41b 100644 --- a/common/stream.h +++ b/common/stream.h @@ -427,6 +427,14 @@ public: */ SeekableReadStream *readStream(uint32 dataSize); + /** + * Read stream in Pascal format, that is, one byte is + * string length, followed by string data + * + * @param transformCR if set (default), then transform \r into \n + */ + Common::String readPascalString(bool transformCR = true); + }; |