ClanLib  2.3.7
string_data8.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Harry Storbacka
28 */
29 
32 
33 #pragma once
34 
35 #include "../api_core.h"
36 #include <string>
37 
38 class CL_StringRef8;
39 
44 {
45 public:
46  typedef unsigned int size_type;
47  static const size_type npos; // = 0xffffffff;
48  typedef char char_type;
49  typedef char *iterator;
50  typedef const char *const_iterator;
51 
53 
58  CL_StringData8(const char *ptr, size_type length);
59 
63  iterator begin() { return (iterator) data_ptr; }
64 
68  iterator end() { return begin() + data_length; }
69 
73  const_iterator begin() const { return (const_iterator) data_ptr; }
74 
78  const_iterator end() const { return begin() + data_length; }
79 
80 // reverse_iterator rbegin();
81 // reverse_iterator rend();
82 // const_reverse_iterator rbegin() const;
83 // const_reverse_iterator rend() const;
84 
85  const char &operator[](size_type n) const { return *(data_ptr + n); }
86  char &operator[](size_type n) { return *(data_ptr + n); }
87 
88  const char *data() const { return data_ptr; }
89 
93  char *data() { return data_ptr; }
94 
98  operator std::string() const;
99 
103  operator CL_StringRef8() const;
104 
108  size_type size() const { return data_length; }
109 
113  size_type length() const { return data_length; }
114 
118  bool empty() const { return data_length == 0; }
119 
126  size_type find(const CL_StringData8 &s, size_type pos = 0) const;
127 
135  size_type find(const char *s, size_type pos, size_type n) const;
136 
143  size_type find(const char *s, size_type pos = 0) const;
144 
151  size_type find(char c, size_type pos = 0) const;
152 
159  size_type rfind(const CL_StringData8 &s, size_type pos = npos) const;
160 
168  size_type rfind(const char *s, size_type pos, size_type n) const;
169 
176  size_type rfind(const char *s, size_type pos = npos) const;
177 
184  size_type rfind(char c, size_type pos = npos) const;
185 
192  size_type find_first_of(const CL_StringData8 &s, size_type pos = 0) const;
193 
201  size_type find_first_of(const char *s, size_type pos, size_type n) const;
202 
209  size_type find_first_of(const char *s, size_type pos = 0) const;
210 
217  size_type find_first_of(char c, size_type pos = 0) const;
218 
225  size_type find_first_not_of(const CL_StringData8 &s, size_type pos = 0) const;
226 
234  size_type find_first_not_of(const char *s, size_type pos, size_type n) const;
235 
242  size_type find_first_not_of(const char *s, size_type pos = 0) const;
243 
250  size_type find_first_not_of(char c, size_type pos = 0) const;
251 
258  size_type find_last_of(const CL_StringData8 &s, size_type pos = npos) const;
259 
267  size_type find_last_of(const char *s, size_type pos, size_type n) const;
268 
275  size_type find_last_of(const char *s, size_type pos = npos) const;
276 
283  size_type find_last_of(char c, size_type pos = npos) const;
284 
291  size_type find_last_not_of(const CL_StringData8 &s, size_type pos = npos) const;
292 
300  size_type find_last_not_of(const char *s, size_type pos, size_type n) const;
301 
308  size_type find_last_not_of(const char *s, size_type pos = npos) const;
309 
316  size_type find_last_not_of(char c, size_type pos = npos) const;
317 
324  CL_StringRef8 substr(size_type pos = 0, size_type n = npos) const;
325 
331  int compare(const CL_StringData8 &s) const;
332 
340  int compare(size_type pos, size_type n, const CL_StringData8 &s) const;
341 
351  int compare(size_type pos, size_type n, const CL_StringData8 &s, size_type pos1, size_type n1) const;
352 
358  int compare(const char *s) const;
359 
368  int compare(size_type pos, size_type n, const char *s, size_type len = npos) const;
369 
370 
371  size_type utf8_length() const;
372 protected:
373  mutable char *data_ptr;
375 };
376 
377 CL_API_CORE bool operator==(const CL_StringData8 &s1, const CL_StringData8 &s2);
378 CL_API_CORE bool operator==(const char *s1, const CL_StringData8 &s2);
379 CL_API_CORE bool operator==(const CL_StringData8 &s1, const char *s2);
380 CL_API_CORE bool operator!=(const CL_StringData8 &s1, const CL_StringData8 &s2);
381 CL_API_CORE bool operator!=(const char *s1, const CL_StringData8 &s2);
382 CL_API_CORE bool operator!=(const CL_StringData8 &s1, const char *s2);
383 CL_API_CORE bool operator<(const CL_StringData8 &s1, const CL_StringData8 &s2);
384 CL_API_CORE bool operator<(const char *s1, const CL_StringData8 &s2);
385 CL_API_CORE bool operator<(const CL_StringData8 &s1, const char *s2);
386 CL_API_CORE bool operator>(const CL_StringData8 &s1, const CL_StringData8 &s2);
387 CL_API_CORE bool operator>(const char *s1, const CL_StringData8 &s2);
388 CL_API_CORE bool operator>(const CL_StringData8 &s1, const char *s2);
389