1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef TITANIC_STRING_H 24 #define TITANIC_STRING_H 25 26 #include "common/scummsys.h" 27 #include "common/array.h" 28 #include "common/str.h" 29 30 namespace Titanic { 31 32 enum FileType { 33 FILETYPE_UNKNOWN = 0, FILETYPE_IMAGE = 1, FILETYPE_MOVIE = 2, 34 FILETYPE_WAV = 3, FILETYPE_DLG = 4 35 }; 36 37 enum ImageType { 38 IMAGETYPE_UNKNOWN = 0, IMAGETYPE_TARGA = 1, IMAGETYPE_JPEG = 2 39 }; 40 41 class CString : public Common::String { 42 public: CString()43 CString() : Common::String() {} CString(const char * str)44 CString(const char *str) : Common::String(str) {} CString(const char * str,uint32 len)45 CString(const char *str, uint32 len) : Common::String(str, len) {} CString(const char * beginP,const char * endP)46 CString(const char *beginP, const char *endP) : Common::String(beginP, endP) {} CString(const String & str)47 CString(const String &str) : Common::String(str) {} 48 CString(char c, uint32 len); CString(char c)49 explicit CString(char c) : Common::String(c) {} 50 explicit CString(int val); 51 52 bool operator==(const CString &x) const; 53 bool operator==(const char *x) const; 54 bool operator!=(const CString &x) const; 55 bool operator!=(const char *x) const; 56 57 /** 58 * Returns the left n characters of the string 59 */ 60 CString left(uint count) const; 61 62 /** 63 * Returns the right n characters of the string 64 */ 65 CString right(uint count) const; 66 67 /** 68 * Returns a substring from within the string 69 */ 70 CString mid(uint start, uint count) const; 71 72 /** 73 * Returns a substring from within the string 74 */ 75 CString mid(uint start) const; 76 77 /** 78 * Returns a substring consisting of the entire string 79 * except for a specified number of characters at the end 80 */ 81 CString deleteRight(uint count) const; 82 83 /** 84 * Returns the index of the first occurance of a given character 85 */ 86 int indexOf(char c) const; 87 88 /** 89 * Returns the index of the first occurance of a given string 90 */ 91 int indexOf(const char *s) const; 92 93 /** 94 * Returns the index of the last occurance of a given character 95 */ 96 int lastIndexOf(char c) const; 97 98 /** 99 * Returns true if the string contains a specified substring, ignoring case 100 */ 101 bool containsIgnoreCase(const CString &str) const; 102 103 /** 104 * Returns the type of a filename based on it's extension 105 */ 106 FileType fileTypeSuffix() const; 107 108 /** 109 * Returns the type of an image filename based on it's extension 110 */ 111 ImageType imageTypeSuffix() const; 112 113 /** 114 * Parses the string as an integer and returns the value 115 */ readInt()116 int readInt() const { 117 return atoi(c_str()); 118 } 119 120 /** 121 * Format a string 122 */ 123 static CString format(const char *fmt, ...); 124 }; 125 126 typedef Common::Array<CString> StringArray; 127 128 } // End of namespace Titanic 129 130 #endif /* TITANIC_STRING_H */ 131