From 7a818009b4c20df1811c0b158b0f8acfe0e3d208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einar=20Johan=20Tr=C3=B8an=20S=C3=B8ma=CC=8Aen?= Date: Mon, 23 Jul 2012 02:23:14 +0200 Subject: [PATCH] WINTERMUTE: Clean out unused utils. --- engines/wintermute/base/base_game.cpp | 1 + .../base/scriptables/script_engine.cpp | 2 +- .../base/scriptables/script_engine.h | 1 - engines/wintermute/utils/path_util.h | 2 +- engines/wintermute/utils/string_util.cpp | 96 ------------------- engines/wintermute/utils/string_util.h | 12 +-- engines/wintermute/utils/utils.cpp | 64 +------------ engines/wintermute/utils/utils.h | 5 - 8 files changed, 6 insertions(+), 177 deletions(-) diff --git a/engines/wintermute/base/base_game.cpp b/engines/wintermute/base/base_game.cpp index 6897a377764..d3da177a927 100644 --- a/engines/wintermute/base/base_game.cpp +++ b/engines/wintermute/base/base_game.cpp @@ -60,6 +60,7 @@ #include "engines/wintermute/base/scriptables/script_ext_math.h" #include "engines/wintermute/video/video_player.h" #include "engines/wintermute/video/video_theora_player.h" +#include "engines/wintermute/utils/utils.h" #include "engines/wintermute/wintermute.h" #include "common/savefile.h" #include "common/textconsole.h" diff --git a/engines/wintermute/base/scriptables/script_engine.cpp b/engines/wintermute/base/scriptables/script_engine.cpp index 44add054c5b..e8544d8cd64 100644 --- a/engines/wintermute/base/scriptables/script_engine.cpp +++ b/engines/wintermute/base/scriptables/script_engine.cpp @@ -37,7 +37,7 @@ #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/sound/base_sound.h" #include "engines/wintermute/base/base_file_manager.h" - +#include "engines/wintermute/utils/utils.h" namespace WinterMute { diff --git a/engines/wintermute/base/scriptables/script_engine.h b/engines/wintermute/base/scriptables/script_engine.h index 06d61b41563..6d2ed92e4f7 100644 --- a/engines/wintermute/base/scriptables/script_engine.h +++ b/engines/wintermute/base/scriptables/script_engine.h @@ -33,7 +33,6 @@ #include "engines/wintermute/coll_templ.h" #include "engines/wintermute/base/base.h" #include "engines/wintermute/wme_debugger.h" -#include "engines/wintermute/utils/utils.h" #include "engines/wintermute/platform_osystem.h" namespace WinterMute { diff --git a/engines/wintermute/utils/path_util.h b/engines/wintermute/utils/path_util.h index 139ce89dddf..a52b4baaf94 100644 --- a/engines/wintermute/utils/path_util.h +++ b/engines/wintermute/utils/path_util.h @@ -29,7 +29,7 @@ #ifndef WINTERMUTE_PATHUTILS_H #define WINTERMUTE_PATHUTILS_H -#include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/dctypes.h" namespace WinterMute { diff --git a/engines/wintermute/utils/string_util.cpp b/engines/wintermute/utils/string_util.cpp index c3fcb09f1d5..fcf5620cd75 100644 --- a/engines/wintermute/utils/string_util.cpp +++ b/engines/wintermute/utils/string_util.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "common/tokenizer.h" #include "engines/wintermute/utils/string_util.h" #include "engines/wintermute/utils/convert_utf.h" @@ -264,48 +263,6 @@ bool StringUtil::isUtf8BOM(const byte *Buffer, uint32 BufferSize) { else return false; } -////////////////////////////////////////////////////////////////////////// -AnsiString StringUtil::replace(const AnsiString &str, const AnsiString &from, const AnsiString &to) { - if (from.empty() || from == to) return str; - - AnsiString result = str; - /*size_t pos = 0;*/ - - while (result.contains(from)) { - const char *startPtr = strstr(result.c_str(), from.c_str()); - uint32 index = startPtr - result.c_str(); - - Common::String tail(result.c_str() + index + to.size()); - result = Common::String(result.c_str(), index); - result += to; - result += tail; - - /* pos = result.find(from, pos); - if (pos == result.npos) break; - - result.replace(pos, from.size(), to); - pos += to.size();*/ - } - - return result; -} - -////////////////////////////////////////////////////////////////////////// -AnsiString StringUtil::trim(const AnsiString &str, bool fromLeft, bool fromRight, const AnsiString &chars) { - AnsiString trimmedStr = str; - - if (fromRight) { - //trimmedStr.erase(trimmedStr.find_last_not_of(chars) + 1); // TODO - warning("fromRight-trim not implemented yet, %s", chars.c_str()); - } - if (fromLeft) { - uint32 lastOf = lastIndexOf(str, chars, 0); - trimmedStr = Common::String(trimmedStr.c_str() + lastOf); - //trimmedStr.erase(0, trimmedStr.find_first_not_of(chars)); - } - return trimmedStr; -} - ////////////////////////////////////////////////////////////////////////// int StringUtil::indexOf(const WideString &str, const WideString &toFind, size_t startFrom) { /*size_t pos = str.find(toFind, startFrom); @@ -318,64 +275,11 @@ int StringUtil::indexOf(const WideString &str, const WideString &toFind, size_t return index - str.c_str(); } -////////////////////////////////////////////////////////////////////////// -int StringUtil::lastIndexOf(const WideString &str, const WideString &toFind, size_t startFrom) { - /*size_t pos = str.rfind(toFind, startFrom); - if (pos == str.npos) return -1; - else return pos;*/ - int32 lastIndex = -1; - bool found = false; - for (size_t i = startFrom; i < str.size(); i++) { - found = false; - for (size_t j = 0; j < toFind.size(); j++) { - if (str[i + j] != toFind[j]) { - found = false; - break; - } else { - found = true; - } - } - if (found) - lastIndex = i; - } - return lastIndex; -} - -////////////////////////////////////////////////////////////////////////// -AnsiString StringUtil::toString(size_t val) { - return Common::String::format("%u", (uint32)val); -} ////////////////////////////////////////////////////////////////////////// AnsiString StringUtil::toString(int val) { return Common::String::format("%d", val); } -////////////////////////////////////////////////////////////////////////// -AnsiString StringUtil::toString(float val) { - return Common::String::format("%f", val); -} - -////////////////////////////////////////////////////////////////////////// -AnsiString StringUtil::toString(double val) { - return Common::String::format("%f", val); -} - - -////////////////////////////////////////////////////////////////////////// -void StringUtil::split(const AnsiString &list, const AnsiString &delimiters, AnsiStringArray &result, bool keepEmptyItems) { - result.clear(); -//TODO: Verify this, wrt keepEmptyItems. - Common::StringTokenizer tokenizer(list.c_str(), delimiters.c_str()); - //typedef boost::char_separator separator_t; - //typedef boost::tokenizer tokenizer_t; - - //separator_t del(delimiters.c_str(), "", keepEmptyItems ? boost::keep_empty_tokens : boost::drop_empty_tokens); - //tokenizer_t tokens(list, del); - while (!tokenizer.empty()) { - Common::String copy(tokenizer.nextToken().c_str()); - result.push_back(copy); - } -} } // end of namespace WinterMute diff --git a/engines/wintermute/utils/string_util.h b/engines/wintermute/utils/string_util.h index bd1b71f405b..80b4ab5911d 100644 --- a/engines/wintermute/utils/string_util.h +++ b/engines/wintermute/utils/string_util.h @@ -29,7 +29,7 @@ #ifndef WINTERMUTE_STRINGUTIL_H #define WINTERMUTE_STRINGUTIL_H -#include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/dctypes.h" namespace WinterMute { @@ -46,19 +46,9 @@ public: static bool endsWith(const AnsiString &str, const AnsiString &pattern, bool ignoreCase = false); static bool isUtf8BOM(const byte *buffer, uint32 bufferSize); - - static AnsiString replace(const AnsiString &str, const AnsiString &from, const AnsiString &to); - static AnsiString trim(const AnsiString &str, bool fromLeft = true, bool fromRight = true, const AnsiString &chars = " \n\r\t"); - static int indexOf(const WideString &str, const WideString &toFind, size_t startFrom); - static int lastIndexOf(const WideString &str, const WideString &toFind, size_t startFrom); - static AnsiString toString(size_t val); static AnsiString toString(int val); - static AnsiString toString(float val); - static AnsiString toString(double val); - - static void split(const AnsiString &list, const AnsiString &delimiters, AnsiStringArray &result, bool keepEmptyItems = false); }; } // end of namespace WinterMute diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 038095c8ae9..ee723cf80aa 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -26,14 +26,7 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/wintypes.h" -#include "engines/wintermute/utils/path_util.h" -#include "engines/wintermute/base/base_game.h" -#include "common/str.h" -#include "common/textconsole.h" #include "engines/wintermute/wintermute.h" namespace WinterMute { @@ -43,36 +36,6 @@ static inline unsigned Sqr(int x) { return (x * x); } - -////////////////////////////////////////////////////////////////////////////////// -void BaseUtils::clip(int *destX, int *destY, Rect32 *srcRect, Rect32 *destRect) { - // If it's partly off the right side of the screen - if (*destX + (srcRect->right - srcRect->left) > destRect->right) - srcRect->right -= *destX + (srcRect->right - srcRect->left) - destRect->right; - - if (srcRect->right < 0) srcRect->right = 0; - - // Partly off the left side of the screen - if (*destX < destRect->left) { - srcRect->left += destRect->left - *destX; - *destX = destRect->left; - } - - // Partly off the top of the screen - if (*destY < destRect->top) { - srcRect->top += destRect->top - *destY; - *destY = destRect->top; - } - - // If it's partly off the bottom side of the screen - if (*destY + (srcRect->bottom - srcRect->top) > destRect->bottom) - srcRect->bottom -= ((srcRect->bottom - srcRect->top) + *destY) - destRect->bottom; - - if (srcRect->bottom < 0) srcRect->bottom = 0; - - return; -} - ////////////////////////////////////////////////////////////////////////////////// // Swap - swaps two integers ////////////////////////////////////////////////////////////////////////////////// @@ -82,11 +45,6 @@ void BaseUtils::swap(int *a, int *b) { *b = Temp; } -////////////////////////////////////////////////////////////////////////// -bool BaseUtils::strBeginsI(const char *string, const char *fragment) { - return (scumm_strnicmp(string, fragment, strlen(fragment)) == 0); -} - ////////////////////////////////////////////////////////////////////////// float BaseUtils::normalizeAngle(float angle) { @@ -99,11 +57,11 @@ float BaseUtils::normalizeAngle(float angle) { //////////////////////////////////////////////////////////////////////////////// void BaseUtils::createPath(const char *path, bool pathOnly) { - AnsiString pathStr; +/* AnsiString pathStr; if (!pathOnly) pathStr = PathUtil::getDirectoryName(path); else pathStr = path; - +*/ // try { warning("BaseUtils::CreatePath - not implemented: %s", path); // boost::filesystem::create_directories(path); @@ -235,24 +193,6 @@ bool BaseUtils::matchesPattern(const char *pattern, const char *string) { } } -////////////////////////////////////////////////////////////////////////// -char *BaseUtils::getPath(const char *filename) { - AnsiString path = PathUtil::getDirectoryName(filename); - //path = boost::filesystem::syste_complete(path).string(); - warning("BaseUtils::GetPath: (%s), not implemented", filename); - char *ret = new char[path.size() + 1]; - strcpy(ret, path.c_str()); - - return ret; -} - -////////////////////////////////////////////////////////////////////////// -char *BaseUtils::getFilename(const char *filename) { - AnsiString path = PathUtil::getFileName(filename); - char *ret = new char[path.size() + 1]; - strcpy(ret, path.c_str()); - return ret; -} ////////////////////////////////////////////////////////////////////////// void BaseUtils::RGBtoHSL(uint32 RGBColor, byte *outH, byte *outS, byte *outL) { diff --git a/engines/wintermute/utils/utils.h b/engines/wintermute/utils/utils.h index 3baafaa6061..3cb01c57b88 100644 --- a/engines/wintermute/utils/utils.h +++ b/engines/wintermute/utils/utils.h @@ -38,9 +38,7 @@ class BaseGame; class BaseUtils { public: - static void clip(int *destX, int *destY, Rect32 *srcRect, Rect32 *destRect); static void swap(int *a, int *b); - static bool strBeginsI(const char *string, const char *fragment); static float normalizeAngle(float angle); static void createPath(const char *path, bool pathOnly = false); @@ -57,9 +55,6 @@ public: static bool matchesPattern(const char *pattern, const char *string); - static char *getPath(const char *filename); - static char *getFilename(const char *filename); - static void RGBtoHSL(uint32 RGBColor, byte *OutH, byte *OutS, byte *OutL); static uint32 HSLtoRGB(byte H, byte S, byte L);