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
16// ============================================================
17template<typename T_Char>
18zfindex _ZFP_zfstring_len(ZF_IN const T_Char *s) {
19 const T_Char *p = s;
20 while(*p) {++p;}
21 return p - s;
22}
23inline zfindex _ZFP_zfstring_len(ZF_IN const zfchar *s) {
24 return zfslen(s);
25}
26template<typename T_Char>
27zfint _ZFP_zfstring_cmp(
28 ZF_IN const T_Char *s1
29 , ZF_IN const T_Char *s1End
30 , ZF_IN const T_Char *s2
31 , ZF_IN const T_Char *s2End
32 ) {
33 while(s1 < s1End && s2 < s2End && *s1 == *s2) {++s1, ++s2;}
34 if(s1 == s1End) {
35 if(s2 == s2End) {
36 return 0;
37 }
38 else {
39 return -1;
40 }
41 }
42 else {
43 if(s2 == s2End) {
44 return 1;
45 }
46 else {
47 return *s1 - *s2;
48 }
49 }
50}
51
52template<typename T_Char>
53zfclassNotPOD _ZFP_zfstringD {
54public:
55 zfuint refCount;
56 zfuint capacity; // capacity including tail '\0'
57 zfuint length;
58 union {
59 T_Char *buf; // capacity != 0
60 const T_Char *ptr; // capacity = 0
61 } d;
62public:
63 _ZFP_zfstringD(void) : refCount(1), capacity(0), length(0), d() {
64 d.ptr = Empty();
65 }
66 ~_ZFP_zfstringD(void) {
67 if(this->capacity) {
68 zfpoolFree(this->d.buf);
69 }
70 }
71public:
72 static const T_Char *Empty(void) {
73 static T_Char buf[1] = {0};
74 return buf;
75 }
76};
77template<typename T_Char>
78zfclassLikePOD _ZFP_zfstringH {
79public:
80 _ZFP_zfstringH(void) : d(zfpoolNew(_ZFP_zfstringD<T_Char>)) {}
81 ~_ZFP_zfstringH(void) {zfpoolDelete(d);}
82public:
83 _ZFP_zfstringD<T_Char> *d;
84};
85
86// ============================================================
90template<typename T_Char>
92public:
95 {
97 d = _ZFP_Empty();
98 ++(d->refCount);
99 }
100
102 {
104 d = s.d;
105 ++(d->refCount);
106 }
107
109 {
111 d = _ZFP_Empty();
112 ++(d->refCount);
113 this->assign(s.cString(), len);
114 }
115
117 {
119 d = _ZFP_Empty();
120 ++(d->refCount);
121 if(pos < s.length()) {
122 if(len > s.length() - pos) {
123 len = s.length() - pos;
124 }
125 this->assign(s.cString() + pos, len);
126 }
127 }
128
129 zft_zfstring(ZF_IN const T_Char *s)
130 {
132 d = _ZFP_Empty();
133 ++(d->refCount);
134 if(s) {
135 this->assign(s);
136 }
137 }
138
139 zft_zfstring(ZF_IN const T_Char *s, ZF_IN zfindex len)
140 {
142 d = _ZFP_Empty();
143 ++(d->refCount);
144 if(s) {
145 this->assign(s, len);
146 }
147 }
148
149 zft_zfstring(ZF_IN const T_Char *s, ZF_IN zfindex pos, ZF_IN zfindex len)
150 {
152 d = _ZFP_Empty();
153 ++(d->refCount);
154 if(s) {
155 this->assign(s + pos, len);
156 }
157 }
158
160 {
162 d = _ZFP_Empty();
163 ++(d->refCount);
164 }
165 ~zft_zfstring(void) {
167 if(--(d->refCount) == 0) {
168 zfpoolDelete(d);
169 }
170 }
171
172public:
174 inline operator const T_Char * (void) const {
175 return this->isEmpty() ? zfnull : this->cString();
176 }
177public:
178 inline zft_zfstring<T_Char> &operator = (ZF_IN const zft_zfstring<T_Char> &s) {
180 _ZFP_zfstringD<T_Char> *dTmp = d;
181 d = s.d;
182 ++(d->refCount);
183 if(--(dTmp->refCount) == 0) {
184 zfpoolDelete(dTmp);
185 }
186 return *this;
187 }
188 inline zft_zfstring<T_Char> &operator = (ZF_IN const T_Char *s) {return this->assign(s);}
189 inline zft_zfstring<T_Char> &operator = (ZF_IN zfnullT const &dummy) {return this->assign(dummy);}
190 zfbool operator == (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->isEqual(ref);}
191 zfbool operator != (ZF_IN const zft_zfstring<T_Char> &ref) const {return !this->isEqual(ref);}
192 zfbool operator == (ZF_IN const T_Char *ref) const {return this->isEqual(ref);}
193 zfbool operator != (ZF_IN const T_Char *ref) const {return !this->isEqual(ref);}
194 zfbool operator == (ZF_IN zfnullT const &dummy) const {return this->isEmpty();}
195 zfbool operator != (ZF_IN zfnullT const &dummy) const {return !this->isEmpty();}
196public:
197 /* ZFTAG_TRICKS: tricks to make zfstlmap<zfstring, xxx> works */
198 inline zfbool operator < (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->compare(ref) < 0;}
199 inline zfbool operator <= (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->compare(ref) <= 0;}
200 inline zfbool operator > (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->compare(ref) > 0;}
201 inline zfbool operator >= (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->compare(ref) >= 0;}
203
204public:
206 inline zft_zfstring<T_Char> &operator += (ZF_IN T_Char c) {return this->append(c);}
207 inline zft_zfstring<T_Char> &operator += (ZF_IN const zft_zfstring<T_Char> &s) {return this->append(s);}
208 inline zft_zfstring<T_Char> &operator += (ZF_IN const T_Char *s) {return this->append(s);}
209
210 template<typename T_Int>
211 inline const T_Char *operator + (ZF_IN T_Int const &offset) const {
212 return this->cString() + offset;
213 }
215
216public:
220 void set(
221 ZF_IN zfindex pos
222 , ZF_IN T_Char c
223 ) {
224 _prepareWrite(this->length());
225 d->d.buf[pos] = c;
226 }
227
230 inline T_Char get(ZF_IN zfindex pos) const {
231 return d->d.ptr[pos];
232 }
233
235 template<typename T_Int>
236 inline T_Char operator [] (ZF_IN T_Int pos) const {
237 return this->get(pos);
238 }
240
241public:
248 _ZFP_zfstringD<T_Char> *dTmp = d;
249 d = ref.d;
250 ref.d = dTmp;
251 }
252
253public:
256 _prepareWrite(d->length + 1);
257 d->d.buf[d->length] = c;
258 d->d.buf[++(d->length)] = '\0';
259 return *this;
260 }
261
263 if(s) {
264 _appendImpl(s.cString(), s.length());
265 }
266 return *this;
267 }
268
271 , ZF_IN zfindex len
272 ) {
273 len = (len <= s.length() ? len : s.length());
274 if(len > 0) {
275 _appendImpl(s.cString(), len);
276 }
277 return *this;
278 }
279
282 , ZF_IN zfindex offset
283 , ZF_IN zfindex len
284 ) {
285 if(offset > s.length()) {
286 offset = s.length();
287 }
288 if(len > s.length() - offset) {
289 len = s.length() - offset;
290 }
291 if(len > 0) {
292 _appendImpl(s.cString() + offset, len);
293 }
294 return *this;
295 }
296
298 ZF_IN const void *s
300 ) {
301 if(s) {
302 if(len == zfindexMax()) {
303 len = _ZFP_zfstring_len((const T_Char *)s);
304 }
305 if(len > 0) {
306 _appendImpl(s, len);
307 }
308 }
309 return *this;
310 }
311private:
312 void _appendImpl(
313 ZF_IN const void *s
314 , ZF_IN zfindex len
315 ) {
316 _prepareWrite(d->length + len);
317 zfmemcpy(d->d.buf + d->length, s, len * sizeof(T_Char));
318 d->d.buf[d->length += (zfuint)len] = '\0';
319 }
320
321public:
324 this->operator = (s);
325 return *this;
326 }
327
330 , ZF_IN zfindex len
331 ) {
332 return this->assign(s.cString(), len <= s.length() ? len : s.length());
333 }
334
337 , ZF_IN zfindex offset
338 , ZF_IN zfindex len
339 ) {
340 if(offset > s.length()) {
341 offset = s.length();
342 }
343 if(len > s.length() - offset) {
344 len = s.length() - offset;
345 }
346 return this->assign(s.cString() + offset, len);
347 }
348
350 ZF_IN const void *s
352 ) {
353 if(len == zfindexMax()) {
354 if(s) {
355 len = _ZFP_zfstring_len((const T_Char *)s);
356 }
357 else {
358 len = 0;
359 }
360 }
361 if(len > 0) {
362 if(len >= d->capacity || d->refCount > 1
363 || (d->capacity >= 128 && len < d->capacity / 3)
364 ) {
365 _capacityChange(len, zffalse);
366 }
367 d->length = (zfuint)len;
368 zfmemcpy(d->d.buf, s, len * sizeof(T_Char));
369 d->d.buf[len] = '\0';
370 }
371 else {
372 this->removeAll();
373 }
374 return *this;
375 }
376
377 inline zft_zfstring<T_Char> &assign(ZF_IN const zfnullT &dummy) {
378 this->removeAll();
379 return *this;
380 }
381
382public:
385 ZF_IN zfindex insertAt
386 , ZF_IN const zft_zfstring<T_Char> &s
387 ) {
388 return this->insert(insertAt, s.cString(), s.length());
389 }
390
392 ZF_IN zfindex insertAt
393 , ZF_IN const void *s
395 ) {
396 if(insertAt >= this->length()) {
397 this->append(s, len);
398 }
399 else if(s) {
400 if(len == zfindexMax()) {
401 len = _ZFP_zfstring_len((const T_Char *)s);
402 }
403 if(len > 0) {
404 zfindex lenTmp = this->length();
405 _prepareWrite(lenTmp + len);
406 d->length = (zfuint)(lenTmp + len);
407 zfmemmove(d->d.buf + insertAt + len, d->d.buf + insertAt, (lenTmp - insertAt) * sizeof(T_Char));
408 zfmemcpy(d->d.buf + insertAt, s, len * sizeof(T_Char));
409 d->d.buf[d->length] = '\0';
410 }
411 }
412 return *this;
413 }
414
415public:
418 ZF_IN zfindex replacePos
419 , ZF_IN zfindex replaceLen
420 , ZF_IN const zft_zfstring<T_Char> &s
421 ) {
422 return this->replace(replacePos, replaceLen, s.cString(), s.length());
423 }
424
426 ZF_IN zfindex replacePos
427 , ZF_IN zfindex replaceLen
428 , ZF_IN const void *s
430 ) {
431 if(replacePos >= this->length()) {
432 this->append(s, len);
433 }
434 else if(s) {
435 zfindex lenTmp = this->length();
436 if(replaceLen > lenTmp - replacePos) {
437 replaceLen = lenTmp - replacePos;
438 }
439 if(len == zfindexMax()) {
440 len = _ZFP_zfstring_len((const T_Char *)s);
441 }
442 if(len > replaceLen) {
443 _prepareWrite(lenTmp + len - replaceLen);
444 }
445 else {
446 _prepareWrite(lenTmp);
447 }
448 zfmemmove(d->d.buf + replacePos + len, d->d.buf + replacePos + replaceLen, (lenTmp - replacePos - replaceLen) * sizeof(T_Char));
449 zfmemcpy(d->d.buf + replacePos, s, len * sizeof(T_Char));
450 d->length = (zfuint)(lenTmp + len - replaceLen);
451 d->d.buf[d->length] = '\0';
452 }
453 return *this;
454 }
455
456public:
458 inline const T_Char *cString(void) const {
459 return d->d.ptr;
460 }
461
462 inline zfindex length(void) const {
463 return (zfindex)d->length;
464 }
465
466 inline zfbool isEmpty(void) const {
467 return d->length == 0;
468 }
469
470 inline zfbool isEqual(ZF_IN const zft_zfstring<T_Char> &ref) const {
471 return d == ref.d || (this->length() == ref.length() && this->compare(ref) == 0);
472 }
473
474 inline zfbool isEqual(ZF_IN const T_Char *s) const {
475 return 0 == _ZFP_zfstring_cmp(this->cString(), this->cString() + this->length(), s, s + (s ? _ZFP_zfstring_len(s) : 0));
476 }
477
478public:
481 if(capacity >= d->capacity) {
482 return _capacityChange(capacity - 1, zftrue);
483 }
484 else {
485 return zftrue;
486 }
487 }
488
489 inline zfindex capacity(void) const {
490 return (zfindex)d->capacity;
491 }
492
493 inline void capacityTrim(void) {
494 if(d->capacity >= 128 && d->length < d->capacity / 3) {
495 _capacityChange(this->length(), zftrue);
496 }
497 }
498
499 void remove(
500 ZF_IN zfindex pos
502 ) {
503 zfindex lenTmp = this->length();
504 if(pos < lenTmp) {
505 if(len > lenTmp - pos) {
506 len = lenTmp - pos;
507 }
508 if(len > 0) {
509 _prepareWrite(lenTmp);
510 zfmemmove(d->d.buf + pos, d->d.buf + pos + len, (lenTmp - pos - len) * sizeof(T_Char));
511 d->length -= (zfuint)len;
512 d->d.buf[d->length] = '\0';
513 }
514 }
515 }
516
517 void removeAll(void) {
518 if(!this->isEmpty()) {
520 if(d->refCount == 1) {
521 if(d->capacity >= 128) {
522 if(--(d->refCount) == 0) {
523 zfpoolDelete(d);
524 }
525 d = _ZFP_Empty();
526 ++(d->refCount);
527 }
528 else if(d->capacity > 0) {
529 d->d.buf[0] = '\0';
530 d->length = 0;
531 }
532 else {
533 d->d.ptr = _ZFP_zfstringD<T_Char>::Empty();
534 d->length = 0;
535 }
536 }
537 else {
538 if(--(d->refCount) == 0) {
539 zfpoolDelete(d);
540 }
541 d = _ZFP_Empty();
542 ++(d->refCount);
543 }
544 }
545 }
546
547public:
549 inline zfint compare(ZF_IN const zft_zfstring<T_Char> &s) const {
550 return d == s.d ? 0 : _ZFP_zfstring_cmp(this->cString(), this->cString() + this->length(), s.cString(), s.cString() + s.length());
551 }
552
554 ZF_IN const T_Char *s
555 , ZF_IN zfindex len = zfindexMax()
556 ) const {
557 if(len == zfindexMax()) {
558 len = s ? _ZFP_zfstring_len(s) : 0;
559 }
560 return _ZFP_zfstring_cmp(this->cString(), this->cString() + this->length(), s, s + (s ? _ZFP_zfstring_len(s) : 0));
561 }
562
563public:
567 const void *buffer(void) const {
568 return d->d.ptr;
569 }
570
577 _prepareWrite(this->length());
578 ret = (void *)d->d.buf;
579 length = d->length;
580
581 d->capacity = 0;
582 d->length = 0;
583 d->d.ptr = _ZFP_zfstringD<T_Char>::Empty();
584 zfpoolDelete(d);
585
586 d = _ZFP_Empty();
587 ++(d->refCount);
588 }
589
592 static void zfunsafe_bufferFree(ZF_IN void *buf) {
593 zfpoolFree(buf);
594 }
595
599 T_Char *zfunsafe_buffer(void) {
600 _prepareWrite(this->length());
601 return d->d.buf;
602 }
603
607 _prepareWrite(this->length());
608 d->length = (zfuint)length;
609 }
610
611private:
612 _ZFP_zfstringD<T_Char> *d;
613public:
615 static inline const zft_zfstring<T_Char> &Empty(void) {
616 static const zft_zfstring<T_Char> d;
617 return d;
618 }
619public:
625 ZF_IN const void *sLiteral
627 ) {
628 _ZFP_zfstringD<T_Char> *d = zfpoolNew(_ZFP_zfstringD<T_Char>);
629 d->d.ptr = (const T_Char *)sLiteral;
630 d->length = (zfuint)(length == zfindexMax() ? _ZFP_zfstring_len((const T_Char *)sLiteral) : length);
631 return zft_zfstring<T_Char>(d);
632 }
633private:
634 explicit zft_zfstring(ZF_IN _ZFP_zfstringD<T_Char> *d)
635 : d(d)
636 {
637 }
638private:
639 static _ZFP_zfstringD<T_Char> *_ZFP_Empty(void) {
640 static _ZFP_zfstringH<T_Char> d;
641 return d.d;
642 }
643 static inline void _capacityOptimize(ZF_IN_OUT zfindex &capacity) {
644 if(capacity < 32) {
645 capacity = ((capacity / 16) + 1) * 16;
646 }
647 else if(capacity < 64) {
648 capacity = ((capacity / 32) + 1) * 32;
649 }
650 else {
651 capacity >>= 4;
652 capacity |= capacity >> 1;
653 capacity |= capacity >> 2;
654 capacity |= capacity >> 4;
655 capacity |= capacity >> 8;
656 capacity |= capacity >> 16;
657 ++capacity;
658 capacity <<= 4;
659 }
660 }
661 // capacity: excluding tail '\0'
662 zfbool _capacityChange(ZF_IN zfindex capacity, zfbool keepContents) {
663 _capacityOptimize(capacity);
665 if(d->refCount == 1) {
666 if(d->capacity > 0) {
667 T_Char *buf = (T_Char *)zfpoolRealloc(d->d.buf, capacity * sizeof(T_Char));
668 if(buf == zfnull) {
669 return zffalse;
670 }
671 d->d.buf = buf;
672 }
673 else {
674 const T_Char *ptr = d->d.ptr;
675 T_Char *buf = (T_Char *)zfpoolMalloc(capacity * sizeof(T_Char));
676 if(buf == zfnull) {
677 return zffalse;
678 }
679 d->d.buf = buf;
680 if(ptr && keepContents) {
681 zfmemcpy(d->d.buf, ptr, capacity * sizeof(T_Char));
682 }
683 else {
684 d->d.buf[0] = '\0';
685 }
686 }
687 }
688 else {
689 T_Char *buf = (T_Char *)zfpoolMalloc(capacity * sizeof(T_Char));
690 if(buf == zfnull) {
691 return zffalse;
692 }
693 _ZFP_zfstringD<T_Char> *dTmp = d;
694 d = zfpoolNew(_ZFP_zfstringD<T_Char>);
695 d->length = dTmp->length;
696 d->d.buf = buf;
697 if(dTmp->length > 0 && keepContents) {
698 zfmemcpy(d->d.buf, dTmp->d.ptr, dTmp->length * sizeof(T_Char));
699 d->d.buf[dTmp->length] = '\0';
700 }
701 else {
702 d->d.buf[0] = '\0';
703 }
704 }
705 d->capacity = (zfuint)capacity;
706 if(!keepContents) {
707 d->length = 0;
708 }
709 return zftrue;
710 }
711 inline void _prepareWrite(ZF_IN zfindex len) {
712 if(len >= d->capacity || d->refCount > 1) {
713 _capacityChange(len, zftrue);
714 }
715 }
716};
717
721#ifndef zftext
722 #define zftext(s) zfstring::shared(s)
723#endif
724
726
727#endif // #ifndef _ZFI_zfstring_h_
728
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:191
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:195
void * zfmemmove(void *dst, const void *src, zfindex size)
wrapper to memmove
Definition ZFCoreTypeDef_ClassType.h:153
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:199
#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:207
void * zfmemcpy(void *dst, const void *src, zfindex size)
wrapper to memcpy
Definition ZFCoreTypeDef_ClassType.h:151
#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 zfpoolDelete(obj)
see zfpoolNew
Definition ZFMemPool.h:36
#define zfpoolRealloc(p, size)
see zfpoolMalloc
Definition ZFMemPool.h:57
#define zfpoolFree(p)
see zfpoolMalloc
Definition ZFMemPool.h:58
#define zfpoolNew(T_Type,...)
internal use only, for allocating internal types for performance
Definition ZFMemPool.h:35
#define zfpoolMalloc(size)
internal use only, for allocating internal types for performance
Definition ZFMemPool.h:56
#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:91
zft_zfstring< T_Char > & assign(const zft_zfstring< T_Char > &s, zfindex len)
replace all content of the string
Definition zfstring.h:328
zfint compare(const zft_zfstring< zfchar > &s) const
Definition zfstring.h:549
zft_zfstring(const zft_zfnullT &dummy)
construct empty string
Definition zfstring.h:159
zfbool capacity(zfindex capacity)
Definition zfstring.h:480
T_Char get(zfindex pos) const
get char at index
Definition zfstring.h:230
void remove(zfindex pos, zfindex len=((zfindex) -1))
remove part of the string
Definition zfstring.h:499
zft_zfstring< T_Char > & assign(const zft_zfstring< T_Char > &s, zfindex offset, zfindex len)
replace all content of the string
Definition zfstring.h:335
zft_zfstring< zfchar > & assign(const zft_zfstring< zfchar > &s)
Definition zfstring.h:323
const T_Char * cString(void) const
access string value
Definition zfstring.h:458
void swap(zft_zfstring< T_Char > &ref)
swap internal data without deep copy, designed for performance
Definition zfstring.h:246
zft_zfstring< T_Char > & append(const void *s, zfindex len=((zfindex) -1))
append string
Definition zfstring.h:297
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:575
zft_zfstring< T_Char > & replace(zfindex replacePos, zfindex replaceLen, const void *s, zfindex len=((zfindex) -1))
replace string in range
Definition zfstring.h:425
zfint compare(const T_Char *s, zfindex len=((zfindex) -1)) const
compare with another string
Definition zfstring.h:553
zft_zfstring< T_Char > & append(const zft_zfstring< T_Char > &s)
append string
Definition zfstring.h:262
void zfunsafe_length(zfindex length)
directly modify the string's length
Definition zfstring.h:606
zft_zfstring(const T_Char *s, zfindex len)
copy content from another string
Definition zfstring.h:139
static void zfunsafe_bufferFree(void *buf)
free buffer returned by zfunsafe_bufferGiveUp
Definition zfstring.h:592
zft_zfstring(const T_Char *s)
copy content from another string
Definition zfstring.h:129
static const zft_zfstring< T_Char > & Empty(void)
global null string ref for impl
Definition zfstring.h:615
T_Char * zfunsafe_buffer(void)
directly access internal writable buffer
Definition zfstring.h:599
zft_zfstring(const zft_zfstring< T_Char > &s)
copy content from another string
Definition zfstring.h:101
zft_zfstring< T_Char > & insert(zfindex insertAt, const zft_zfstring< T_Char > &s)
insert string
Definition zfstring.h:384
void set(zfindex pos, T_Char c)
change char at index
Definition zfstring.h:220
zft_zfstring< T_Char > & append(const zft_zfstring< T_Char > &s, zfindex offset, zfindex len)
append string
Definition zfstring.h:280
zft_zfstring< T_Char > & assign(const zft_zfnullT &dummy)
replace all content of the string
Definition zfstring.h:377
zfbool isEqual(const zft_zfstring< T_Char > &ref) const
true if equal
Definition zfstring.h:470
zft_zfstring(const zft_zfstring< T_Char > &s, zfindex pos, zfindex len)
copy content from another string
Definition zfstring.h:116
zfindex length(void) const
length of the string
Definition zfstring.h:462
zfindex capacity(void) const
get current capacity (including tail '\0')
Definition zfstring.h:489
zft_zfstring< T_Char > & assign(const void *s, zfindex len=((zfindex) -1))
replace all content of the string
Definition zfstring.h:349
zft_zfstring< T_Char > & insert(zfindex insertAt, const void *s, zfindex len=((zfindex) -1))
insert string
Definition zfstring.h:391
void capacityTrim(void)
trim to a proper capacity to save memory
Definition zfstring.h:493
zft_zfstring(const T_Char *s, zfindex pos, zfindex len)
copy content from another string
Definition zfstring.h:149
void removeAll(void)
Definition zfstring.h:517
zft_zfstring< T_Char > & append(const zft_zfstring< T_Char > &s, zfindex len)
append string
Definition zfstring.h:269
const void * buffer(void) const
return internal buffer
Definition zfstring.h:567
zft_zfstring(const zft_zfstring< T_Char > &s, zfindex len)
copy content from another string
Definition zfstring.h:108
zfbool isEqual(const T_Char *s) const
true if equal
Definition zfstring.h:474
static zft_zfstring< T_Char > shared(const void *sLiteral, zfindex length=((zfindex) -1))
explicitly create from literal string, you must ensure the literal's life exceeds the returned string
Definition zfstring.h:624
zfbool isEmpty(void) const
true if empty
Definition zfstring.h:466
zft_zfstring(void)
construct an empty string
Definition zfstring.h:94
zft_zfstring< T_Char > & replace(zfindex replacePos, zfindex replaceLen, const zft_zfstring< T_Char > &s)
replace string in range
Definition zfstring.h:417
zft_zfstring< T_Char > & append(T_Char c)
append string
Definition zfstring.h:255