2019-12-01 10:19:47 -08:00
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-12-16 22:00:28 -08:00
|
|
|
#ifndef ULTIMA_STD_STRING_H
|
|
|
|
#define ULTIMA_STD_STRING_H
|
2019-12-01 10:19:47 -08:00
|
|
|
|
|
|
|
#include "common/str.h"
|
|
|
|
|
2019-12-16 21:32:17 -08:00
|
|
|
namespace Ultima {
|
2019-12-01 10:19:47 -08:00
|
|
|
namespace std {
|
|
|
|
|
|
|
|
class string : public Common::String {
|
|
|
|
public:
|
|
|
|
typedef size_t size_type;
|
|
|
|
static const size_type npos = (size_type) - 1;
|
2019-12-05 20:54:58 -08:00
|
|
|
|
|
|
|
struct reverse_iterator {
|
|
|
|
private:
|
|
|
|
string *_owner;
|
|
|
|
int _index;
|
|
|
|
public:
|
|
|
|
reverse_iterator(string *owner, int index) : _owner(owner), _index(index) {}
|
2019-12-10 22:33:08 -08:00
|
|
|
reverse_iterator() : _owner(0), _index(-1) {}
|
2019-12-05 20:54:58 -08:00
|
|
|
|
|
|
|
char &operator*() const { return (*_owner)[_index]; }
|
|
|
|
|
|
|
|
reverse_iterator &operator++() {
|
|
|
|
--_index;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const reverse_iterator &rhs) {
|
|
|
|
return _owner == rhs._owner && _index == rhs._index;
|
|
|
|
}
|
|
|
|
bool operator!=(const reverse_iterator &rhs) {
|
|
|
|
return !operator==(rhs);
|
|
|
|
}
|
|
|
|
};
|
2019-12-01 10:19:47 -08:00
|
|
|
public:
|
|
|
|
string() : Common::String() {}
|
|
|
|
string(const char *str) : Common::String(str) {}
|
|
|
|
string(const char *str, uint32 len) : Common::String(str, len) {}
|
|
|
|
string(const char *beginP, const char *endP) : Common::String(beginP, endP) {}
|
|
|
|
string(const String &str) : Common::String(str) {}
|
|
|
|
explicit string(char c) : Common::String(c) {}
|
|
|
|
string(size_t n, char c);
|
2019-12-03 19:41:53 -08:00
|
|
|
virtual ~string() {}
|
2019-12-01 10:19:47 -08:00
|
|
|
|
2019-12-01 19:21:18 -08:00
|
|
|
size_t length() const { return size(); }
|
|
|
|
|
2019-12-01 17:07:58 -08:00
|
|
|
/**
|
|
|
|
* String square brackets allows modifying characters
|
|
|
|
*/
|
|
|
|
char &operator[](size_t idx) {
|
|
|
|
assert(idx < _size);
|
|
|
|
return _str[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Square brackets for const strings simply returns characters
|
|
|
|
*/
|
|
|
|
char operator[](size_t idx) const {
|
|
|
|
return Common::String::operator[](idx);
|
|
|
|
}
|
|
|
|
|
2019-12-04 08:00:53 -08:00
|
|
|
/**
|
|
|
|
* Get a character at an index
|
|
|
|
*/
|
|
|
|
char at(size_t idx) { return operator[](idx); }
|
|
|
|
|
2019-12-01 19:21:18 -08:00
|
|
|
virtual int Compare(const string &s) const {
|
|
|
|
return compareTo(s);
|
|
|
|
}
|
|
|
|
|
2019-12-01 10:19:47 -08:00
|
|
|
/**
|
|
|
|
* Finds the index of a character in the string
|
|
|
|
*/
|
|
|
|
size_t find(char c, size_t pos = 0) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does a find for the passed string
|
|
|
|
*/
|
|
|
|
size_t find(const char *s) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does a reverse find for the passed string
|
|
|
|
*/
|
|
|
|
size_t rfind(const char *s) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does a reverse find for a passed character
|
|
|
|
*/
|
|
|
|
size_t rfind(char c, size_t pos = npos) const;
|
|
|
|
|
2019-12-04 08:00:53 -08:00
|
|
|
/**
|
|
|
|
* Find first character in the string matching the passed character
|
|
|
|
*/
|
|
|
|
size_t find_first_of(char c, size_t pos = 0) const;
|
|
|
|
|
2019-12-01 19:21:18 -08:00
|
|
|
/**
|
|
|
|
* Find first character in the string that's any character of the passed string
|
|
|
|
*/
|
2019-12-04 08:00:53 -08:00
|
|
|
size_t find_first_of(const char *chars, size_t pos = 0) const;
|
2019-12-01 19:21:18 -08:00
|
|
|
|
2019-12-01 10:19:47 -08:00
|
|
|
/**
|
|
|
|
* Find first character in the string that's not the specified character
|
|
|
|
*/
|
2019-12-04 08:00:53 -08:00
|
|
|
size_t find_first_not_of(char c, size_t pos = 0) const;
|
2019-12-01 10:19:47 -08:00
|
|
|
|
2019-12-01 19:21:18 -08:00
|
|
|
/**
|
|
|
|
* Find first character in the string that's not any character of the passed string
|
|
|
|
*/
|
2019-12-04 08:00:53 -08:00
|
|
|
size_t find_first_not_of(const char *chars, size_t pos = 0) const;
|
2019-12-01 19:21:18 -08:00
|
|
|
|
2019-12-01 10:19:47 -08:00
|
|
|
/**
|
|
|
|
* Find the last character in the string that's not the specified character
|
|
|
|
*/
|
|
|
|
size_t find_last_not_of(char c) const;
|
|
|
|
|
2019-12-01 19:21:18 -08:00
|
|
|
/**
|
|
|
|
* Find the last character in the string that's not in any of the passed characters
|
|
|
|
*/
|
|
|
|
size_t find_last_not_of(const char *chars) const;
|
|
|
|
|
2019-12-01 10:19:47 -08:00
|
|
|
/**
|
|
|
|
* Return a substring of this string
|
|
|
|
*/
|
|
|
|
string substr(size_t pos = 0, size_t len = npos) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Erases len number of characters from pos
|
|
|
|
*/
|
|
|
|
string &erase(size_t pos = 0, size_t len = npos);
|
2019-12-01 17:07:58 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resizes a string
|
|
|
|
*/
|
|
|
|
void resize(size_t count);
|
2019-12-02 20:54:26 -08:00
|
|
|
|
|
|
|
void insert(size_t pos, size_t n, char c) {
|
|
|
|
for (uint idx = 0; idx < n; ++idx)
|
|
|
|
insertChar(c, pos);
|
|
|
|
}
|
2019-12-03 21:23:20 -08:00
|
|
|
|
|
|
|
void append(const string &str) {
|
|
|
|
*this += str;
|
|
|
|
}
|
2019-12-05 20:54:58 -08:00
|
|
|
|
|
|
|
reverse_iterator rbegin() {
|
|
|
|
return reverse_iterator(this, (int)size() - 1);
|
|
|
|
}
|
|
|
|
reverse_iterator rend() {
|
|
|
|
return reverse_iterator(this, -1);
|
|
|
|
}
|
2019-12-08 21:33:06 -08:00
|
|
|
|
|
|
|
bool operator==(const string &x) const {
|
|
|
|
return !Compare(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const char *x) const {
|
|
|
|
return !Compare(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const string &x) const {
|
|
|
|
return Compare(x) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator !=(const char *x) const {
|
|
|
|
return Compare(x) != 0;
|
|
|
|
}
|
2019-12-01 10:19:47 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern const char *const endl;
|
|
|
|
|
|
|
|
} // End of namespace std
|
2019-12-16 21:32:17 -08:00
|
|
|
} // End of namespace Ultima
|
2019-12-01 10:19:47 -08:00
|
|
|
|
|
|
|
#endif
|