zenilib: zenilib/jni/external/zenilib/zeni/Zeni/String.h Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
String.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2 * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3 *
4 * zenilib is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * zenilib is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef ZENI_STRING_H
19 #define ZENI_STRING_H
20
21 #include <string>
22 #include <cctype>
23 #include <cstddef>
24 #include <cstring>
25 #include <iosfwd>
26
27 namespace Zeni {
28
29 class ZENI_DLL String {
30 public:
31 typedef ptrdiff_t difference_type;
32 typedef size_t size_type;
33 typedef char value_type;
34 typedef value_type * pointer;
35 typedef value_type & reference;
36
37 static const size_type npos = size_type(-1);
38
39 class ZENI_DLL iterator {
40 friend class String;
41
42 public:
43 typedef ptrdiff_t difference_type;
44 typedef std::random_access_iterator_tag iterator_category;
45 typedef char value_type;
46 typedef value_type * pointer;
47 typedef value_type & reference;
48
49 iterator();
50 ~iterator();
51
52 iterator(const iterator &rhs);
53 iterator & operator=(const iterator &rhs);
54
55 bool operator==(const iterator &rhs) const;
56 bool operator!=(const iterator &rhs) const;
57
58 value_type operator*() const;
59 value_type & operator*();
60 value_type operator->() const;
61 value_type & operator->();
62
63 iterator operator++();
64 iterator operator--();
65 iterator operator++(int);
66 iterator operator--(int);
67
68 iterator operator+(const difference_type &n) const;
69 iterator operator-(const difference_type &n) const;
70 difference_type operator-(const iterator &rhs) const;
71
72 bool operator<(const iterator &rhs) const;
73 bool operator>(const iterator &rhs) const;
74 bool operator<=(const iterator &rhs) const;
75 bool operator>=(const iterator &rhs) const;
76
77 iterator operator+=(const difference_type &n);
78 iterator operator-=(const difference_type &n);
79
80 value_type operator[](const difference_type &n) const;
81 value_type & operator[](const difference_type &n);
82
83 private:
84 iterator(const std::string::iterator &iter);
85 iterator & operator=(const std::string::iterator &iter);
86
87 void * m_impl;
88 };
89 class ZENI_DLL const_iterator {
90 friend class String;
91
92 public:
93 typedef ptrdiff_t difference_type;
94 typedef std::random_access_iterator_tag iterator_category;
95 typedef char value_type;
96 typedef value_type * pointer;
97 typedef value_type & reference;
98
99 const_iterator();
100 ~const_iterator();
101
102 const_iterator(const const_iterator &rhs);
103 const_iterator & operator=(const const_iterator &rhs);
104
105 const_iterator(const String::iterator &rhs);
106 const_iterator & operator=(const String::iterator &rhs);
107
108 bool operator==(const const_iterator &rhs) const;
109 bool operator!=(const const_iterator &rhs) const;
110
111 value_type operator*() const;
112 value_type operator->() const;
113
114 const_iterator operator++();
115 const_iterator operator--();
116 const_iterator operator++(int);
117 const_iterator operator--(int);
118
119 const_iterator operator+(const difference_type &n) const;
120 const_iterator operator-(const difference_type &n) const;
121 difference_type operator-(const const_iterator &rhs) const;
122
123 bool operator<(const const_iterator &rhs) const;
124 bool operator>(const const_iterator &rhs) const;
125 bool operator<=(const const_iterator &rhs) const;
126 bool operator>=(const const_iterator &rhs) const;
127
128 const_iterator operator+=(const difference_type &n);
129 const_iterator operator-=(const difference_type &n);
130
131 value_type operator[](const difference_type &n) const;
132
133 private:
134 const_iterator(const std::string::const_iterator &iter);
135 const_iterator & operator=(const std::string::const_iterator &iter);
136
137 void * m_impl;
138 };
139 class ZENI_DLL reverse_iterator {
140 friend class String;
141
142 public:
143 typedef ptrdiff_t difference_type;
144 typedef std::random_access_iterator_tag iterator_category;
145 typedef char value_type;
146 typedef value_type * pointer;
147 typedef value_type & reference;
148
149 reverse_iterator();
150 ~reverse_iterator();
151
152 reverse_iterator(const reverse_iterator &rhs);
153 reverse_iterator & operator=(const reverse_iterator &rhs);
154
155 bool operator==(const reverse_iterator &rhs) const;
156 bool operator!=(const reverse_iterator &rhs) const;
157
158 value_type operator*() const;
159 value_type & operator*();
160 value_type operator->() const;
161 value_type & operator->();
162
163 reverse_iterator operator++();
164 reverse_iterator operator--();
165 reverse_iterator operator++(int);
166 reverse_iterator operator--(int);
167
168 reverse_iterator operator+(const difference_type &n) const;
169 reverse_iterator operator-(const difference_type &n) const;
170 difference_type operator-(const reverse_iterator &rhs) const;
171
172 bool operator<(const reverse_iterator &rhs) const;
173 bool operator>(const reverse_iterator &rhs) const;
174 bool operator<=(const reverse_iterator &rhs) const;
175 bool operator>=(const reverse_iterator &rhs) const;
176
177 reverse_iterator operator+=(const difference_type &n);
178 reverse_iterator operator-=(const difference_type &n);
179
180 value_type operator[](const difference_type &n) const;
181 value_type & operator[](const difference_type &n);
182
183 private:
184 reverse_iterator(const std::string::reverse_iterator &iter);
185 reverse_iterator & operator=(const std::string::reverse_iterator &iter);
186
187 void * m_impl;
188 };
189 class ZENI_DLL const_reverse_iterator {
190 friend class String;
191
192 public:
193 typedef ptrdiff_t difference_type;
194 typedef std::random_access_iterator_tag iterator_category;
195 typedef char value_type;
196 typedef value_type * pointer;
197 typedef value_type & reference;
198
199 const_reverse_iterator();
200 ~const_reverse_iterator();
201
202 const_reverse_iterator(const const_reverse_iterator &rhs);
203 const_reverse_iterator & operator=(const const_reverse_iterator &rhs);
204
205 const_reverse_iterator(const String::reverse_iterator &rhs);
206 const_reverse_iterator & operator=(const String::reverse_iterator &rhs);
207
208 bool operator==(const const_reverse_iterator &rhs) const;
209 bool operator!=(const const_reverse_iterator &rhs) const;
210
211 value_type operator*() const;
212 value_type operator->() const;
213
214 const_reverse_iterator operator++();
215 const_reverse_iterator operator--();
216 const_reverse_iterator operator++(int);
217 const_reverse_iterator operator--(int);
218
219 const_reverse_iterator operator+(const difference_type &n) const;
220 const_reverse_iterator operator-(const difference_type &n) const;
221 difference_type operator-(const const_reverse_iterator &rhs) const;
222
223 bool operator<(const const_reverse_iterator &rhs) const;
224 bool operator>(const const_reverse_iterator &rhs) const;
225 bool operator<=(const const_reverse_iterator &rhs) const;
226 bool operator>=(const const_reverse_iterator &rhs) const;
227
228 const_reverse_iterator operator+=(const difference_type &n);
229 const_reverse_iterator operator-=(const difference_type &n);
230
231 value_type operator[](const difference_type &n) const;
232
233 private:
234 const_reverse_iterator(const std::string::const_reverse_iterator &iter);
235 const_reverse_iterator & operator=(const std::string::const_reverse_iterator &iter);
236
237 void * m_impl;
238 };
239
240 String();
241 String(const String &str);
242 String(const String &str, size_t pos, size_t n = npos);
243 String(const char * s, size_t n);
244 String(const char * s);
245 String(size_t n, char c);
246 //template<class InputIterator> String(InputIterator begin, InputIterator end) : std::string(begin, end) {}
247
248 ~String();
249
250 String & operator=(const String &str);
251 String & operator=(const char *s);
252 String & operator=(char c);
253
254 iterator begin();
255 const_iterator begin() const;
256
257 iterator end();
258 const_iterator end() const;
259
260 reverse_iterator rbegin();
261 const_reverse_iterator rbegin() const;
262
263 reverse_iterator rend();
264 const_reverse_iterator rend() const;
265
266 size_t size() const;
267
268 size_t length() const;
269
270 size_t max_size() const;
271
272 void resize(size_t n, char c);
273 void resize(size_t n);
274
275 size_t capacity() const;
276
277 void reserve(size_t res_arg = 0);
278
279 void clear();
280
281 bool empty() const;
282
283 value_type operator[](const unsigned int &pos) const;
284 value_type & operator[](const unsigned int &pos);
285
286 value_type at(size_t pos) const;
287 value_type & at(size_t pos);
288
289 String & operator+=(const String & str);
290 String & operator+=(const char *s);
291 String & operator+=(char c);
292
293 String & append(const String &str);
294 String & append(const String &str, size_t pos, size_t n);
295 String & append(const char *s, size_t n);
296 String & append(const char *s);
297 String & append(size_t n, char c);
298 //template <class InputIterator>
299 //String & append(InputIterator first, InputIterator last) {
300 // append(first, last);
301 // return *this;
302 //}
303
304 void push_back(char c);
305
306 String & assign(const String &str);
307 String & assign(const String &str, size_t pos, size_t n);
308 String & assign(const char *s, size_t n);
309 String & assign(const char *s);
310 String & assign(size_t n, char c);
311 //template <class InputIterator>
312 //String & assign(InputIterator first, InputIterator last) {
313 // assign(first, last);
314 // return *this;
315 //}
316
317 String & insert(size_t pos1, const String &str);
318 String & insert(size_t pos1, const String &str, size_t pos2, size_t n);
319 String & insert(size_t pos1, const char *s, size_t n);
320 String & insert(size_t pos1, const char *s);
321 String & insert(size_t pos1, size_t n, char c);
322 iterator insert(iterator p, char c);
323 void insert(iterator p, size_t n, char c);
324 //template<class InputIterator>
325 //void insert(iterator p, InputIterator first, InputIterator last) {
326 // insert(p, first, last);
327 //}
328
329 String & erase(size_t pos = 0, size_t n = npos);
330 iterator erase(iterator position);
331 iterator erase(iterator first, iterator last);
332
333 String & replace(size_t pos1, size_t n1, const String &str);
334 String & replace(iterator i1, iterator i2, const String &str);
335 String & replace(size_t pos1, size_t n1, const String &str, size_t pos2, size_t n2);
336 String & replace(size_t pos1, size_t n1, const char *s, size_t n2);
337 String & replace(iterator i1, iterator i2, const char *s, size_t n2);
338 String & replace(size_t pos1, size_t n1, const char *s);
339 String & replace(iterator i1, iterator i2, const char *s);
340 String & replace(size_t pos1, size_t n1, size_t n2, char c);
341 String & replace(iterator i1, iterator i2, size_t n2, char c);
342 //template<class InputIterator>
343 //String & replace(iterator i1, iterator i2, InputIterator j1, InputIterator j2) {
344 // replace(i1, i2, j1, j2);
345 // return *this;
346 //}
347
348 void swap(String &str);
349
350 const char * c_str() const;
351
352 const char * data() const;
353
354 size_t copy(char *s, size_t n, size_t pos = 0) const;
355
356 size_t find(const String &str, size_t pos = 0) const;
357 size_t find(const char *s, size_t pos, size_t n) const;
358 size_t find(const char *s, size_t pos = 0) const;
359 size_t find(char c, size_t pos = 0) const;
360
361 size_t rfind(const String &str, size_t pos = npos) const;
362 size_t rfind(const char *s, size_t pos, size_t n) const;
363 size_t rfind(const char *s, size_t pos = npos) const;
364 size_t rfind(char c, size_t pos = npos) const;
365
366 size_t find_first_of(const String &str, size_t pos = 0) const;
367 size_t find_first_of(const char *s, size_t pos, size_t n) const;
368 size_t find_first_of(const char *s, size_t pos = 0) const;
369 size_t find_first_of(char c, size_t pos = 0) const;
370
371 size_t find_last_of(const String &str, size_t pos = npos) const;
372 size_t find_last_of(const char *s, size_t pos, size_t n) const;
373 size_t find_last_of(const char *s, size_t pos = npos) const;
374 size_t find_last_of(char c, size_t pos = npos) const;
375
376 size_t find_first_not_of(const String &str, size_t pos = 0) const;
377 size_t find_first_not_of(const char *s, size_t pos, size_t n) const;
378 size_t find_first_not_of(const char *s, size_t pos = 0) const;
379 size_t find_first_not_of(char c, size_t pos = 0) const;
380
381 size_t find_last_not_of(const String &str, size_t pos = npos) const;
382 size_t find_last_not_of(const char *s, size_t pos, size_t n) const;
383 size_t find_last_not_of(const char *s, size_t pos = npos) const;
384 size_t find_last_not_of(char c, size_t pos = npos) const;
385
386 String substr(size_t pos = 0, size_t n = npos) const;
387
388 int compare(const String &str) const;
389 int compare(const char *s) const;
390 int compare(size_t pos1, size_t n1, const String &str) const;
391 int compare(size_t pos1, size_t n1, const char *s) const;
392 int compare(size_t pos1, size_t n1, const String &str, size_t pos2, size_t n2) const;
393 int compare(size_t pos1, size_t n1, const char *s, size_t n2) const;
394
395 bool operator==(const Zeni::String &rhs) const;
396 bool operator==(const char *rhs) const;
397 bool operator!=(const Zeni::String &rhs) const;
398 bool operator!=(const char *rhs) const;
399 bool operator<(const Zeni::String &rhs) const;
400 bool operator<(const char *rhs) const;
401 bool operator>(const Zeni::String &rhs) const;
402 bool operator>(const char *rhs) const;
403 bool operator<=(const Zeni::String &rhs) const;
404 bool operator<=(const char *rhs) const;
405 bool operator>=(const Zeni::String &rhs) const;
406 bool operator>=(const char *rhs) const;
407
408 struct ZENI_DLL Hash {
409 static const size_t bucket_size = 4;
410 static const size_t min_buckets = 8;
411
412 size_t operator()(const String &str) const;
413
414 bool operator()(const String &lhs, const String &rhs) const;
415 };
416
417 explicit inline String(const std::string &rhs) : m_impl(0) {
418 String lhs(rhs.data(), rhs.size());
419 swap(lhs);
420 }
421
422 inline String & operator=(const std::string &rhs) {
423 String lhs(rhs);
424 swap(lhs);
425 return *this;
426 }
427
428 inline std::string std_str() const {
429 std::string rv(data(), size());
430 return rv;
431 }
432
433 private:
434 std::string * m_impl;
435 };
436
437 }
438
439 ZENI_DLL Zeni::String::iterator operator+(const Zeni::String::iterator::difference_type &lhs, const Zeni::String::iterator &rhs);
440 ZENI_DLL Zeni::String::const_iterator operator+(const Zeni::String::const_iterator::difference_type &lhs, const Zeni::String::const_iterator &rhs);
441 ZENI_DLL Zeni::String::reverse_iterator operator+(const Zeni::String::reverse_iterator::difference_type &lhs, const Zeni::String::reverse_iterator &rhs);
442 ZENI_DLL Zeni::String::const_reverse_iterator operator+(const Zeni::String::const_reverse_iterator::difference_type &lhs, const Zeni::String::const_reverse_iterator &rhs);
443
444 ZENI_DLL Zeni::String operator+(const Zeni::String &lhs, const Zeni::String &rhs);
445 ZENI_DLL Zeni::String operator+(const Zeni::String &lhs, const char *rhs);
446 ZENI_DLL Zeni::String operator+(const Zeni::String &lhs, char rhs);
447 ZENI_DLL Zeni::String operator+(const char *lhs, const Zeni::String &rhs);
448 ZENI_DLL Zeni::String operator+(char lhs, const Zeni::String &rhs);
449
450 ZENI_DLL bool operator==(const char *lhs, const Zeni::String &rhs);
451 ZENI_DLL bool operator!=(const char *lhs, const Zeni::String &rhs);
452 ZENI_DLL bool operator<(const char *lhs, const Zeni::String &rhs);
453 ZENI_DLL bool operator>(const char *lhs, const Zeni::String &rhs);
454 ZENI_DLL bool operator<=(const char *lhs, const Zeni::String &rhs);
455 ZENI_DLL bool operator>=(const char *lhs, const Zeni::String &rhs);
456
457 ZENI_DLL void swap(Zeni::String &lhs, Zeni::String &rhs);
458
459 ZENI_DLL std::istream & operator>>(std::istream &is, const Zeni::String &str);
460 ZENI_DLL std::ostream & operator<<(std::ostream &os, const Zeni::String &str);
461
462 #endif
Zeni::String::Hash
Definition: String.h:408
Zeni::String::iterator::difference_type
ptrdiff_t difference_type
Definition: String.h:43
Zeni::String::const_iterator::difference_type
ptrdiff_t difference_type
Definition: String.h:93
s
GLdouble s
Definition: glew.h:1376
operator>
bool operator>(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:279
Zeni::String::iterator::reference
value_type & reference
Definition: String.h:47
Zeni::String::reverse_iterator::pointer
value_type * pointer
Definition: String.h:146
Zeni::String::iterator
Definition: String.h:39
operator<
bool operator<(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:273
Zeni::String::value_type
char value_type
Definition: String.h:33
pp::operator==
bool operator==(const SourceLocation &lhs, const SourceLocation &rhs)
Definition: SourceLocation.h:27
n
GLclampd n
Definition: glew.h:7287
operator+
TiXmlString operator+(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.cpp:86
operator>>
std::istream & operator>>(std::istream &is, Zeni::String &str)
Definition: String.cpp:582
Zeni::String::const_reverse_iterator
Definition: String.h:189
i2
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint GLint i2
Definition: SDL_glfuncs.h:118
Zeni::String::iterator::value_type
char value_type
Definition: String.h:45
Zeni::String::operator=
String & operator=(const std::string &rhs)
Definition: String.h:422
Zeni::String
Definition: String.h:29
Zeni::String::reverse_iterator::reference
value_type & reference
Definition: String.h:147
Zeni::String::iterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: String.h:44
Zeni::String::difference_type
ptrdiff_t difference_type
Definition: String.h:31
Zeni::String::pointer
value_type * pointer
Definition: String.h:34
Zeni::String::String
String(const std::string &rhs)
Definition: String.h:417
Zeni::String::iterator::pointer
value_type * pointer
Definition: String.h:46
Zeni::String::reference
value_type & reference
Definition: String.h:35
first
GLint first
Definition: gl2ext.h:1011
length
GLsizei GLsizei * length
Definition: gl2ext.h:792
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
Zeni::String::const_iterator::value_type
char value_type
Definition: String.h:95
Zeni::String::reverse_iterator::value_type
char value_type
Definition: String.h:145
p
GLfloat GLfloat p
Definition: glew.h:14938
empty
static const char empty[1]
Definition: bdflib.c:513
c
const GLfloat * c
Definition: glew.h:14913
Zeni::String::const_iterator
Definition: String.h:89
Zeni::String::const_iterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: String.h:94
Zeni::operator*
Quaternion operator*(const float &lhs, const Quaternion &rhs)
Definition: Quaternion.h:110
Zeni::String::const_reverse_iterator::pointer
value_type * pointer
Definition: String.h:196
pp::operator!=
bool operator!=(const SourceLocation &lhs, const SourceLocation &rhs)
Definition: SourceLocation.h:32
i1
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint i1
Definition: SDL_glfuncs.h:118
pp::operator<<
std::ostream & operator<<(std::ostream &out, const Token &token)
Definition: Token.cpp:74
Zeni::String::const_reverse_iterator::value_type
char value_type
Definition: String.h:195
Zeni::String::const_iterator::pointer
value_type * pointer
Definition: String.h:96
Zeni::String::const_reverse_iterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: String.h:194
operator>=
bool operator>=(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:281
Zeni::String::reverse_iterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: String.h:144
swap
void swap(Zeni::String &lhs, Zeni::String &rhs)
Definition: String.cpp:578
string
GLsizei const GLcharARB ** string
Definition: glew.h:5638
Zeni::String::size_type
size_t size_type
Definition: String.h:32
Zeni::String::const_reverse_iterator::difference_type
ptrdiff_t difference_type
Definition: String.h:193
Zeni::String::reverse_iterator::difference_type
ptrdiff_t difference_type
Definition: String.h:143
end
GLuint GLuint end
Definition: glew.h:1239
Zeni::String::reverse_iterator
Definition: String.h:139
Zeni::String::std_str
std::string std_str() const
Definition: String.h:428
str
#define str(s)
Zeni::String::const_reverse_iterator::reference
value_type & reference
Definition: String.h:197
operator<=
bool operator<=(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:280
Zeni::String::const_iterator::reference
value_type & reference
Definition: String.h:97
size
GLsizei size
Definition: gl2ext.h:1467