diff options
author | Sven Hesse | 2011-08-31 13:41:43 +0200 |
---|---|---|
committer | Sven Hesse | 2011-09-03 18:00:08 +0200 |
commit | eebd5a28f9a76f3021041480fd22d218bcfa18d9 (patch) | |
tree | d848a5cd3b63eaa87c78cd9100d2fb2d66c5b572 /engines | |
parent | 06021e46678bfa9524cc1a7ace1345b04fdd6317 (diff) | |
download | scummvm-rg350-eebd5a28f9a76f3021041480fd22d218bcfa18d9.tar.gz scummvm-rg350-eebd5a28f9a76f3021041480fd22d218bcfa18d9.tar.bz2 scummvm-rg350-eebd5a28f9a76f3021041480fd22d218bcfa18d9.zip |
GOB: Add Util::readString()
Diffstat (limited to 'engines')
-rw-r--r-- | engines/gob/util.cpp | 25 | ||||
-rw-r--r-- | engines/gob/util.h | 8 |
2 files changed, 29 insertions, 4 deletions
diff --git a/engines/gob/util.cpp b/engines/gob/util.cpp index 6d83745602..1add604ccb 100644 --- a/engines/gob/util.cpp +++ b/engines/gob/util.cpp @@ -20,6 +20,10 @@ * */ +#include "common/stream.h" +#include "common/events.h" + +#include "graphics/palette.h" #include "gob/gob.h" #include "gob/util.h" @@ -31,10 +35,6 @@ #include "gob/videoplayer.h" #include "gob/sound/sound.h" -#include "common/events.h" - -#include "graphics/palette.h" - namespace Gob { Util::Util(GobEngine *vm) : _vm(vm) { @@ -534,6 +534,23 @@ Common::String Util::setExtension(const Common::String &str, const Common::Strin return str + ext; } +Common::String Util::readString(Common::SeekableReadStream &stream, int n) { + Common::String str; + + char c; + while (n-- > 0) { + if ((c = stream.readByte()) == '\0') + break; + + str += c; + } + + if (n > 0) + stream.skip(n); + + return str; +} + /* NOT IMPLEMENTED */ void Util::checkJoystick() { _vm->_global->_useJoystick = 0; diff --git a/engines/gob/util.h b/engines/gob/util.h index a6a689c1d2..7c1e44c0f6 100644 --- a/engines/gob/util.h +++ b/engines/gob/util.h @@ -23,8 +23,13 @@ #ifndef GOB_UTIL_H #define GOB_UTIL_H +#include "common/str.h" #include "common/keyboard.h" +namespace Common { + class SeekableReadStream; +} + namespace Gob { class GobEngine; @@ -131,6 +136,9 @@ public: static char *setExtension(char *str, const char *ext); static Common::String setExtension(const Common::String &str, const Common::String &ext); + /** Read a constant-length string out of a stream. */ + static Common::String readString(Common::SeekableReadStream &stream, int n); + Util(GobEngine *vm); protected: |