summaryrefslogtreecommitdiff
path: root/core/ustring.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/ustring.h')
-rw-r--r--core/ustring.h51
1 files changed, 44 insertions, 7 deletions
diff --git a/core/ustring.h b/core/ustring.h
index 001d111d64..3b4405833c 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -32,6 +32,7 @@
#define RSTRING_H
#include "array.h"
+#include "cowdata.h"
#include "typedefs.h"
#include "vector.h"
@@ -39,9 +40,27 @@
@author red <red@killy>
*/
-class CharString : public Vector<char> {
+class CharString {
+
+ CowData<char> _cowdata;
+
public:
+ _FORCE_INLINE_ char *ptrw() { return _cowdata.ptrw(); }
+ _FORCE_INLINE_ const char *ptr() const { return _cowdata.ptr(); }
+ _FORCE_INLINE_ int size() const { return _cowdata.size(); }
+ Error resize(int p_size) { return _cowdata.resize(p_size); }
+
+ _FORCE_INLINE_ char get(int p_index) { return _cowdata.get(p_index); }
+ _FORCE_INLINE_ const char get(int p_index) const { return _cowdata.get(p_index); }
+ _FORCE_INLINE_ void set(int p_index, const char &p_elem) { _cowdata.set(p_index, p_elem); }
+ _FORCE_INLINE_ char &operator[](int p_index) { return _cowdata.get_m(p_index); }
+ _FORCE_INLINE_ const char &operator[](int p_index) const { return _cowdata.get(p_index); }
+
+ _FORCE_INLINE_ CharString() {}
+ _FORCE_INLINE_ CharString(const CharString &p_str) { _cowdata._ref(p_str._cowdata); }
+
bool operator<(const CharString &p_right) const;
+ CharString &operator+=(char p_char);
int length() const { return size() ? size() - 1 : 0; }
const char *get_data() const;
operator const char *() { return get_data(); };
@@ -60,7 +79,9 @@ struct StrRange {
}
};
-class String : public Vector<CharType> {
+class String {
+
+ CowData<CharType> _cowdata;
void copy_from(const char *p_cstr);
void copy_from(const CharType *p_cstr, int p_clip_to = -1);
@@ -74,6 +95,21 @@ public:
npos = -1 ///<for "some" compatibility with std::string (npos is a huge value in std::string)
};
+ _FORCE_INLINE_ CharType *ptrw() { return _cowdata.ptrw(); }
+ _FORCE_INLINE_ const CharType *ptr() const { return _cowdata.ptr(); }
+
+ void remove(int p_index) { _cowdata.remove(p_index); }
+
+ _FORCE_INLINE_ void clear() { resize(0); }
+
+ _FORCE_INLINE_ CharType get(int p_index) { return _cowdata.get(p_index); }
+ _FORCE_INLINE_ const CharType get(int p_index) const { return _cowdata.get(p_index); }
+ _FORCE_INLINE_ void set(int p_index, const CharType &p_elem) { _cowdata.set(p_index, p_elem); }
+ _FORCE_INLINE_ int size() const { return _cowdata.size(); }
+ Error resize(int p_size) { return _cowdata.resize(p_size); }
+ _FORCE_INLINE_ CharType &operator[](int p_index) { return _cowdata.get_m(p_index); }
+ _FORCE_INLINE_ const CharType &operator[](int p_index) const { return _cowdata.get(p_index); }
+
bool operator==(const String &p_str) const;
bool operator!=(const String &p_str) const;
String operator+(const String &p_str) const;
@@ -192,8 +228,8 @@ public:
String dedent() const;
String strip_edges(bool left = true, bool right = true) const;
String strip_escapes() const;
- String lstrip(const Vector<CharType> &p_chars) const;
- String rstrip(const Vector<CharType> &p_chars) const;
+ String lstrip(const String &p_chars) const;
+ String rstrip(const String &p_chars) const;
String get_extension() const;
String get_basename() const;
String plus_file(const String &p_file) const;
@@ -254,9 +290,10 @@ public:
* The constructors must not depend on other overloads
*/
/* String(CharType p_char);*/
- inline String() {}
- inline String(const String &p_str) :
- Vector(p_str) {}
+
+ _FORCE_INLINE_ String() {}
+ _FORCE_INLINE_ String(const String &p_str) { _cowdata._ref(p_str._cowdata); }
+
String(const char *p_str);
String(const CharType *p_str, int p_clip_to_len = -1);
String(const StrRange &p_range);