COMMON: Add ReadStream::readString() and use it in the Ultima engine
This commit is contained in:
parent
6c24e0de98
commit
b5d6716d1d
4 changed files with 19 additions and 27 deletions
|
@ -52,6 +52,16 @@ SeekableReadStream *ReadStream::readStream(uint32 dataSize) {
|
||||||
return new MemoryReadStream((byte *)buf, dataSize, DisposeAfterUse::YES);
|
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 ReadStream::readPascalString(bool transformCR) {
|
||||||
Common::String s;
|
Common::String s;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
|
@ -637,6 +637,15 @@ public:
|
||||||
*/
|
*/
|
||||||
SeekableReadStream *readStream(uint32 dataSize);
|
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
|
* Read a string in Pascal format, that is, one byte is
|
||||||
* string length, followed by string data.
|
* string length, followed by string data.
|
||||||
|
|
|
@ -27,18 +27,6 @@
|
||||||
namespace Ultima {
|
namespace Ultima {
|
||||||
namespace Shared {
|
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())
|
#define ERROR error("Could not open file - %s", name.c_str())
|
||||||
|
|
||||||
File::File(const Common::String &name) : Common::File(), _filesize(-1) {
|
File::File(const Common::String &name) : Common::File(), _filesize(-1) {
|
||||||
|
@ -93,15 +81,5 @@ bool File::eof() {
|
||||||
return pos() >= _filesize;
|
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 Shared
|
||||||
} // End of namespace Ultima
|
} // End of namespace Ultima
|
||||||
|
|
|
@ -74,11 +74,6 @@ public:
|
||||||
* Differing eof that returns true when pos == size as well as beyond
|
* Differing eof that returns true when pos == size as well as beyond
|
||||||
*/
|
*/
|
||||||
bool eof();
|
bool eof();
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads in a null terminated string
|
|
||||||
*/
|
|
||||||
Common::String readString();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Shared
|
} // End of namespace Shared
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue