14 typedef wchar_t mychar;
16 static size_t mystrlen(
const mychar * str){
18 for(
const mychar * it = str; *it; ++it, ++i){
26 struct const_iterator {
27 inline const_iterator& operator ++(
void) { ++it;
return *
this; }
28 inline const_iterator& operator --(
void) { --it;
return *
this; }
29 inline const_iterator& operator +=(
long i) { it += i;
return *
this; }
30 inline const_iterator& operator -=(
long i) { it -= i;
return *
this; }
31 inline const_iterator operator ++(
int) {
32 const_iterator result(*
this);
36 inline const_iterator operator --(
int) {
37 const_iterator result(*
this);
41 inline const_iterator operator +(
long i)
const {
42 const_iterator result(*
this);
46 inline const_iterator operator -(
long i)
const {
47 const_iterator result(*
this);
51 inline size_t operator -(const_iterator other)
const {
54 inline mychar & operator [](
size_t pos)
const {
return it[pos]; };
55 inline mychar & operator *(
void)
const {
return *it; }
56 inline bool operator == (
const const_iterator & other)
const {
return it == other.it; }
57 inline bool operator != (
const const_iterator & other)
const {
return it != other.it; }
58 inline bool operator > (
const const_iterator & other)
const {
return it > other.it; }
59 inline bool operator >= (
const const_iterator & other)
const {
return it >= other.it; }
60 inline bool operator < (
const const_iterator & other)
const {
return it < other.it; }
61 inline bool operator <= (
const const_iterator & other)
const {
return it <= other.it; }
62 inline const_iterator & operator = (
const const_iterator & orig) { it = orig.it;
return *
this; }
63 const_iterator (
const const_iterator & orig) : it(orig.it) {}
64 const_iterator (
const mychar * place) : it((mychar*)place) {}
65 const_iterator(
void) : it(0) {};
71 inline iterator& operator ++(
void) { ++it;
return *
this; }
72 inline iterator& operator --(
void) { --it;
return *
this; }
73 inline iterator& operator +=(
long i) { it += i;
return *
this; }
74 inline iterator& operator -=(
long i) { it -= i;
return *
this; }
75 inline iterator operator ++(
int) {
76 iterator result(*
this);
80 inline iterator operator --(
int) {
81 iterator result(*
this);
85 inline iterator operator +(
long i)
const {
86 iterator result(*
this);
90 inline iterator operator -(
long i)
const {
91 iterator result(*
this);
95 inline mychar & operator [](
size_t pos)
const {
return it[pos]; };
96 inline mychar & operator *(
void)
const {
return *it; }
97 inline bool operator == (
const iterator & other)
const {
return it == other.it; }
98 inline bool operator != (
const iterator & other)
const {
return it != other.it; }
99 inline bool operator > (
const iterator & other)
const {
return it > other.it; }
100 inline bool operator >= (
const iterator & other)
const {
return it >= other.it; }
101 inline bool operator < (
const iterator & other)
const {
return it < other.it; }
102 inline bool operator <= (
const iterator & other)
const {
return it <= other.it; }
103 inline iterator & operator = (
const iterator & orig) { it = orig.it;
return *
this; }
104 inline operator const_iterator() const json_nothrow {
return const_iterator(it); }
105 iterator (
const iterator & orig) : it(orig.it) {}
106 iterator (
const mychar * place) : it((mychar*)place) {}
112 const static size_t npos = 0xFFFFFFFF;
118 setToCStr(meh, mystrlen(meh));
121 json_string(
const mychar * meh,
size_t l) : len(l), str(0){
126 json_string(
const iterator & beg,
const iterator & en) : len(0), str(0){
127 setToCStr(beg.it, en.it - beg.it);
131 json_string(
const const_iterator & beg,
const const_iterator & en) : len(0), str(0){
132 setToCStr(beg.it, en.it - beg.it);
137 setToCStr(meh.c_str(), meh.len);
142 json_string(
unsigned int l, mychar meh) : len(0), str(0){
143 str = (mychar*)std::malloc((l + 1) *
sizeof(mychar));
145 for (
unsigned int i = 0; i < l; ++i){
160 iterator begin(
void){
return iterator(str); };
161 iterator end(
void){
return iterator(str + length()); };
162 const iterator begin(
void)
const {
return iterator(str); };
163 const iterator end(
void)
const {
return iterator(str + length()); };
164 void assign(
const iterator & beg,
const iterator & en){
167 json_string & append(
const iterator & beg,
const iterator & en){
169 return *
this += temp;
172 const mychar * c_str(
void)
const {
return str; };
173 const mychar * data(
void)
const {
return str; };
174 size_t length(
void)
const {
return len; };
175 size_t capacity(
void)
const {
return len; };
176 bool empty(
void)
const {
return len == 0; };
178 bool operator ==(
const json_string & other)
const {
179 if (len != other.len)
return false;
180 return memcmp(str, other.str, len *
sizeof(mychar)) == 0;
183 bool operator !=(
const json_string & other)
const {
184 return !(*
this == other);
187 const wchar_t & operator[] (
size_t pos)
const {
return str[pos]; }
188 wchar_t & operator[] (
size_t pos ){
return str[pos]; }
192 setToCStr(meh.c_str(), meh.len);
198 setToCStr(meh, mystrlen(meh));
203 size_t newlen = len + other.len;
204 mychar * newstr = (mychar*)std::malloc((newlen + 1) *
sizeof(mychar));
205 std::memcpy(newstr, str, len *
sizeof(mychar));
206 std::memcpy(newstr + len, other.str, (other.len + 1) *
sizeof(mychar));
220 mychar temp[2] = {other, L
'\0'};
222 return (*
this) += temp_s;
225 const json_string operator + (
const mychar other)
const {
231 void reserve(
size_t){};
232 void clear(
void){setToCStr(L
"", 0);}
234 json_string substr(
size_t pos = 0,
size_t n = npos)
const {
236 if (n > len) n = len;
237 if (n + pos > len) n = len - pos;
238 res.setToCStr(str + pos, n);
244 size_t find ( mychar c,
size_t pos = 0 )
const {
245 if (pos > len)
return npos;
246 for(mychar * i = str + pos; *i; ++i){
247 if (*i == c)
return i - str;
252 size_t find_first_not_of (
const mychar* s,
size_t pos = 0 )
const {
253 if (pos > len)
return npos;
254 for(mychar * i = str + pos; *i; ++i){
256 for(
const mychar * k = s; *k; ++k){
262 if (!found)
return i - str;
267 size_t find_first_of (
const mychar* s,
size_t pos = 0 )
const {
268 if (pos > len)
return npos;
269 for(mychar * i = str + pos; *i; ++i){
270 for(
const mychar * k = s; *k; ++k){
279 iterator erase(iterator it, iterator it2){
280 size_t mov = it2.it - it.it;
281 std::memmove(str, it2.it, (len - mov + 1) *
sizeof(mychar));
288 void setToCStr(
const mychar * st,
size_t l){
290 str = (mychar*)std::memcpy(std::malloc((len + 1) *
sizeof(mychar)), st, (len + 1) *
sizeof(mychar));
Definition: StringTest.h:22