ScummVM API documentation
tt_string.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef TITANIC_TT_STRING_H
23 #define TITANIC_TT_STRING_H
24 
25 #include "titanic/support/string.h"
26 
27 namespace Titanic {
28 
29 class SimpleFile;
30 
31 struct TTstringData {
32  CString _string;
33  int _referenceCount;
34 
35  TTstringData() : _referenceCount(1) {}
36  TTstringData(const char *str) : _string(str), _referenceCount(1) {}
37  TTstringData(const CString &str) : _string(str), _referenceCount(1) {}
38 };
39 
40 enum TTstringStatus {
41  SS_VALID = 0, SS_1 = 1, SS_2 = 2, SS_3 = 3, SS_4 = 4,
42  SS_5 = 5, SS_7 = 7, SS_8 = 8, SS_11 = 11, SS_13 = 13
43 };
44 
45 class TTstring {
46 private:
47  TTstringData *_data;
48  TTstringStatus _status;
49 public:
50  TTstring();
51  TTstring(const char *str);
52  TTstring(const CString &str);
53  TTstring(const TTstring &str);
54  virtual ~TTstring();
55 
56  void operator=(const TTstring &str);
57  void operator=(const CString &str);
58  void operator=(const char *str);
59  TTstring &operator+=(const char *str);
60  TTstring &operator+=(const TTstring &str);
61  TTstring &operator+=(char c);
62  bool operator==(const TTstring &str) const;
63  bool operator==(const char *str) const;
64 
65  const char &operator[](int index) {
66  return *(c_str() + index);
67  }
68 
69  bool empty() const {
70  return _data->_string.empty();
71  }
72 
73  char firstChar() const {
74  return _data->_string.firstChar();
75  }
76 
77  char lastChar() const {
78  return _data->_string.lastChar();
79  }
80 
81  int size() const {
82  return _data->_string.size();
83  }
84 
85  void deleteLastChar() {
86  _data->_string.deleteLastChar();
87  }
88 
89  bool hasPrefix(const CString &str) const {
90  return _data->_string.hasPrefix(str);
91  }
92  bool hasPrefix(const char *str) const {
93  return _data->_string.hasPrefix(str);
94  }
95  bool hasSuffix(const CString &str) const {
96  return _data->_string.hasSuffix(str);
97  }
98  bool hasSuffix(const char *str) const {
99  return _data->_string.hasSuffix(str);
100  }
101 
102  bool contains(const char *s) const {
103  return _data->_string.contains(s);
104  }
105 
109  TTstring *copy() const {
110  return new TTstring(c_str());
111  }
112 
116  bool isValid() const {
117  return _status == SS_VALID;
118  }
119 
123  TTstringStatus getStatus() const { return _status; }
124 
128  const char *c_str() const { return _data->_string.c_str(); }
129 
133  operator const char *() const { return c_str(); }
134 
138  char charAt(int index) const { return *(c_str() + index); }
139 
143  void save(SimpleFile *file) const;
144 
148  bool compareAt(int index, const char *str) const {
149  return !strncmp(c_str() + index, str, strlen(str));
150  }
151 
156  TTstring tokenize(const char *delim);
157 
161  int deletePrefix(int count);
162 
166  int deleteSuffix(int count);
167 
168 };
169 
170 } // End of namespace Titanic
171 
172 #endif /* TITANIC_TT_STRING_H */
bool compareAt(int index, const char *str) const
Definition: tt_string.h:148
const char * c_str() const
Definition: tt_string.h:128
TTstring * copy() const
Definition: tt_string.h:109
Definition: simple_file.h:49
void deleteLastChar()
Definition: str-base.h:137
Definition: arm.h:30
Definition: string.h:40
Definition: tt_string.h:45
char charAt(int index) const
Definition: tt_string.h:138
Definition: tt_string.h:31
bool isValid() const
Definition: tt_string.h:116
TTstringStatus getStatus() const
Definition: tt_string.h:123