aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/module.mk1
-rw-r--r--common/tokenizer.cpp59
-rw-r--r--common/tokenizer.h61
-rw-r--r--common/util.cpp33
-rw-r--r--common/util.h26
5 files changed, 121 insertions, 59 deletions
diff --git a/common/module.mk b/common/module.mk
index 3516e3cd4e..4ea28a63d4 100644
--- a/common/module.mk
+++ b/common/module.mk
@@ -20,6 +20,7 @@ MODULE_OBJS := \
stream.o \
util.o \
system.o \
+ tokenizer.o \
unarj.o \
unzip.o \
xmlparser.o \
diff --git a/common/tokenizer.cpp b/common/tokenizer.cpp
new file mode 100644
index 0000000000..8bca133b5b
--- /dev/null
+++ b/common/tokenizer.cpp
@@ -0,0 +1,59 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#include "common/tokenizer.h"
+
+namespace Common {
+
+StringTokenizer::StringTokenizer(const String &str, const String &delimiters) : _str(str), _delimiters(delimiters) {
+ reset();
+}
+
+void StringTokenizer::reset() {
+ _tokenBegin = _tokenEnd = 0;
+}
+
+bool StringTokenizer::empty() const {
+ // Search for the next token's start (i.e. the next non-delimiter character)
+ for (uint i = _tokenEnd; i < _str.size(); i++) {
+ if (!_delimiters.contains(_str[i]))
+ return false; // Found a token so the tokenizer is not empty
+ }
+ // Didn't find any more tokens so the tokenizer is empty
+ return true;
+}
+
+String StringTokenizer::nextToken() {
+ // Seek to next token's start (i.e. jump over the delimiters before next token)
+ for (_tokenBegin = _tokenEnd; _tokenBegin < _str.size() && _delimiters.contains(_str[_tokenBegin]); _tokenBegin++)
+ ;
+ // Seek to the token's end (i.e. jump over the non-delimiters)
+ for (_tokenEnd = _tokenBegin; _tokenEnd < _str.size() && !_delimiters.contains(_str[_tokenEnd]); _tokenEnd++)
+ ;
+ // Return the found token
+ return String(_str.c_str() + _tokenBegin, _tokenEnd - _tokenBegin);
+}
+
+} // End of namespace Common
+
diff --git a/common/tokenizer.h b/common/tokenizer.h
new file mode 100644
index 0000000000..0ee6e37da7
--- /dev/null
+++ b/common/tokenizer.h
@@ -0,0 +1,61 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef COMMON_TOKENIZER_H
+#define COMMON_TOKENIZER_H
+
+#include "common/scummsys.h"
+#include "common/str.h"
+
+namespace Common {
+
+/**
+ * A simple non-optimized string tokenizer.
+ *
+ * Example of use:
+ * StringTokenizer("Now, this is a test!", " ,!") gives tokens "Now", "this", "is", "a" and "test" using nextToken().
+ */
+class StringTokenizer {
+public:
+ /**
+ * Creates a StringTokenizer.
+ * @param str The string to be tokenized.
+ * @param delimiters String containing all the delimiter characters (i.e. the characters to be ignored).
+ * @note Uses space, horizontal tab, carriage return, newline, form feed and vertical tab as delimiters by default.
+ */
+ StringTokenizer(const String &str, const String &delimiters = " \t\r\n\f\v");
+ void reset(); ///< Resets the tokenizer to its initial state
+ bool empty() const; ///< Returns true if there are no more tokens left in the string, false otherwise
+ String nextToken(); ///< Returns the next token from the string (Or an empty string if there are no more tokens)
+
+private:
+ const String _str; ///< The string to be tokenized
+ const String _delimiters; ///< String containing all the delimiter characters
+ uint _tokenBegin; ///< Latest found token's begin (Valid after a call to nextToken(), zero otherwise)
+ uint _tokenEnd; ///< Latest found token's end (Valid after a call to nextToken(), zero otherwise)
+};
+
+} // End of namespace Common
+
+#endif
diff --git a/common/util.cpp b/common/util.cpp
index f04b403e19..3bc5edf7fb 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -30,39 +30,6 @@
namespace Common {
-StringTokenizer::StringTokenizer(const String &str, const String &delimiters) : _str(str), _delimiters(delimiters) {
- reset();
-}
-
-void StringTokenizer::reset() {
- _tokenBegin = _tokenEnd = 0;
-}
-
-bool StringTokenizer::empty() const {
- // Search for the next token's start (i.e. the next non-delimiter character)
- for (uint i = _tokenEnd; i < _str.size(); i++) {
- if (!_delimiters.contains(_str[i]))
- return false; // Found a token so the tokenizer is not empty
- }
- // Didn't find any more tokens so the tokenizer is empty
- return true;
-}
-
-String StringTokenizer::nextToken() {
- // Seek to next token's start (i.e. jump over the delimiters before next token)
- for (_tokenBegin = _tokenEnd; _tokenBegin < _str.size() && _delimiters.contains(_str[_tokenBegin]); _tokenBegin++)
- ;
- // Seek to the token's end (i.e. jump over the non-delimiters)
- for (_tokenEnd = _tokenBegin; _tokenEnd < _str.size() && !_delimiters.contains(_str[_tokenEnd]); _tokenEnd++)
- ;
- // Return the found token
- return String(_str.c_str() + _tokenBegin, _tokenEnd - _tokenBegin);
-}
-
-
-#pragma mark -
-
-
//
// Print hexdump of the data passed in
//
diff --git a/common/util.h b/common/util.h
index e5d2f91b32..3969945271 100644
--- a/common/util.h
+++ b/common/util.h
@@ -66,32 +66,6 @@ template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
namespace Common {
/**
- * A simple non-optimized string tokenizer.
- *
- * Example of use:
- * StringTokenizer("Now, this is a test!", " ,!") gives tokens "Now", "this", "is", "a" and "test" using nextToken().
- */
-class StringTokenizer {
-public:
- /**
- * Creates a StringTokenizer.
- * @param str The string to be tokenized.
- * @param delimiters String containing all the delimiter characters (i.e. the characters to be ignored).
- * @note Uses space, horizontal tab, carriage return, newline, form feed and vertical tab as delimiters by default.
- */
- StringTokenizer(const String &str, const String &delimiters = " \t\r\n\f\v");
- void reset(); ///< Resets the tokenizer to its initial state
- bool empty() const; ///< Returns true if there are no more tokens left in the string, false otherwise
- String nextToken(); ///< Returns the next token from the string (Or an empty string if there are no more tokens)
-
-private:
- const String _str; ///< The string to be tokenized
- const String _delimiters; ///< String containing all the delimiter characters
- uint _tokenBegin; ///< Latest found token's begin (Valid after a call to nextToken(), zero otherwise)
- uint _tokenEnd; ///< Latest found token's end (Valid after a call to nextToken(), zero otherwise)
-};
-
-/**
* Print a hexdump of the data passed in. The number of bytes per line is
* customizable.
* @param data the data to be dumped