ZFFramework
Loading...
Searching...
No Matches
zfstring.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_zfstring_h_
7#define _ZFI_zfstring_h_
8
11#include "ZFCoreMutex.h"
12#include "ZFMemPool.h"
13
15
19template<int minCapacityRadix>
21 capacity >>= minCapacityRadix;
22 capacity |= capacity >> 1;
23 capacity |= capacity >> 2;
24 capacity |= capacity >> 4;
25 capacity |= capacity >> 8;
26 capacity |= capacity >> 16;
27 ++capacity;
28 capacity <<= minCapacityRadix;
29}
30
31// ============================================================
32template<typename T_Char>
33zfindex _ZFP_zfstring_len(ZF_IN const T_Char *s) {
34 const T_Char *p = s;
35 while(*p) {++p;}
36 return p - s;
37}
38inline zfindex _ZFP_zfstring_len(ZF_IN const zfchar *s) {
39 return zfslen(s);
40}
41template<typename T_Char>
42zfint _ZFP_zfstring_cmp(
43 ZF_IN const T_Char *s1
44 , ZF_IN const T_Char *s1End
45 , ZF_IN const T_Char *s2
46 , ZF_IN const T_Char *s2End
47 ) {
48 while(s1 < s1End && s2 < s2End && *s1 == *s2) {++s1, ++s2;}
49 if(s1 == s1End) {
50 if(s2 == s2End) {
51 return 0;
52 }
53 else {
54 return -1;
55 }
56 }
57 else {
58 if(s2 == s2End) {
59 return 1;
60 }
61 else {
62 return *s1 - *s2;
63 }
64 }
65}
66
67template<typename T_Char>
68zfclassNotPOD _ZFP_zfstringD {
69public:
70 zfuint refCount;
71 // capacity: including tail '\0'
72 // possible values:
73 // * _ZFP_ST_Shared and length > 0 : shared string and null terminated
74 // * >= _ZFP_ST_Normal : normal allocated string
75 zfuint capacity;
76 zfuint length;
77 union {
78 T_Char *buf; // capacity >= _ZFP_ST_Normal
79 const T_Char *ptr; // capacity = _ZFP_ST_Shared
80 } d;
81public:
82 _ZFP_zfstringD(void) : refCount(1), capacity(0), length(0), d() {
83 d.ptr = Empty();
84 }
85 ~_ZFP_zfstringD(void) {
86 if(this->capacity >= 2 /* _ZFP_ST_Normal */) {
87 zfunsafe_zfpoolFree(this->d.buf);
88 }
89 }
90public:
91 static const T_Char *Empty(void) {
92 static T_Char buf[1] = {0};
93 return buf;
94 }
95};
96template<typename T_Char>
97zfclassLikePOD _ZFP_zfstringH {
98public:
99 _ZFP_zfstringH(void) : d(zfpoolNew(_ZFP_zfstringD<T_Char>)) {}
100 ~_ZFP_zfstringH(void) {zfpoolDelete(d);}
101public:
102 _ZFP_zfstringD<T_Char> *d;
103};
104
105// ============================================================
109template<typename T_Char>
111public:
114 {
116 d = _ZFP_Empty();
117 ++(d->refCount);
118 }
119
121 {
123 d = s.d;
124 ++(d->refCount);
125 }
126
128 {
130 d = _ZFP_Empty();
131 ++(d->refCount);
132 if(len >= s.length()) {
133 this->assign(s);
134 }
135 else {
136 this->assign(s.cString(), len);
137 }
138 }
139
141 {
143 d = _ZFP_Empty();
144 ++(d->refCount);
145 if(pos < s.length()) {
146 if(len > s.length() - pos) {
147 len = s.length() - pos;
148 }
149 this->assign(s.cString() + pos, len);
150 }
151 }
152
153 zft_zfstring(ZF_IN const T_Char *s)
154 {
156 d = _ZFP_Empty();
157 ++(d->refCount);
158 if(s) {
159 this->assign(s);
160 }
161 }
162
163 zft_zfstring(ZF_IN const T_Char *s, ZF_IN zfindex len)
164 {
166 d = _ZFP_Empty();
167 ++(d->refCount);
168 if(s) {
169 this->assign(s, len);
170 }
171 }
172
173 zft_zfstring(ZF_IN const T_Char *s, ZF_IN zfindex pos, ZF_IN zfindex len)
174 {
176 d = _ZFP_Empty();
177 ++(d->refCount);
178 if(s) {
179 this->assign(s + pos, len);
180 }
181 }
182
184 {
186 d = _ZFP_Empty();
187 ++(d->refCount);
188 }
189 ~zft_zfstring(void) {
191 if(--(d->refCount) == 0) {
193 }
194 }
195
196public:
198 inline operator const T_Char * (void) const {
199 return this->isEmpty() ? zfnull : this->cString();
200 }
201 inline operator zfbool (void) const {
202 return !this->isEmpty();
203 }
204public:
205 inline zft_zfstring<T_Char> &operator = (ZF_IN const zft_zfstring<T_Char> &s) {
206 if(d != s.d) {
208 _ZFP_zfstringD<T_Char> *dTmp = d;
209 d = s.d;
210 ++(d->refCount);
211 if(--(dTmp->refCount) == 0) {
213 }
214 }
215 return *this;
216 }
217 inline zft_zfstring<T_Char> &operator = (ZF_IN const T_Char *s) {return this->assign(s);}
218 inline zft_zfstring<T_Char> &operator = (ZF_IN zfnullT const &dummy) {return this->assign(dummy);}
219 zfbool operator == (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->isEqual(ref);}
220 zfbool operator != (ZF_IN const zft_zfstring<T_Char> &ref) const {return !this->isEqual(ref);}
221 zfbool operator == (ZF_IN const T_Char *ref) const {return this->isEqual(ref);}
222 zfbool operator != (ZF_IN const T_Char *ref) const {return !this->isEqual(ref);}
223 zfbool operator == (ZF_IN zfnullT const &dummy) const {return this->isEmpty();}
224 zfbool operator != (ZF_IN zfnullT const &dummy) const {return !this->isEmpty();}
225public:
226 /* ZFTAG_TRICKS: tricks to make zfstlmap<zfstring, xxx> works */
227 inline zfbool operator < (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->compare(ref) < 0;}
228 inline zfbool operator <= (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->compare(ref) <= 0;}
229 inline zfbool operator > (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->compare(ref) > 0;}
230 inline zfbool operator >= (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->compare(ref) >= 0;}
232
233public:
235 inline zft_zfstring<T_Char> &operator += (ZF_IN T_Char c) {return this->append(c);}
236 inline zft_zfstring<T_Char> &operator += (ZF_IN const zft_zfstring<T_Char> &s) {return this->append(s);}
237 inline zft_zfstring<T_Char> &operator += (ZF_IN const T_Char *s) {return this->append(s);}
238
239 template<typename T_Int>
240 inline const T_Char *operator + (ZF_IN T_Int const &offset) const {
241 return this->cString() + offset;
242 }
244
245public:
249 void set(
250 ZF_IN zfindex pos
251 , ZF_IN T_Char c
252 ) {
253 _prepareWrite(this->length());
254 d->d.buf[pos] = c;
255 }
256
259 inline T_Char get(ZF_IN zfindex pos) const {
260 return d->d.ptr[pos];
261 }
262
264 template<typename T_Int>
265 inline T_Char operator [] (ZF_IN T_Int pos) const {
266 return this->get(pos);
267 }
269
270public:
277 _ZFP_zfstringD<T_Char> *dTmp = d;
278 d = ref.d;
279 ref.d = dTmp;
280 }
281
282public:
285 _prepareWrite(d->length + 1);
286 d->d.buf[d->length] = c;
287 d->d.buf[++(d->length)] = '\0';
288 return *this;
289 }
290
292 if(s) {
293 if(this->capacity() != 0) {
294 _appendImpl(s.cString(), s.length());
295 }
296 else {
297 this->operator = (s);
298 }
299 }
300 return *this;
301 }
302
305 , ZF_IN zfindex len
306 ) {
307 len = (len <= s.length() ? len : s.length());
308 if(len > 0) {
309 _appendImpl(s.cString(), len);
310 }
311 return *this;
312 }
313
316 , ZF_IN zfindex offset
317 , ZF_IN zfindex len
318 ) {
319 if(offset > s.length()) {
320 offset = s.length();
321 }
322 if(len > s.length() - offset) {
323 len = s.length() - offset;
324 }
325 if(len > 0) {
326 _appendImpl(s.cString() + offset, len);
327 }
328 return *this;
329 }
330
332 ZF_IN const void *s
334 ) {
335 if(s) {
336 if(len == zfindexMax()) {
337 len = _ZFP_zfstring_len((const T_Char *)s);
338 }
339 if(len > 0) {
340 _appendImpl(s, len);
341 }
342 }
343 return *this;
344 }
345private:
346 void _appendImpl(
347 ZF_IN const void *s
348 , ZF_IN zfindex len
349 ) {
350 _prepareWrite(d->length + len);
351 zfmemcpy(d->d.buf + d->length, s, len * sizeof(T_Char));
352 d->d.buf[d->length += (zfuint)len] = '\0';
353 }
354
355public:
358 this->operator = (s);
359 return *this;
360 }
361
364 , ZF_IN zfindex len
365 ) {
366 return this->assign(s.cString(), len <= s.length() ? len : s.length());
367 }
368
371 , ZF_IN zfindex offset
372 , ZF_IN zfindex len
373 ) {
374 if(offset > s.length()) {
375 offset = s.length();
376 }
377 if(len > s.length() - offset) {
378 len = s.length() - offset;
379 }
380 return this->assign(s.cString() + offset, len);
381 }
382
384 ZF_IN const void *s
386 ) {
387 if(len == zfindexMax()) {
388 if(s) {
389 len = _ZFP_zfstring_len((const T_Char *)s);
390 }
391 else {
392 len = 0;
393 }
394 }
395 if(len > 0) {
396 if(len >= d->capacity || d->refCount > 1
397 || (d->capacity >= 128 && len < d->capacity / 3)
398 ) {
399 _capacityChange(len, zffalse);
400 }
401 d->length = (zfuint)len;
402 zfmemcpy(d->d.buf, s, len * sizeof(T_Char));
403 d->d.buf[len] = '\0';
404 }
405 else {
406 this->removeAll();
407 }
408 return *this;
409 }
410
411 inline zft_zfstring<T_Char> &assign(ZF_IN const zfnullT &dummy) {
412 this->removeAll();
413 return *this;
414 }
415
416public:
419 ZF_IN zfindex insertAt
420 , ZF_IN const zft_zfstring<T_Char> &s
421 ) {
422 return this->insert(insertAt, s.cString(), s.length());
423 }
424
426 ZF_IN zfindex insertAt
427 , ZF_IN const void *s
429 ) {
430 if(insertAt >= this->length()) {
431 this->append(s, len);
432 }
433 else if(s) {
434 if(len == zfindexMax()) {
435 len = _ZFP_zfstring_len((const T_Char *)s);
436 }
437 if(len > 0) {
438 zfindex lenTmp = this->length();
439 _prepareWrite(lenTmp + len);
440 d->length = (zfuint)(lenTmp + len);
441 zfmemmove(d->d.buf + insertAt + len, d->d.buf + insertAt, (lenTmp - insertAt) * sizeof(T_Char));
442 zfmemcpy(d->d.buf + insertAt, s, len * sizeof(T_Char));
443 d->d.buf[d->length] = '\0';
444 }
445 }
446 return *this;
447 }
448
449public:
452 ZF_IN zfindex replacePos
453 , ZF_IN zfindex replaceLen
454 , ZF_IN const zft_zfstring<T_Char> &s
455 ) {
456 return this->replace(replacePos, replaceLen, s.cString(), s.length());
457 }
458
460 ZF_IN zfindex replacePos
461 , ZF_IN zfindex replaceLen
462 , ZF_IN const void *s
464 ) {
465 if(replacePos >= this->length()) {
466 this->append(s, len);
467 }
468 else if(s) {
469 zfindex lenTmp = this->length();
470 if(replaceLen > lenTmp - replacePos) {
471 replaceLen = lenTmp - replacePos;
472 }
473 if(len == zfindexMax()) {
474 len = _ZFP_zfstring_len((const T_Char *)s);
475 }
476 if(len > replaceLen) {
477 _prepareWrite(lenTmp + len - replaceLen);
478 }
479 else {
480 _prepareWrite(lenTmp);
481 }
482 zfmemmove(d->d.buf + replacePos + len, d->d.buf + replacePos + replaceLen, (lenTmp - replacePos - replaceLen) * sizeof(T_Char));
483 zfmemcpy(d->d.buf + replacePos, s, len * sizeof(T_Char));
484 d->length = (zfuint)(lenTmp + len - replaceLen);
485 d->d.buf[d->length] = '\0';
486 }
487 return *this;
488 }
489
490public:
494 inline const T_Char *cString(void) const {
495 return d->d.ptr;
496 }
497
498 inline zfindex length(void) const {
499 return (zfindex)d->length;
500 }
501
502 inline zfbool isShared(void) const {
503 return d->capacity < _ZFP_ST_Normal && d->length > 0;
504 }
505
506 inline zfbool isEmpty(void) const {
507 return d->length == 0;
508 }
509
510 inline zfbool isEqual(ZF_IN const zft_zfstring<T_Char> &ref) const {
511 return d == ref.d || (this->length() == ref.length() && this->compare(ref) == 0);
512 }
513
514 inline zfbool isEqual(ZF_IN const T_Char *s) const {
515 return 0 == _ZFP_zfstring_cmp(this->cString(), this->cString() + this->length(), s, s + (s ? _ZFP_zfstring_len(s) : 0));
516 }
517
518public:
521 if(capacity >= d->capacity) {
522 return _capacityChange(capacity - 1, zftrue);
523 }
524 else {
525 return zftrue;
526 }
527 }
528
529 inline zfindex capacity(void) const {
530 if(d->capacity >= _ZFP_ST_Normal) {
531 return (zfindex)d->capacity;
532 }
533 else {
534 return 0;
535 }
536 }
537
538 inline void capacityTrim(void) {
539 if(d->capacity >= 128 && d->length < d->capacity / 3) {
540 _capacityChange(this->length(), zftrue);
541 }
542 }
543
544 void remove(
545 ZF_IN zfindex pos
547 ) {
548 zfindex lenTmp = this->length();
549 if(pos < lenTmp) {
550 if(len > lenTmp - pos) {
551 len = lenTmp - pos;
552 }
553 if(len > 0) {
554 _prepareWrite(lenTmp);
555 zfmemmove(d->d.buf + pos, d->d.buf + pos + len, (lenTmp - pos - len) * sizeof(T_Char));
556 d->length -= (zfuint)len;
557 d->d.buf[d->length] = '\0';
558 }
559 }
560 }
561
562 void removeAll(void) {
563 if(!this->isEmpty()) {
565 if(d->refCount == 1) {
566 if(d->capacity >= 128) {
567 if(--(d->refCount) == 0) {
569 }
570 d = _ZFP_Empty();
571 ++(d->refCount);
572 }
573 else if(d->capacity >= _ZFP_ST_Normal) {
574 d->d.buf[0] = '\0';
575 d->length = 0;
576 }
577 else {
578 d->d.ptr = _ZFP_zfstringD<T_Char>::Empty();
579 d->length = 0;
580 }
581 }
582 else {
583 if(--(d->refCount) == 0) {
585 }
586 d = _ZFP_Empty();
587 ++(d->refCount);
588 }
589 }
590 }
591
592public:
594 inline zfint compare(ZF_IN const zft_zfstring<T_Char> &s) const {
595 return d == s.d ? 0 : _ZFP_zfstring_cmp(this->cString(), this->cString() + this->length(), s.cString(), s.cString() + s.length());
596 }
597
599 ZF_IN const T_Char *s
600 , ZF_IN zfindex len = zfindexMax()
601 ) const {
602 if(len == zfindexMax()) {
603 len = s ? _ZFP_zfstring_len(s) : 0;
604 }
605 return _ZFP_zfstring_cmp(this->cString(), this->cString() + this->length(), s, s + (s ? _ZFP_zfstring_len(s) : 0));
606 }
607
608public:
612 const void *buffer(void) const {
613 return d->d.ptr;
614 }
615
622 _prepareWrite(this->length());
623 ret = (void *)d->d.buf;
624 length = d->length;
625
626 d->capacity = 0;
627 d->length = 0;
628 d->d.ptr = _ZFP_zfstringD<T_Char>::Empty();
630
631 d = _ZFP_Empty();
632 ++(d->refCount);
633 }
634
637 static void zfunsafe_bufferFree(ZF_IN void *buf) {
638 zfpoolFree(buf);
639 }
640
644 T_Char *zfunsafe_buffer(void) {
645 _prepareWrite(this->length());
646 return d->d.buf;
647 }
648
652 _prepareWrite(this->length());
653 d->length = (zfuint)length;
654 }
655
656private:
657 enum { // string type
658 _ZFP_ST_Shared = 0, // shared and null terminated
659 _ZFP_ST_Normal = 1, // normal allocated
660 };
661private:
662 _ZFP_zfstringD<T_Char> *d;
663public:
665 static inline const zft_zfstring<T_Char> &Empty(void) {
666 static const zft_zfstring<T_Char> d;
667 return d;
668 }
669public:
685 ZF_IN const void *sLiteral
687 ) {
689 _ZFP_zfstringD<T_Char> *d = zfunsafe_zfpoolNew(_ZFP_zfstringD<T_Char>);
690 d->d.ptr = (const T_Char *)sLiteral;
691 d->length = (length != zfindexMax() ? (zfuint)length : (zfuint)_ZFP_zfstring_len((const T_Char *)sLiteral));
692 d->capacity = _ZFP_ST_Shared;
693 return zft_zfstring<T_Char>(d);
694 }
695
696 const zft_zfstring<T_Char> &sharedCopy(void) const {
697 if(this->isShared()) {
699 const T_Char *ptr = d->d.ptr;
700 {
701 zfindex capacity = d->length;
702 _capacityOptimize(capacity);
703 d->capacity = (zfuint)capacity;
704 }
705 d->d.buf = (T_Char *)zfunsafe_zfpoolMalloc(d->capacity);
706 zfmemcpy(d->d.buf, ptr, d->length);
707 d->d.buf[d->length] = '\0';
708 }
709 return *this;
710 }
711private:
712 explicit zft_zfstring(ZF_IN _ZFP_zfstringD<T_Char> *d)
713 : d(d)
714 {
715 }
716private:
717 static _ZFP_zfstringD<T_Char> *_ZFP_Empty(void) {
718 static _ZFP_zfstringH<T_Char> d;
719 return d.d;
720 }
721 static inline void _capacityOptimize(ZF_IN_OUT zfindex &capacity) {
723 }
724 // capacity: excluding tail '\0'
725 zfbool _capacityChange(ZF_IN zfindex capacity, zfbool keepContents) {
726 _capacityOptimize(capacity);
728 if(d->refCount == 1) {
729 if(d->capacity >= _ZFP_ST_Normal) {
730 T_Char *buf = (T_Char *)zfunsafe_zfpoolRealloc(d->d.buf, capacity * sizeof(T_Char));
731 if(buf == zfnull) {
732 return zffalse;
733 }
734 d->d.buf = buf;
735 }
736 else {
737 const T_Char *ptr = d->d.ptr;
738 T_Char *buf = (T_Char *)zfunsafe_zfpoolMalloc(capacity * sizeof(T_Char));
739 if(buf == zfnull) {
740 return zffalse;
741 }
742 d->d.buf = buf;
743 if(ptr && keepContents) {
744 zfmemcpy(d->d.buf, ptr, capacity * sizeof(T_Char));
745 }
746 else {
747 d->d.buf[0] = '\0';
748 }
749 }
750 }
751 else {
752 T_Char *buf = (T_Char *)zfunsafe_zfpoolMalloc(capacity * sizeof(T_Char));
753 if(buf == zfnull) {
754 return zffalse;
755 }
756 _ZFP_zfstringD<T_Char> *dTmp = d;
757 d = zfunsafe_zfpoolNew(_ZFP_zfstringD<T_Char>);
758 d->length = dTmp->length;
759 d->d.buf = buf;
760 if(dTmp->length > 0 && keepContents) {
761 zfmemcpy(d->d.buf, dTmp->d.ptr, dTmp->length * sizeof(T_Char));
762 d->d.buf[dTmp->length] = '\0';
763 }
764 else {
765 d->d.buf[0] = '\0';
766 }
767 }
768 d->capacity = (zfuint)capacity;
769 if(!keepContents) {
770 d->length = 0;
771 }
772 return zftrue;
773 }
774 inline void _prepareWrite(ZF_IN zfindex len) {
775 if(len >= d->capacity || d->refCount > 1) {
776 _capacityChange(len, zftrue);
777 }
778 }
779};
780
784#ifndef zftext
785 #define zftext(s, ...) zfstring::shared(s, ##__VA_ARGS__)
786#endif
787
789
790#endif // #ifndef _ZFI_zfstring_h_
791
core mutex
#define ZFCoreMutexLocker()
util method to lock current block
Definition ZFCoreMutex.h:95
types for ZFFramework
zfindex zfslen(const zfchar *s)
strlen wrapper as zfchar type
Definition ZFCoreTypeDef_CharType.h:144
_ZFT_t_zfchar zfchar
char wrapper
Definition ZFCoreTypeDef_CharType.h:17
types for ZFFramework
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:196
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:200
void * zfmemmove(void *dst, const void *src, zfindex size)
wrapper to memmove
Definition ZFCoreTypeDef_ClassType.h:158
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:204
#define zfclassNotPOD
shows the class is not a POD type, you should not memset it or declare it in stack or copy value by c...
Definition ZFCoreTypeDef_ClassType.h:48
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:212
void * zfmemcpy(void *dst, const void *src, zfindex size)
wrapper to memcpy
Definition ZFCoreTypeDef_ClassType.h:156
#define zfnullT
type for zfnull, can be used for function overload
Definition ZFCoreTypeDef_CoreType.h:85
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
_ZFT_t_zfint zfint
same as int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:165
#define zfindexMax()
(zfindex)-1, indicate a max index value, see zfindex
Definition ZFCoreTypeDef_CoreType.h:159
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
_ZFT_t_zfuint zfuint
same as unsigned int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:169
memory pool
#define zfunsafe_zfpoolNew(T_Type,...)
see zfnew
Definition ZFMemPool.h:44
#define zfpoolDelete(obj)
see zfnew
Definition ZFMemPool.h:81
#define zfunsafe_zfpoolRealloc(p, size)
see zfnew
Definition ZFMemPool.h:63
#define zfunsafe_zfpoolDelete(obj)
see zfnew
Definition ZFMemPool.h:45
#define zfunsafe_zfpoolMalloc(size)
see zfnew
Definition ZFMemPool.h:62
#define zfunsafe_zfpoolFree(p)
see zfnew
Definition ZFMemPool.h:64
#define zfpoolFree(p)
see zfnew
Definition ZFMemPool.h:100
#define zfpoolNew(T_Type,...)
see zfnew
Definition ZFMemPool.h:80
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
ZFUIMargin & operator+=(ZFUIMargin &v0, const ZFUIMargin &v1)
v0 += v1
Definition ZFUITypeDef.h:325
ZFUIMargin operator+(const ZFUIMargin &v0, const ZFUIMargin &v1)
v0 + v1
Definition ZFUITypeDef.h:310
low level string container
Definition zfstring.h:110
zfbool isShared(void) const
whether this string is created from shared
Definition zfstring.h:502
zft_zfstring< T_Char > & assign(const zft_zfstring< T_Char > &s, zfindex len)
replace all content of the string
Definition zfstring.h:362
zfint compare(const zft_zfstring< zfchar > &s) const
Definition zfstring.h:594
zft_zfstring(const zft_zfnullT &dummy)
construct empty string
Definition zfstring.h:183
zfbool capacity(zfindex capacity)
Definition zfstring.h:520
T_Char get(zfindex pos) const
get char at index
Definition zfstring.h:259
void remove(zfindex pos, zfindex len=((zfindex) -1))
remove part of the string
Definition zfstring.h:544
zft_zfstring< T_Char > & assign(const zft_zfstring< T_Char > &s, zfindex offset, zfindex len)
replace all content of the string
Definition zfstring.h:369
zft_zfstring< zfchar > & assign(const zft_zfstring< zfchar > &s)
Definition zfstring.h:357
const T_Char * cString(void) const
access string value, see shared
Definition zfstring.h:494
void swap(zft_zfstring< T_Char > &ref)
swap internal data without deep copy, designed for performance
Definition zfstring.h:275
zft_zfstring< T_Char > & append(const void *s, zfindex len=((zfindex) -1))
append string
Definition zfstring.h:331
void zfunsafe_bufferGiveUp(void *&ret, zfindex &length)
give up the buffer's ownership and return the buffer, you must free it manually by zfunsafe_bufferFre...
Definition zfstring.h:620
zft_zfstring< T_Char > & replace(zfindex replacePos, zfindex replaceLen, const void *s, zfindex len=((zfindex) -1))
replace string in range
Definition zfstring.h:459
zfint compare(const T_Char *s, zfindex len=((zfindex) -1)) const
compare with another string
Definition zfstring.h:598
zft_zfstring< T_Char > & append(const zft_zfstring< T_Char > &s)
append string
Definition zfstring.h:291
const zft_zfstring< T_Char > & sharedCopy(void) const
see shared
Definition zfstring.h:696
void zfunsafe_length(zfindex length)
directly modify the string's length
Definition zfstring.h:651
zft_zfstring(const T_Char *s, zfindex len)
copy content from another string
Definition zfstring.h:163
static void zfunsafe_bufferFree(void *buf)
free buffer returned by zfunsafe_bufferGiveUp
Definition zfstring.h:637
zft_zfstring(const T_Char *s)
copy content from another string
Definition zfstring.h:153
static const zft_zfstring< T_Char > & Empty(void)
global null string ref for impl
Definition zfstring.h:665
T_Char * zfunsafe_buffer(void)
directly access internal writable buffer
Definition zfstring.h:644
zft_zfstring(const zft_zfstring< T_Char > &s)
copy content from another string
Definition zfstring.h:120
zft_zfstring< T_Char > & insert(zfindex insertAt, const zft_zfstring< T_Char > &s)
insert string
Definition zfstring.h:418
void set(zfindex pos, T_Char c)
change char at index
Definition zfstring.h:249
zft_zfstring< T_Char > & append(const zft_zfstring< T_Char > &s, zfindex offset, zfindex len)
append string
Definition zfstring.h:314
zft_zfstring< T_Char > & assign(const zft_zfnullT &dummy)
replace all content of the string
Definition zfstring.h:411
zfbool isEqual(const zft_zfstring< T_Char > &ref) const
true if equal
Definition zfstring.h:510
zft_zfstring(const zft_zfstring< T_Char > &s, zfindex pos, zfindex len)
copy content from another string
Definition zfstring.h:140
zfindex length(void) const
length of the string
Definition zfstring.h:498
zfindex capacity(void) const
get current capacity (including tail '\0')
Definition zfstring.h:529
zft_zfstring< T_Char > & assign(const void *s, zfindex len=((zfindex) -1))
replace all content of the string
Definition zfstring.h:383
zft_zfstring< T_Char > & insert(zfindex insertAt, const void *s, zfindex len=((zfindex) -1))
insert string
Definition zfstring.h:425
void capacityTrim(void)
trim to a proper capacity to save memory
Definition zfstring.h:538
zft_zfstring(const T_Char *s, zfindex pos, zfindex len)
copy content from another string
Definition zfstring.h:173
void removeAll(void)
Definition zfstring.h:562
zft_zfstring< T_Char > & append(const zft_zfstring< T_Char > &s, zfindex len)
append string
Definition zfstring.h:303
const void * buffer(void) const
return internal buffer
Definition zfstring.h:612
zft_zfstring(const zft_zfstring< T_Char > &s, zfindex len)
copy content from another string
Definition zfstring.h:127
zfbool isEqual(const T_Char *s) const
true if equal
Definition zfstring.h:514
static zft_zfstring< T_Char > shared(const void *sLiteral, zfindex length=((zfindex) -1))
explicitly create from literal string
Definition zfstring.h:684
zfbool isEmpty(void) const
true if empty
Definition zfstring.h:506
zft_zfstring(void)
construct an empty string
Definition zfstring.h:113
zft_zfstring< T_Char > & replace(zfindex replacePos, zfindex replaceLen, const zft_zfstring< T_Char > &s)
replace string in range
Definition zfstring.h:451
zft_zfstring< T_Char > & append(T_Char c)
append string
Definition zfstring.h:284
void ZFCoreCapacityOptimize(zfindex &capacity)
util to optimize capacity
Definition zfstring.h:20