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}
23template<typename T_Char>
24zfint _ZFP_zfstring_cmp(
25 ZF_IN const T_Char *s1
26 , ZF_IN const T_Char *s2
27 ) {
28 while(*s1 && *s2 && *s1 == *s2) {++s1, ++s2;}
29 return *s1 - *s2;
30}
31template<typename T_Char>
32zfint _ZFP_zfstring_ncmp(
33 ZF_IN const T_Char *s1
34 , ZF_IN const T_Char *s2
35 , ZF_IN zfindex len
36 ) {
37 while(--len && *s1 && *s2 && *s1 == *s2) {++s1, ++s2;}
38 return *s1 - *s2;
39}
40
41// ============================================================
42inline zfindex _ZFP_zfstring_len(ZF_IN const zfchar *s) {
43 return zfslen(s);
44}
45inline zfint _ZFP_zfstring_cmp(
46 ZF_IN const zfchar *s1
47 , ZF_IN const zfchar *s2
48 ) {
49 return zfscmp(s1, s2);
50}
51inline zfint _ZFP_zfstring_ncmp(
52 ZF_IN const zfchar *s1
53 , ZF_IN const zfchar *s2
54 , ZF_IN zfindex len
55 ) {
56 return zfsncmp(s1, s2, len);
57}
58
59template<typename T_Char>
60zfclassNotPOD _ZFP_zfstringD {
61public:
62 zfuint refCount;
63 zfuint capacity; // capacity including tail '\0'
64 zfuint length;
65 union {
66 T_Char *buf; // capacity != 0
67 const T_Char *ptr; // capacity = 0
68 } d;
69public:
70 _ZFP_zfstringD(void) : refCount(1), capacity(0), length(0), d() {
71 static T_Char buf[1] = {0};
72 d.ptr = buf;
73 }
74};
75template<typename T_Char>
76zfclassLikePOD _ZFP_zfstringH {
77public:
78 _ZFP_zfstringH(void) : d(zfpoolNew(_ZFP_zfstringD<T_Char>)) {}
79 ~_ZFP_zfstringH(void) {zfpoolDelete(d);}
80public:
81 _ZFP_zfstringD<T_Char> *d;
82};
83
84// ============================================================
88template<typename T_Char>
90public:
93 {
95 d = _ZFP_Empty();
96 ++(d->refCount);
97 }
98
100 {
102 d = s.d;
103 ++(d->refCount);
104 }
105
107 {
109 d = _ZFP_Empty();
110 ++(d->refCount);
111 this->assign(s.cString(), len);
112 }
113
115 {
117 d = _ZFP_Empty();
118 ++(d->refCount);
119 if(pos < s.length()) {
120 if(len > s.length() - pos) {
121 len = s.length() - pos;
122 }
123 this->assign(s.cString() + pos, len);
124 }
125 }
126
127 zft_zfstring(ZF_IN const T_Char *s)
128 {
130 d = _ZFP_Empty();
131 ++(d->refCount);
132 if(s) {
133 this->assign(s);
134 }
135 }
136
137 zft_zfstring(ZF_IN const T_Char *s, ZF_IN zfindex len)
138 {
140 d = _ZFP_Empty();
141 ++(d->refCount);
142 if(s) {
143 this->assign(s, len);
144 }
145 }
146
147 zft_zfstring(ZF_IN const T_Char *s, ZF_IN zfindex pos, ZF_IN zfindex len)
148 {
150 d = _ZFP_Empty();
151 ++(d->refCount);
152 if(s) {
153 this->assign(s + pos, len);
154 }
155 }
156
158 {
160 d = _ZFP_Empty();
161 ++(d->refCount);
162 }
163 ~zft_zfstring(void) {
165 if(d->refCount == 1) {
166 if(d->capacity) {
167 zffree(d->d.buf);
168 }
169 zfpoolDelete(d);
170 }
171 else {
172 --(d->refCount);
173 }
174 }
175
176public:
178 inline operator const T_Char * (void) const {
179 return this->isEmpty() ? zfnull : this->cString();
180 }
181public:
182 inline zft_zfstring<T_Char> &operator = (ZF_IN const zft_zfstring<T_Char> &s) {
184 _ZFP_zfstringD<T_Char> *dTmp = d;
185 d = s.d;
186 ++(d->refCount);
187 if(dTmp->refCount == 1) {
188 if(dTmp->capacity) {
189 zffree(dTmp->d.buf);
190 }
191 zfpoolDelete(dTmp);
192 }
193 else {
194 --(dTmp->refCount);
195 }
196 return *this;
197 }
198 inline zft_zfstring<T_Char> &operator = (ZF_IN const T_Char *s) {return this->assign(s);}
199 inline zft_zfstring<T_Char> &operator = (ZF_IN zfnullT const &dummy) {return this->assign(dummy);}
200 zfbool operator == (ZF_IN const zft_zfstring<T_Char> &ref) const {return (this->compare(ref) == 0);}
201 zfbool operator != (ZF_IN const zft_zfstring<T_Char> &ref) const {return (this->compare(ref) != 0);}
202 zfbool operator == (ZF_IN const T_Char *ref) const {return (this->compare(ref) == 0);}
203 zfbool operator != (ZF_IN const T_Char *ref) const {return (this->compare(ref) != 0);}
204 zfbool operator == (ZF_IN zfnullT const &dummy) const {return this->isEmpty();}
205 zfbool operator != (ZF_IN zfnullT const &dummy) const {return !this->isEmpty();}
206public:
207 /* ZFTAG_TRICKS: tricks to make ZFMap<zfstring, xxx> works */
208 inline zfbool operator < (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->compare(ref) < 0;}
209 inline zfbool operator <= (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->compare(ref) <= 0;}
210 inline zfbool operator > (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->compare(ref) > 0;}
211 inline zfbool operator >= (ZF_IN const zft_zfstring<T_Char> &ref) const {return this->compare(ref) >= 0;}
213
214public:
216 inline zft_zfstring<T_Char> &operator += (ZF_IN T_Char c) {return this->append(c);}
217 inline zft_zfstring<T_Char> &operator += (ZF_IN const zft_zfstring<T_Char> &s) {return this->append(s);}
218 inline zft_zfstring<T_Char> &operator += (ZF_IN const T_Char *s) {return this->append(s);}
219
220 template<typename T_Int>
221 inline const T_Char *operator + (ZF_IN T_Int const &offset) const {
222 return this->cString() + offset;
223 }
225
226public:
230 void set(
231 ZF_IN zfindex pos
232 , ZF_IN T_Char c
233 ) {
234 _prepareWrite(this->length());
235 d->d.buf[pos] = c;
236 }
237
240 inline T_Char get(ZF_IN zfindex pos) const {
241 return d->d.ptr[pos];
242 }
243
245 template<typename T_Int>
246 inline T_Char operator [] (ZF_IN T_Int pos) const {
247 return this->get(pos);
248 }
250
251public:
258 _ZFP_zfstringD<T_Char> *dTmp = d;
259 d = ref.d;
260 ref.d = dTmp;
261 }
262
263public:
266 _prepareWrite(d->length + 1);
267 d->d.buf[d->length] = c;
268 d->d.buf[++(d->length)] = '\0';
269 return *this;
270 }
271
273 if(s) {
274 _appendImpl(s.cString(), s.length());
275 }
276 return *this;
277 }
278
281 , ZF_IN zfindex len
282 ) {
283 len = (len <= s.length() ? len : s.length());
284 if(len > 0) {
285 _appendImpl(s.cString(), len);
286 }
287 return *this;
288 }
289
292 , ZF_IN zfindex offset
293 , ZF_IN zfindex len
294 ) {
295 if(offset > s.length()) {
296 offset = s.length();
297 }
298 if(len > s.length() - offset) {
299 len = s.length() - offset;
300 }
301 if(len > 0) {
302 _appendImpl(s.cString() + offset, len);
303 }
304 return *this;
305 }
306
308 ZF_IN const void *s
310 ) {
311 if(s) {
312 if(len == zfindexMax()) {
313 len = _ZFP_zfstring_len((const T_Char *)s);
314 }
315 if(len > 0) {
316 _appendImpl(s, len);
317 }
318 }
319 return *this;
320 }
321private:
322 void _appendImpl(
323 ZF_IN const void *s
324 , ZF_IN zfindex len
325 ) {
326 _prepareWrite(d->length + len);
327 zfmemcpy(d->d.buf + d->length, s, len * sizeof(T_Char));
328 d->d.buf[d->length += (zfuint)len] = '\0';
329 }
330
331public:
334 this->operator = (s);
335 return *this;
336 }
337
340 , ZF_IN zfindex len
341 ) {
342 return this->assign(s.cString(), len <= s.length() ? len : s.length());
343 }
344
347 , ZF_IN zfindex offset
348 , ZF_IN zfindex len
349 ) {
350 if(offset > s.length()) {
351 offset = s.length();
352 }
353 if(len > s.length() - offset) {
354 len = s.length() - offset;
355 }
356 return this->assign(s.cString() + offset, len);
357 }
358
360 ZF_IN const void *s
362 ) {
363 if(len == zfindexMax()) {
364 if(s) {
365 len = _ZFP_zfstring_len((const T_Char *)s);
366 }
367 else {
368 len = 0;
369 }
370 }
371 if(len > 0) {
372 _capacityChange(len, zffalse);
373 d->length = (zfuint)len;
374 zfmemcpy(d->d.buf, s, len * sizeof(T_Char));
375 d->d.buf[len] = '\0';
376 }
377 else {
378 this->removeAll();
379 }
380 return *this;
381 }
382
383 inline zft_zfstring<T_Char> &assign(ZF_IN const zfnullT &dummy) {
384 this->removeAll();
385 return *this;
386 }
387
388public:
391 ZF_IN zfindex insertAt
392 , ZF_IN const zft_zfstring<T_Char> &s
393 ) {
394 return this->insert(insertAt, s.cString(), s.length());
395 }
396
398 ZF_IN zfindex insertAt
399 , ZF_IN const void *s
401 ) {
402 if(insertAt >= this->length()) {
403 this->append(s, len);
404 }
405 else if(s) {
406 if(len == zfindexMax()) {
407 len = _ZFP_zfstring_len((const T_Char *)s);
408 }
409 if(len > 0) {
410 zfindex lenTmp = this->length();
411 _prepareWrite(lenTmp + len);
412 d->length = (zfuint)(lenTmp + len);
413 zfmemmove(d->d.buf + insertAt + len, d->d.buf + insertAt, (lenTmp - insertAt) * sizeof(T_Char));
414 zfmemcpy(d->d.buf + insertAt, s, len * sizeof(T_Char));
415 d->d.buf[d->length] = '\0';
416 }
417 }
418 return *this;
419 }
420
421public:
424 ZF_IN zfindex replacePos
425 , ZF_IN zfindex replaceLen
426 , ZF_IN const zft_zfstring<T_Char> &s
427 ) {
428 return this->replace(replacePos, replaceLen, s.cString(), s.length());
429 }
430
432 ZF_IN zfindex replacePos
433 , ZF_IN zfindex replaceLen
434 , ZF_IN const void *s
436 ) {
437 if(replacePos >= this->length()) {
438 this->append(s, len);
439 }
440 else if(s) {
441 zfindex lenTmp = this->length();
442 if(replaceLen > lenTmp - replacePos) {
443 replaceLen = lenTmp - replacePos;
444 }
445 if(len == zfindexMax()) {
446 len = _ZFP_zfstring_len((const T_Char *)s);
447 }
448 if(len > replaceLen) {
449 _prepareWrite(lenTmp + len - replaceLen);
450 }
451 else {
452 _prepareWrite(lenTmp);
453 }
454 zfmemmove(d->d.buf + replacePos + len, d->d.buf + replacePos + replaceLen, (lenTmp - replacePos - replaceLen) * sizeof(T_Char));
455 zfmemcpy(d->d.buf + replacePos, s, len * sizeof(T_Char));
456 d->length = (zfuint)(lenTmp + len - replaceLen);
457 d->d.buf[d->length] = '\0';
458 }
459 return *this;
460 }
461
462public:
464 inline const T_Char *cString(void) const {
465 return d->d.ptr;
466 }
467
468 inline zfindex length(void) const {
469 return (zfindex)d->length;
470 }
471
472 inline zfbool isEmpty(void) const {
473 return d->length == 0;
474 }
475
476public:
479 if(capacity >= d->capacity) {
480 _capacityChange(capacity - 1, zftrue);
481 }
482 }
483
484 inline zfindex capacity(void) const {
485 return (zfindex)d->capacity;
486 }
487
488 inline void capacityTrim(void) {
489 if(d->capacity >= 128 && d->length <= 32) {
490 _capacityChange(this->length(), zftrue);
491 }
492 }
493
494 void remove(
495 ZF_IN zfindex pos
497 ) {
498 zfindex lenTmp = this->length();
499 if(pos < lenTmp) {
500 if(len > lenTmp - pos) {
501 len = lenTmp - pos;
502 }
503 if(len > 0) {
504 _prepareWrite(lenTmp);
505 zfmemmove(d->d.buf + pos, d->d.buf + pos + len, (lenTmp - pos - len) * sizeof(T_Char));
506 d->length -= (zfuint)len;
507 d->d.buf[d->length] = '\0';
508 }
509 }
510 }
511
512 inline void removeAll(void) {
513 if(!this->isEmpty()) {
515 if(d->refCount == 1) {
516 if(d->capacity > 0) {
517 d->d.buf[0] = '\0';
518 d->length = 0;
519 }
520 else {
521 d->d.ptr = zfnull;
522 d->length = 0;
523 }
524 }
525 else {
526 --(d->refCount);
527 d = _ZFP_Empty();
528 ++(d->refCount);
529 }
530 }
531 }
532
533public:
535 inline zfint compare(ZF_IN const zft_zfstring<T_Char> &s) const {
536 return d == s.d ? 0 : _ZFP_zfstring_cmp(this->cString(), s.cString());
537 }
538
540 ZF_IN const T_Char *s
541 , ZF_IN zfindex len = zfindexMax()
542 ) const {
543 if(len == zfindexMax()) {
544 len = s ? _ZFP_zfstring_len(s) : 0;
545 }
546 if(this->length() < len) {
547 return -1;
548 }
549 else if(this->length() > len) {
550 return 1;
551 }
552 else {
553 return _ZFP_zfstring_ncmp(this->cString(), s, len);
554 }
555 }
556
557public:
561 const void *buffer(void) const {
562 return d->d.ptr;
563 }
564
571 _prepareWrite(this->length());
572 T_Char *ret = d->d.buf;
573 zfpoolDelete(d);
574 d = _ZFP_Empty();
575 ++(d->refCount);
576 return ret;
577 }
578
581 static void zfunsafe_bufferFree(ZF_IN void *buf) {
582 zffree(buf);
583 }
584
588 T_Char *zfunsafe_buffer(void) {
589 _prepareWrite(this->length());
590 return d->d.buf;
591 }
592
596 _prepareWrite(this->length());
597 d->length = (zfuint)length;
598 }
599
600private:
601 _ZFP_zfstringD<T_Char> *d;
602public:
604 static inline const zft_zfstring<T_Char> &Empty(void) {
605 static const zft_zfstring<T_Char> d;
606 return d;
607 }
608public:
614 ZF_IN const void *sLiteral
616 ) {
617 _ZFP_zfstringD<T_Char> *d = zfpoolNew(_ZFP_zfstringD<T_Char>);
618 d->d.ptr = (const T_Char *)sLiteral;
619 d->length = (zfuint)(length == zfindexMax() ? _ZFP_zfstring_len((const T_Char *)sLiteral) : length);
620 return zft_zfstring<T_Char>(d);
621 }
622private:
623 explicit zft_zfstring(ZF_IN _ZFP_zfstringD<T_Char> *d)
624 : d(d)
625 {
626 }
627private:
628 static _ZFP_zfstringD<T_Char> *_ZFP_Empty(void) {
629 static _ZFP_zfstringH<T_Char> d;
630 return d.d;
631 }
632 static inline void _capacityOptimize(ZF_IN_OUT zfindex &capacity) {
633 if(capacity < 32) {
634 capacity = ((capacity / 16) + 1) * 16;
635 }
636 else if(capacity < 64) {
637 capacity = ((capacity / 32) + 1) * 32;
638 }
639 else if(capacity < 1024) {
640 capacity = ((capacity / 128) + 1) * 128;
641 }
642 else {
643 capacity = ((capacity / 1024) + 1) * 1024;
644 }
645 }
646 // capacity: excluding tail '\0'
647 void _capacityChange(ZF_IN zfindex capacity, zfbool keepContents) {
648 _capacityOptimize(capacity);
650 if(d->refCount == 1) {
651 if(d->capacity > 0) {
652 d->d.buf = (T_Char *)zfrealloc(d->d.buf, capacity * sizeof(T_Char));
653 }
654 else {
655 const T_Char *ptr = d->d.ptr;
656 d->d.buf = (T_Char *)zfmalloc(capacity * sizeof(T_Char));
657 if(ptr && keepContents) {
658 zfmemcpy(d->d.buf, ptr, capacity * sizeof(T_Char));
659 }
660 else {
661 d->d.buf[0] = '\0';
662 }
663 }
664 }
665 else {
666 _ZFP_zfstringD<T_Char> *dTmp = d;
667 d = zfpoolNew(_ZFP_zfstringD<T_Char>);
668 d->length = dTmp->length;
669 d->d.buf = (T_Char *)zfmalloc(capacity * sizeof(T_Char));
670 if(dTmp->length > 0 && keepContents) {
671 zfmemcpy(d->d.buf, dTmp->d.ptr, dTmp->length * sizeof(T_Char));
672 d->d.buf[dTmp->length] = '\0';
673 }
674 else {
675 d->d.buf[0] = '\0';
676 }
677 }
678 d->capacity = (zfuint)capacity;
679 if(!keepContents) {
680 d->length = 0;
681 }
682 }
683 inline void _prepareWrite(ZF_IN zfindex capacity) {
684 if(capacity >= d->capacity || d->refCount > 1) {
685 _capacityChange(capacity, zftrue);
686 }
687 }
688};
689
693#ifndef zftext
694 #define zftext(s) zfstring::shared(s)
695#endif
696
698
699#endif // #ifndef _ZFI_zfstring_h_
700
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
zfint zfsncmp(const zfchar *s1, const zfchar *s2, zfindex count)
strncmp wrapper as zfchar type
Definition ZFCoreTypeDef_CharType.h:158
zfint zfscmp(const zfchar *s1, const zfchar *s2)
strcmp wrapper as zfchar type
Definition ZFCoreTypeDef_CharType.h:152
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 zffree(ptr)
same as free defined for future use, do nothing if ptr is NULL
Definition ZFCoreTypeDef_ClassType.h:112
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
void * zfmemmove(void *dst, const void *src, zfindex size)
wrapper to memmove
Definition ZFCoreTypeDef_ClassType.h:142
#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:196
#define zfrealloc(oldPtr, newSize)
same as realloc defined for future use
Definition ZFCoreTypeDef_ClassType.h:106
void * zfmemcpy(void *dst, const void *src, zfindex size)
wrapper to memcpy
Definition ZFCoreTypeDef_ClassType.h:140
#define zfmalloc(size)
same as malloc defined for future use
Definition ZFCoreTypeDef_ClassType.h:100
#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:38
#define zfpoolNew(T_Type,...)
internal use only, for allocating internal types for performance
Definition ZFMemPool.h:37
#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:89
void * zfunsafe_bufferGiveUp(void)
give up the buffer's ownership and return the buffer, you must free it manually by zfunsafe_bufferFre...
Definition zfstring.h:569
zft_zfstring< T_Char > & assign(const zft_zfstring< T_Char > &s, zfindex len)
replace all content of the string
Definition zfstring.h:338
zfint compare(const zft_zfstring< T_Char > &s) const
compare with another string
Definition zfstring.h:535
zft_zfstring(const zft_zfnullT &dummy)
construct empty string
Definition zfstring.h:157
T_Char get(zfindex pos) const
get char at index
Definition zfstring.h:240
void remove(zfindex pos, zfindex len=((zfindex) -1))
remove part of the string
Definition zfstring.h:494
zft_zfstring< T_Char > & assign(const zft_zfstring< T_Char > &s, zfindex offset, zfindex len)
replace all content of the string
Definition zfstring.h:345
zft_zfstring< zfchar > & assign(const zft_zfstring< zfchar > &s)
Definition zfstring.h:333
const T_Char * cString(void) const
access string value
Definition zfstring.h:464
void swap(zft_zfstring< T_Char > &ref)
swap internal data without deep copy, designed for performance
Definition zfstring.h:256
zft_zfstring< T_Char > & append(const void *s, zfindex len=((zfindex) -1))
append string
Definition zfstring.h:307
zft_zfstring< T_Char > & replace(zfindex replacePos, zfindex replaceLen, const void *s, zfindex len=((zfindex) -1))
replace string in range
Definition zfstring.h:431
zfint compare(const T_Char *s, zfindex len=((zfindex) -1)) const
compare with another string
Definition zfstring.h:539
zft_zfstring< T_Char > & append(const zft_zfstring< T_Char > &s)
append string
Definition zfstring.h:272
void zfunsafe_length(zfindex length)
directly modify the string's length
Definition zfstring.h:595
zft_zfstring(const T_Char *s, zfindex len)
copy content from another string
Definition zfstring.h:137
static void zfunsafe_bufferFree(void *buf)
free buffer returned by zfunsafe_bufferGiveUp
Definition zfstring.h:581
zft_zfstring(const T_Char *s)
copy content from another string
Definition zfstring.h:127
static const zft_zfstring< T_Char > & Empty(void)
global null string ref for impl
Definition zfstring.h:604
T_Char * zfunsafe_buffer(void)
directly access internal writable buffer
Definition zfstring.h:588
zft_zfstring(const zft_zfstring< T_Char > &s)
copy content from another string
Definition zfstring.h:99
zft_zfstring< T_Char > & insert(zfindex insertAt, const zft_zfstring< T_Char > &s)
insert string
Definition zfstring.h:390
void set(zfindex pos, T_Char c)
change char at index
Definition zfstring.h:230
zft_zfstring< T_Char > & append(const zft_zfstring< T_Char > &s, zfindex offset, zfindex len)
append string
Definition zfstring.h:290
zft_zfstring< T_Char > & assign(const zft_zfnullT &dummy)
replace all content of the string
Definition zfstring.h:383
zft_zfstring(const zft_zfstring< T_Char > &s, zfindex pos, zfindex len)
copy content from another string
Definition zfstring.h:114
zfindex length(void) const
Definition zfstring.h:468
zfindex capacity(void) const
get current capacity (including tail '\0')
Definition zfstring.h:484
zft_zfstring< T_Char > & assign(const void *s, zfindex len=((zfindex) -1))
replace all content of the string
Definition zfstring.h:359
zft_zfstring< T_Char > & insert(zfindex insertAt, const void *s, zfindex len=((zfindex) -1))
insert string
Definition zfstring.h:397
void capacity(zfindex capacity)
ensure the string's capacity (including tail '\0'), note the result capacity is not ensured same as r...
Definition zfstring.h:478
void capacityTrim(void)
trim to a proper capacity to save memory
Definition zfstring.h:488
zft_zfstring(const T_Char *s, zfindex pos, zfindex len)
copy content from another string
Definition zfstring.h:147
void removeAll(void)
Definition zfstring.h:512
zft_zfstring< T_Char > & append(const zft_zfstring< T_Char > &s, zfindex len)
append string
Definition zfstring.h:279
const void * buffer(void) const
return internal buffer
Definition zfstring.h:561
zft_zfstring(const zft_zfstring< T_Char > &s, zfindex len)
copy content from another string
Definition zfstring.h:106
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:613
zfbool isEmpty(void) const
true if empty
Definition zfstring.h:472
zft_zfstring(void)
construct an empty string
Definition zfstring.h:92
zft_zfstring< T_Char > & replace(zfindex replacePos, zfindex replaceLen, const zft_zfstring< T_Char > &s)
replace string in range
Definition zfstring.h:423
zft_zfstring< T_Char > & append(T_Char c)
append string
Definition zfstring.h:265