mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-30 23:43:10 +00:00
COMMON: Add ReadStream::readPascalString()
This commit is contained in:
parent
599184ab19
commit
0b95b734b8
@ -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...
|
||||
|
@ -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);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user