ScummVM API documentation
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 ULTIMA_STD_STRING_H
23 #define ULTIMA_STD_STRING_H
24 
25 #include "common/str.h"
26 
27 namespace Ultima {
28 namespace Std {
29 
30 class string : public Common::String {
31 public:
32  typedef size_t size_type;
33 
35  private:
36  string *_owner;
37  int _index;
38  public:
39  reverse_iterator(string *owner, int index) : _owner(owner), _index(index) {}
40  reverse_iterator() : _owner(0), _index(-1) {}
41 
42  char &operator*() const { return (*_owner)[_index]; }
43 
44  reverse_iterator &operator++() {
45  --_index;
46  return *this;
47  }
48  reverse_iterator operator++(int) {
49  reverse_iterator tmp(_owner, _index);
50  ++(*this);
51  return tmp;
52  }
53 
54  bool operator==(const reverse_iterator &rhs) {
55  return _owner == rhs._owner && _index == rhs._index;
56  }
57  bool operator!=(const reverse_iterator &rhs) {
58  return !operator==(rhs);
59  }
60  };
61 public:
62  string() : Common::String() {}
63  string(const char *str) : Common::String(str) {}
64  string(const char *str, uint32 len) : Common::String(str, len) {}
65  string(const char *beginP, const char *endP) : Common::String(beginP, endP) {}
66  string(const String &str) : Common::String(str) {}
67  string(char c) : Common::String(c) {}
68  string(size_t n, char c);
69  virtual ~string() {}
70 
71  size_t length() const { return size(); }
72 
76  void assign(const char *s, size_t count = npos) {
77  if (count == npos)
78  *this = s;
79  else
80  *this = string(s, count);
81  }
82  void assign(const string &s, size_t count = npos) {
83  if (count == npos)
84  *this = s;
85  else
86  *this = string(s.c_str(), count);
87  }
88 
92  char &operator[](size_t idx) {
93  assert(idx < _size);
94  return _str[idx];
95  }
96 
100  char operator[](size_t idx) const {
101  return Common::String::operator[](idx);
102  }
103 
107  char at(size_t idx) { return operator[](idx); }
108 
109  virtual int Compare(const string &s) const {
110  return compareTo(s);
111  }
112 
116  void resize(size_t count);
117 
118  void insert(size_t pos, size_t n, char c) {
119  for (uint idx = 0; idx < n; ++idx)
120  insertChar(c, pos);
121  }
122 
126  void append(size_t n, char c) {
127  string str(n, c);
128  *this += str;
129  }
130 
134  void append(const string &str, size_t theSize = npos) {
135  if (theSize == npos)
136  *this += str;
137  else
138  *this += Common::String(str.c_str(), theSize);
139  }
140 
144  void push_back(char c) {
145  *this += c;
146  }
147 
148  reverse_iterator rbegin() {
149  return reverse_iterator(this, (int)size() - 1);
150  }
151  reverse_iterator rend() {
152  return reverse_iterator(this, -1);
153  }
154 
155  bool operator==(const string &x) const {
156  return !Compare(x);
157  }
158 
159  bool operator==(const char *x) const {
160  return !Compare(x);
161  }
162 
163  bool operator!=(const string &x) const {
164  return Compare(x) != 0;
165  }
166 
167  bool operator !=(const char *x) const {
168  return Compare(x) != 0;
169  }
170 };
171 
172 extern const char *const endl;
173 
174 extern Common::String to_uppercase(const Common::String &s);
175 
176 } // End of namespace Std
177 } // End of namespace Ultima
178 
179 #endif
Definition: str.h:59
void resize(size_t count)
void insertChar(value_type c, uint32 p)
void push_back(char c)
Definition: string.h:144
char operator[](size_t idx) const
Definition: string.h:100
Definition: str.h:38
Definition: detection.h:27
char & operator[](size_t idx)
Definition: string.h:92
void append(size_t n, char c)
Definition: string.h:126
uint32 _size
Definition: str-base.h:54
Definition: string.h:30
char at(size_t idx)
Definition: string.h:107
value_type * _str
Definition: str-base.h:60
Definition: algorithm.h:37
void append(const string &str, size_t theSize=npos)
Definition: string.h:134
void assign(const char *s, size_t count=npos)
Definition: string.h:76