mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-20 19:21:46 +00:00
Move StringTokenizer to its own files (tokenizer.h/tokenizer.cpp).
svn-id: r48310
This commit is contained in:
parent
8f30fa1a6c
commit
38b2b3c04f
@ -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"
|
||||
|
@ -20,6 +20,7 @@ MODULE_OBJS := \
|
||||
stream.o \
|
||||
util.o \
|
||||
system.o \
|
||||
tokenizer.o \
|
||||
unarj.o \
|
||||
unzip.o \
|
||||
xmlparser.o \
|
||||
|
59
common/tokenizer.cpp
Normal file
59
common/tokenizer.cpp
Normal file
@ -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
|
||||
|
61
common/tokenizer.h
Normal file
61
common/tokenizer.h
Normal file
@ -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
|
@ -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
|
||||
//
|
||||
|
@ -65,32 +65,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.
|
||||
|
@ -23,11 +23,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/util.h"
|
||||
|
||||
#include "parallaction/graphics.h"
|
||||
#include "parallaction/parallaction.h"
|
||||
|
||||
#include "common/tokenizer.h"
|
||||
|
||||
namespace Parallaction {
|
||||
|
||||
class WrappedLineFormatter {
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -28,6 +28,8 @@
|
||||
|
||||
#include "graphics/scaler.h"
|
||||
|
||||
#include "common/tokenizer.h"
|
||||
|
||||
namespace GUI {
|
||||
|
||||
ThemeEval::~ThemeEval() {
|
||||
|
@ -30,6 +30,8 @@
|
||||
|
||||
#include "graphics/VectorRenderer.h"
|
||||
|
||||
#include "common/tokenizer.h"
|
||||
|
||||
namespace GUI {
|
||||
|
||||
struct TextDataInfo {
|
||||
|
Loading…
x
Reference in New Issue
Block a user