StringBase.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ROCKETCORESTRINGBASE_H
00029 #define ROCKETCORESTRINGBASE_H
00030
00031 #include <Rocket/Core/Debug.h>
00032 #include <Rocket/Core/StringStorage.h>
00033
00034
00035 namespace Rocket {
00036 namespace Core {
00037
00042 template< typename T >
00043 class StringBase
00044 {
00045 public:
00046 typedef size_t size_type;
00047 static const size_type npos = (size_type)-1;
00048
00049 StringBase();
00050 StringBase(const StringBase& copy);
00051 StringBase(const T* string);
00052 StringBase(const T* string_start, const T* string_end);
00053 StringBase(size_type length, const T character);
00054 StringBase(size_type max_length, const T* fmt, ...);
00055
00056 ~StringBase();
00057
00059 inline bool Empty() const;
00061 void Clear();
00062
00064 inline size_type Length() const;
00066 inline const T* CString() const;
00067
00071 size_type Find(const T* find, size_type offset = 0) const;
00075 size_type Find(const StringBase<T>& find, size_type offset = 0) const;
00079 size_type RFind(const T* find, size_type offset = npos) const;
00083 size_type RFind(const StringBase<T>& find, size_type offset = npos) const;
00084
00088 StringBase<T> Replace(const T* find, const T* replace) const;
00092 StringBase<T> Replace(const StringBase<T>& find, const StringBase<T>& replace) const;
00093
00097 inline StringBase<T> Substring(size_type start, size_type length = StringBase<T>::npos) const;
00098
00102 inline StringBase<T>& Append(const T* append, size_type count = StringBase<T>::npos);
00106 inline StringBase<T>& Append(const StringBase<T>& append, size_type count = StringBase<T>::npos);
00109 inline StringBase<T>& Append(const T& append);
00110
00114 inline StringBase<T>& Assign(const T* assign, size_type count = StringBase<T>::npos);
00118 inline StringBase<T>& Assign(const T* assign, const T* end);
00122 inline StringBase<T>& Assign(const StringBase<T>& assign, size_type count = StringBase<T>::npos);
00123
00128 inline void Insert(size_type index, const T* insert, size_type count = StringBase<T>::npos);
00133 inline void Insert(size_type index, const StringBase<T>& insert, size_type count = StringBase<T>::npos);
00137 inline void Insert(size_type index, const T& insert);
00138
00142 inline void Erase(size_type index, size_type length = StringBase<T>::npos);
00143
00149 int FormatString(size_type max_length, const T* format, ...);
00150
00153 void Resize(size_type size);
00154
00157 StringBase<T> ToLower() const;
00160 StringBase<T> ToUpper() const;
00161
00162 inline bool operator==(const T* compare) const;
00163 inline bool operator==(const StringBase<T>& compare) const;
00164
00165 inline bool operator!=(const T* compare) const;
00166 inline bool operator!=(const StringBase<T>& compare) const;
00167
00168 inline bool operator<(const T* compare) const;
00169 inline bool operator<(const StringBase<T>& compare) const;
00170
00171 inline StringBase<T>& operator=(const T* assign);
00172 inline StringBase<T>& operator=(const StringBase<T>& assign);
00173
00174 inline StringBase<T> operator+(const T* append) const;
00175 inline StringBase<T> operator+(const StringBase<T>& append) const;
00176
00177 inline StringBase<T>& operator+=(const T* append);
00178 inline StringBase<T>& operator+=(const StringBase<T>& append);
00179 inline StringBase<T>& operator+=(const T& append);
00180
00181 inline const T& operator[](size_type index) const;
00182 inline T& operator[](size_type index);
00183
00184 protected:
00185
00186 mutable T* value;
00187 size_type length;
00188
00189 mutable StringStorage::StringID string_id;
00190
00191 size_type GetLength(const T* string) const;
00192
00193
00194 inline void AddStorage() const;
00195
00196
00197 inline void Modify(size_type new_size, bool shrink = false);
00198
00199 inline void Copy(T* target, const T* src, size_type length, bool terminate = false) const;
00200
00201 inline void Release() const;
00202
00203
00204
00205
00206
00207 inline size_type _Find(const T* find, size_type find_length, size_type offset = 0) const;
00208 inline size_type _RFind(const T* find, size_type find_length, size_type offset = 0) const;
00209 inline StringBase<T> _Replace(const T* find, size_type find_length, const T* replace, size_type replace_length) const;
00210 inline StringBase<T>& _Append(const T* append, size_type append_length, size_type count = StringBase<T>::npos);
00211 inline StringBase<T>& _Assign(const T* assign, size_type assign_length, size_type count = StringBase<T>::npos);
00212 inline void _Insert(size_type index, const T* insert, size_type insert_length, size_type count = StringBase<T>::npos);
00213 };
00214
00215 #include <Rocket/Core/StringBase.inl>
00216
00217 }
00218 }
00219
00220 #endif