14 static size_t mystrlen(
const mychar * str){
16 for(
const mychar * it = str; *it; ++it, ++i){
27 inline const_iterator& operator +=(
long i) { it += i;
return *
this; }
28 inline const_iterator& operator -=(
long i) { it -= i;
return *
this; }
52 inline mychar & operator [](
size_t pos)
const {
return it[pos]; };
53 inline mychar & operator *(
void)
const {
return *it; }
54 inline bool operator == (
const const_iterator & other)
const {
return it == other.it; }
55 inline bool operator != (
const const_iterator & other)
const {
return it != other.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; }
69 inline iterator& operator ++(
void) { ++it;
return *
this; }
70 inline iterator& operator --(
void) { --it;
return *
this; }
71 inline iterator& operator +=(
long i) { it += i;
return *
this; }
72 inline iterator& operator -=(
long i) { it -= i;
return *
this; }
83 inline iterator operator +(
long i)
const {
88 inline iterator operator -(
long i)
const {
93 inline mychar & operator [](
size_t pos)
const {
return it[pos]; };
94 inline mychar & operator *(
void)
const {
return *it; }
95 inline bool operator == (
const iterator & other)
const {
return it == other.it; }
96 inline bool operator != (
const iterator & other)
const {
return it != other.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 iterator & operator = (
const iterator & orig) { it = orig.it;
return *
this; }
104 iterator (
const mychar * place) : it((mychar*)place) {}
111 const static size_t npos = 0xFFFFFFFF;
117 setToCStr(meh, mystrlen(meh));
120 json_string(
const mychar * meh,
size_t l) : len(l), str(0){
125 json_string(
const iterator & beg,
const iterator & en) : len(0), str(0){
126 setToCStr(beg.it, en.it - beg.it);
130 json_string(
const const_iterator & beg,
const const_iterator & en) : len(0), str(0){
131 setToCStr(beg.it, en.it - beg.it);
136 setToCStr(meh.c_str(), meh.len);
141 json_string(
unsigned int l, mychar meh) : len(0), str(0){
142 str = (mychar*)std::malloc((l + 1) *
sizeof(mychar));
144 for (
unsigned int i = 0; i < l; ++i){
159 iterator begin(
void){
return iterator(str); };
160 iterator end(
void){
return iterator(str + length()); };
161 const iterator begin(
void)
const {
return iterator(str); };
162 const iterator end(
void)
const {
return iterator(str + length()); };
163 void assign(
const iterator & beg,
const iterator & en){
166 json_string & append(
const iterator & beg,
const iterator & en){
168 return *
this += temp;
171 const mychar * c_str(
void)
const {
return str; };
172 const mychar * data(
void)
const {
return str; };
173 size_t length(
void)
const {
return len; };
174 size_t capacity(
void)
const {
return len; };
175 bool empty(
void)
const {
return len == 0; };
177 bool operator ==(
const json_string & other)
const {
178 if (len != other.len)
return false;
179 return memcmp(str, other.str, len *
sizeof(mychar)) == 0;
182 bool operator !=(
const json_string & other)
const {
183 return !(*
this == other);
186 const char & operator[] (
size_t pos)
const {
return str[pos]; }
187 char & operator[] (
size_t pos ){
return str[pos]; }
191 setToCStr(meh.c_str(), meh.len);
197 setToCStr(meh, mystrlen(meh));
202 size_t newlen = len + other.len;
203 mychar * newstr = (mychar*)std::malloc((newlen + 1) *
sizeof(mychar));
204 std::memcpy(newstr, str, len *
sizeof(mychar));
205 std::memcpy(newstr + len, other.str, (other.len + 1) *
sizeof(mychar));
219 mychar temp[2] = {other,
'\0'};
221 return (*
this) += temp_s;
224 const json_string operator + (
const mychar other)
const {
230 void reserve(
size_t){};
231 void clear(
void){setToCStr(
"", 0);}
233 json_string substr(
size_t pos = 0,
size_t n = npos)
const {
235 if (n > len) n = len;
236 if (n + pos > len) n = len - pos;
237 res.setToCStr(str + pos, n);
243 size_t find ( mychar c,
size_t pos = 0 )
const {
244 if (pos > len)
return npos;
245 for(mychar * i = str + pos; *i; ++i){
246 if (*i == c)
return i - str;
251 size_t find_first_not_of (
const mychar* s,
size_t pos = 0 )
const {
252 if (pos > len)
return npos;
253 for(mychar * i = str + pos; *i; ++i){
255 for(
const mychar * k = s; *k; ++k){
261 if (!found)
return i - str;
266 size_t find_first_of (
const mychar* s,
size_t pos = 0 )
const {
267 if (pos > len)
return npos;
268 for(mychar * i = str + pos; *i; ++i){
269 for(
const mychar * k = s; *k; ++k){
278 iterator erase(iterator it, iterator it2){
279 size_t mov = it2.it - it.it;
280 std::memmove(str, it2.it, (len - mov + 1) *
sizeof(mychar));
287 void setToCStr(
const mychar * st,
size_t l){
289 str = (mychar*)std::memcpy(std::malloc((len + 1) *
sizeof(mychar)), st, (len + 1) *
sizeof(mychar));
Definition: StringTest.h:68
Definition: StringTest.h:24
Definition: StringTest.h:22