aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2010-03-20 12:56:56 +0000
committerJohannes Schickel2010-03-20 12:56:56 +0000
commit38b2b3c04fcba9b767ea0121a558abcb7314675f (patch)
treef276d4ea50809a12bd7365c51c8b50c154a287d6
parent8f30fa1a6cad5c03ff8fc6476357994592ec8d25 (diff)
downloadscummvm-rg350-38b2b3c04fcba9b767ea0121a558abcb7314675f.tar.gz
scummvm-rg350-38b2b3c04fcba9b767ea0121a558abcb7314675f.tar.bz2
scummvm-rg350-38b2b3c04fcba9b767ea0121a558abcb7314675f.zip
Move StringTokenizer to its own files (tokenizer.h/tokenizer.cpp).
svn-id: r48310
-rw-r--r--base/main.cpp1
-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
-rw-r--r--engines/parallaction/balloons.cpp4
-rw-r--r--gui/ListWidget.cpp1
-rw-r--r--gui/ThemeEngine.cpp2
-rw-r--r--gui/ThemeEval.cpp2
-rw-r--r--gui/ThemeParser.cpp2
11 files changed, 130 insertions, 62 deletions
diff --git a/base/main.cpp b/base/main.cpp
index ac4159f378..71a5f96382 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -45,6 +45,7 @@
#include "common/file.h"
#include "common/fs.h"
#include "common/system.h"
+#include "common/tokenizer.h"
#include "gui/GuiManager.h"
#include "gui/message.h"
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
diff --git a/engines/parallaction/balloons.cpp b/engines/parallaction/balloons.cpp
index bb6e10572b..c6e41b8f72 100644
--- a/engines/parallaction/balloons.cpp
+++ b/engines/parallaction/balloons.cpp
@@ -23,11 +23,11 @@
*
*/
-#include "common/util.h"
-
#include "parallaction/graphics.h"
#include "parallaction/parallaction.h"
+#include "common/tokenizer.h"
+
namespace Parallaction {
class WrappedLineFormatter {
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp
index 80289b9b80..ad6c7e0c3a 100644
--- a/gui/ListWidget.cpp
+++ b/gui/ListWidget.cpp
@@ -25,6 +25,7 @@
#include "common/system.h"
#include "common/events.h"
#include "common/frac.h"
+#include "common/tokenizer.h"
#include "gui/ListWidget.h"
#include "gui/ScrollBarWidget.h"
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp
index fb2603eb16..b472ad0535 100644
--- a/gui/ThemeEngine.cpp
+++ b/gui/ThemeEngine.cpp
@@ -23,13 +23,13 @@
*
*/
-#include "common/util.h"
#include "common/system.h"
#include "common/events.h"
#include "common/config-manager.h"
#include "common/file.h"
#include "common/fs.h"
#include "common/unzip.h"
+#include "common/tokenizer.h"
#include "graphics/colormasks.h"
#include "graphics/cursorman.h"
diff --git a/gui/ThemeEval.cpp b/gui/ThemeEval.cpp
index 8872741228..017d47fd29 100644
--- a/gui/ThemeEval.cpp
+++ b/gui/ThemeEval.cpp
@@ -28,6 +28,8 @@
#include "graphics/scaler.h"
+#include "common/tokenizer.h"
+
namespace GUI {
ThemeEval::~ThemeEval() {
diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp
index 4d7c91686b..e22d440bd9 100644
--- a/gui/ThemeParser.cpp
+++ b/gui/ThemeParser.cpp
@@ -30,6 +30,8 @@
#include "graphics/VectorRenderer.h"
+#include "common/tokenizer.h"
+
namespace GUI {
struct TextDataInfo {