aboutsummaryrefslogtreecommitdiff
path: root/common/xmlparser.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/xmlparser.h')
-rw-r--r--common/xmlparser.h42
1 files changed, 40 insertions, 2 deletions
diff --git a/common/xmlparser.h b/common/xmlparser.h
index c7f7218857..d7d929cb9a 100644
--- a/common/xmlparser.h
+++ b/common/xmlparser.h
@@ -30,6 +30,7 @@
#include "graphics/surface.h"
#include "common/system.h"
#include "common/xmlparser.h"
+#include "common/stream.h"
#include "common/hashmap.h"
#include "common/hash-str.h"
@@ -37,6 +38,43 @@
namespace Common {
+class XMLStream {
+protected:
+ SeekableReadStream *_stream;
+ int _pos;
+
+public:
+ XMLStream() : _stream(0), _pos(0) {}
+
+ ~XMLStream() {
+ delete _stream;
+ }
+
+ SeekableReadStream *stream() {
+ return _stream;
+ }
+
+ const char operator [](int idx) {
+ assert(_stream && idx >= 0);
+
+ if (_pos + 1 != idx)
+ _stream->seek(idx, SEEK_SET);
+
+ _pos = idx;
+
+ return _stream->readSByte();
+ }
+
+ void fillFromMem(const char *buffer, bool dispose = false) {
+ delete _stream;
+ _stream = new MemoryReadStream((const byte*)buffer, strlen(buffer), dispose);
+ }
+
+ void fillFromFile(const char *filename) {
+
+ }
+};
+
/**
* The base XMLParser class implements generic functionality for parsing
* XML-like files.
@@ -132,7 +170,7 @@ protected:
/**
* Prints an error message when parsing fails and stops the parser.
*/
- virtual void parserError(const char *errorString, ...);
+ virtual void parserError(const char *errorString, ...) GCC_PRINTF(1, 2);
/**
* Skips spaces/whitelines etc. Returns true if any spaces were skipped.
@@ -199,7 +237,7 @@ protected:
}
int _pos; /** Current position on the XML buffer. */
- char *_text; /** Buffer with the text being parsed */
+ XMLStream _text; /** Buffer with the text being parsed */
char *_fileName;
ParserState _state; /** Internal state of the parser */