COMMON: Add ReadStream::readString() and use it in the Ultima engine

This commit is contained in:
Cameron Cawley 2020-12-11 19:32:17 +00:00 committed by Paul Gilbert
parent 6c24e0de98
commit b5d6716d1d
4 changed files with 19 additions and 27 deletions

View File

@ -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;

View File

@ -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.

View File

@ -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

View File

@ -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