mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-19 00:15:30 +00:00
COMMON: Add ReadStream::readString() and use it in the Ultima engine
This commit is contained in:
parent
6c24e0de98
commit
b5d6716d1d
@ -52,6 +52,16 @@ SeekableReadStream *ReadStream::readStream(uint32 dataSize) {
|
||||
return new MemoryReadStream((byte *)buf, dataSize, DisposeAfterUse::YES);
|
||||
}
|
||||
|
||||
Common::String ReadStream::readString(char terminator) {
|
||||
Common::String result;
|
||||
char c;
|
||||
|
||||
while ((c = (char)readByte()) != terminator && !eos())
|
||||
result += c;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Common::String ReadStream::readPascalString(bool transformCR) {
|
||||
Common::String s;
|
||||
char *buf;
|
||||
|
@ -637,6 +637,15 @@ public:
|
||||
*/
|
||||
SeekableReadStream *readStream(uint32 dataSize);
|
||||
|
||||
/**
|
||||
* Reads in a terminated string. Upon successful completion,
|
||||
* return a string with the content of the line, *without*
|
||||
* the terminating character.
|
||||
*
|
||||
* @param terminator The terminating character to use.
|
||||
*/
|
||||
String readString(char terminator = 0);
|
||||
|
||||
/**
|
||||
* Read a string in Pascal format, that is, one byte is
|
||||
* string length, followed by string data.
|
||||
|
@ -27,18 +27,6 @@
|
||||
namespace Ultima {
|
||||
namespace Shared {
|
||||
|
||||
Common::String readStringFromStream(Common::SeekableReadStream *s) {
|
||||
Common::String result;
|
||||
char c;
|
||||
while ((c = s->readByte()) != '\0')
|
||||
result += c;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#define ERROR error("Could not open file - %s", name.c_str())
|
||||
|
||||
File::File(const Common::String &name) : Common::File(), _filesize(-1) {
|
||||
@ -93,15 +81,5 @@ bool File::eof() {
|
||||
return pos() >= _filesize;
|
||||
}
|
||||
|
||||
Common::String File::readString() {
|
||||
Common::String result;
|
||||
char c;
|
||||
|
||||
while (!eof() && (c = (char)readByte()) != '\0')
|
||||
result += c;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // End of namespace Shared
|
||||
} // End of namespace Ultima
|
||||
|
@ -74,11 +74,6 @@ public:
|
||||
* Differing eof that returns true when pos == size as well as beyond
|
||||
*/
|
||||
bool eof();
|
||||
|
||||
/**
|
||||
* Reads in a null terminated string
|
||||
*/
|
||||
Common::String readString();
|
||||
};
|
||||
|
||||
} // End of namespace Shared
|
||||
|
Loading…
x
Reference in New Issue
Block a user