aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/support/string.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-03 16:16:35 -0400
committerPaul Gilbert2016-04-03 16:16:35 -0400
commit1efbed540948edcbf3ac2c72c0984def044274cf (patch)
tree63b4543753951b55c756a9b81cd5df5ab2718943 /engines/titanic/support/string.cpp
parent432153274385295a9a4eb01e56bfcc72cc5f202e (diff)
downloadscummvm-rg350-1efbed540948edcbf3ac2c72c0984def044274cf.tar.gz
scummvm-rg350-1efbed540948edcbf3ac2c72c0984def044274cf.tar.bz2
scummvm-rg350-1efbed540948edcbf3ac2c72c0984def044274cf.zip
TITANIC: Move most of the root classes into new support/ folder
Diffstat (limited to 'engines/titanic/support/string.cpp')
-rw-r--r--engines/titanic/support/string.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/engines/titanic/support/string.cpp b/engines/titanic/support/string.cpp
new file mode 100644
index 0000000000..86dc0be0b0
--- /dev/null
+++ b/engines/titanic/support/string.cpp
@@ -0,0 +1,122 @@
+/* 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.
+ *
+ */
+
+#include "common/algorithm.h"
+#include "titanic/support/string.h"
+
+namespace Titanic {
+
+CString::CString(char c, uint32 len) : Common::String() {
+ ensureCapacity(len, false);
+ for (uint idx = 0; idx < len; ++idx)
+ (*this) += c;
+}
+
+CString::CString(int val) : Common::String() {
+ char buffer[16];
+ itoa(val, buffer, 10);
+ *this += buffer;
+}
+
+CString CString::left(uint count) const {
+ return (count > size()) ? CString() : CString(c_str(), c_str() + count);
+}
+
+CString CString::right(uint count) const {
+ uint strSize = size();
+ return (count > strSize) ? CString() :
+ CString(c_str() + strSize - count, c_str() + strSize);
+}
+
+CString CString::mid(uint start, uint count) const {
+ if (start >= size())
+ return CString();
+ else
+ return CString(c_str() + start, MIN(count, size() - start));
+}
+
+CString CString::mid(uint start) const {
+ uint strSize = size();
+ assert(start <= strSize);
+ return mid(start, strSize - start);
+}
+
+int CString::indexOf(char c) const {
+ const char *charP = strchr(c_str(), c);
+ return charP ? charP - c_str() : -1;
+}
+
+int CString::lastIndexOf(char c) const {
+ const char *charP = strrchr(c_str(), c);
+ return charP ? charP - c_str() : -1;
+}
+
+FileType CString::fileTypeSuffix() const {
+ CString ext = right(1);
+ if (ext == "0" || ext == "4")
+ return FILETYPE_IMAGE;
+ else if (ext == "1")
+ return FILETYPE_WAV;
+ else if (ext == "2" || ext == "3")
+ return FILETYPE_MOVIE;
+
+ ext = right(3);
+ if (ext == "tga" || ext == "jpg")
+ return FILETYPE_IMAGE;
+ else if (ext == "wav")
+ return FILETYPE_WAV;
+ else if (ext == "avi" || ext == "mov")
+ return FILETYPE_MOVIE;
+ else if (ext == "dlg")
+ return FILETYPE_DLG;
+ else
+ return FILETYPE_UNKNOWN;
+}
+
+ImageType CString::imageTypeSuffix() const {
+ CString ext = right(1);
+ if (ext == "0")
+ return IMAGETYPE_TARGA;
+ else if (ext == "4")
+ return IMAGETYPE_JPEG;
+
+ ext = right(3);
+ if (ext == "tga")
+ return IMAGETYPE_TARGA;
+ else if (ext == "jpg")
+ return IMAGETYPE_JPEG;
+ else
+ return IMAGETYPE_UNKNOWN;
+}
+
+CString CString::format(const char *fmt, ...) {
+ String output;
+
+ va_list va;
+ va_start(va, fmt);
+ output = String::vformat(fmt, va);
+ va_end(va);
+
+ return output;
+}
+
+} // End of namespace Titanic