Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXString.h
1 /********************************************************************************
2 * *
3 * S t r i n g O b j e c t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2024 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXSTRING_H
22 #define FXSTRING_H
23 
24 namespace FX {
25 
26 
27 class FXStream;
28 
29 
42 class FXAPI FXString {
43 private:
44  FXchar* str;
45 public:
46  static const FXchar null[];
47 public:
48 
50  FXString();
51 
53  FXString(const FXString& s);
54 
56  FXString(const FXchar* s);
57 
59  FXString(const FXnchar* s);
60 
62  FXString(const FXwchar* s);
63 
65  FXString(const FXchar* s,FXint n);
66 
68  FXString(const FXnchar* s,FXint n);
69 
71  FXString(const FXwchar* s,FXint n);
72 
74  FXString(FXchar c,FXint n);
75 
77  FXint length() const { return *(((FXint*)str)-1); }
78 
80  FXbool length(FXint len);
81 
83  FXwchar wc(FXint p) const;
84 
86  FXwchar wcnxt(FXint& p) const;
87 
89  FXwchar wcprv(FXint& p) const;
90 
92  FXint inc(FXint p) const;
93 
95  FXint inc(FXint p,FXint n) const;
96 
98  FXint dec(FXint p) const;
99 
101  FXint dec(FXint p,FXint n) const;
102 
104  FXint count() const;
105 
107  FXint count(FXint start,FXint end) const;
108 
110  FXint offset(FXint indx) const;
111 
113  FXint index(FXint offs) const;
114 
116  FXint validate(FXint p) const;
117 
119  FXchar* text(){ return str; }
120 
122  const FXchar* text() const { return str; }
123 
125  FXbool empty() const { return (((FXint*)str)[-1]==0); }
126 
128  FXbool operator!() const { return (((FXint*)str)[-1]==0); }
129 
131  FXchar& operator[](FXint i){ return str[i]; }
132 
134  const FXchar& operator[](FXint i) const { return str[i]; }
135 
137  FXchar& at(FXint i){ return str[i]; }
138 
140  const FXchar& at(FXint i) const { return str[i]; }
141 
143  FXchar& head(){ return str[0]; }
144 
146  const FXchar& head() const { return str[0]; }
147 
149  FXchar& tail(){ return str[length()-1]; }
150 
152  const FXchar& tail() const { return str[length()-1]; }
153 
155  FXString& operator=(const FXchar* s);
156 
158  FXString& operator=(const FXnchar* s);
159 
161  FXString& operator=(const FXwchar* s);
162 
164  FXString& operator=(const FXString& s);
165 
167  FXString& operator+=(FXchar c);
168 
170  FXString& operator+=(const FXchar* s);
171 
173  FXString& operator+=(const FXnchar* s);
174 
176  FXString& operator+=(const FXwchar* s);
177 
179  FXString& operator+=(const FXString& s);
180 
182  FXString& adopt(FXString& s);
183 
185  FXString& assign(FXchar c);
186 
188  FXString& assign(FXchar c,FXint n);
189 
191  FXString& assign(const FXchar* s);
192 
194  FXString& assign(const FXnchar* s);
195 
197  FXString& assign(const FXwchar* s);
198 
200  FXString& assign(const FXchar *s,FXint n);
201 
203  FXString& assign(const FXnchar *s,FXint n);
204 
206  FXString& assign(const FXwchar *s,FXint n);
207 
209  FXString& assign(const FXString& s);
210 
212  FXString& insert(FXint pos,FXchar c);
213 
215  FXString& insert(FXint pos,FXchar c,FXint n);
216 
218  FXString& insert(FXint pos,const FXchar* s);
219 
221  FXString& insert(FXint pos,const FXnchar* s);
222 
224  FXString& insert(FXint pos,const FXwchar* s);
225 
227  FXString& insert(FXint pos,const FXchar* s,FXint n);
228 
230  FXString& insert(FXint pos,const FXnchar* s,FXint n);
231 
233  FXString& insert(FXint pos,const FXwchar* s,FXint n);
234 
236  FXString& insert(FXint pos,const FXString& s);
237 
239  FXString& prepend(FXchar c);
240 
242  FXString& prepend(FXchar c,FXint n);
243 
245  FXString& prepend(const FXchar* s);
246 
248  FXString& prepend(const FXnchar* s);
249 
251  FXString& prepend(const FXwchar* s);
252 
254  FXString& prepend(const FXchar* s,FXint n);
255 
257  FXString& prepend(const FXnchar* s,FXint n);
258 
260  FXString& prepend(const FXwchar* s,FXint n);
261 
263  FXString& prepend(const FXString& s);
264 
266  FXString& append(FXchar c);
267 
269  FXString& append(FXchar c,FXint n);
270 
272  FXString& append(const FXchar* s);
273 
275  FXString& append(const FXnchar* s);
276 
278  FXString& append(const FXwchar* s);
279 
281  FXString& append(const FXchar* s,FXint n);
282 
284  FXString& append(const FXnchar* s,FXint n);
285 
287  FXString& append(const FXwchar* s,FXint n);
288 
290  FXString& append(const FXString& s);
291 
293  FXString& replace(FXint pos,FXchar c);
294 
296  FXString& replace(FXint pos,FXint r,FXchar c,FXint n);
297 
299  FXString& replace(FXint pos,FXint r,const FXchar* s);
300 
302  FXString& replace(FXint pos,FXint r,const FXnchar* s);
303 
305  FXString& replace(FXint pos,FXint r,const FXwchar* s);
306 
308  FXString& replace(FXint pos,FXint r,const FXchar* s,FXint n);
309 
311  FXString& replace(FXint pos,FXint r,const FXnchar* s,FXint n);
312 
314  FXString& replace(FXint pos,FXint r,const FXwchar* s,FXint n);
315 
317  FXString& replace(FXint pos,FXint r,const FXString& s);
318 
320  FXString& move(FXint dst,FXint src,FXint n);
321 
323  FXString& erase(FXint pos);
324 
326  FXString& erase(FXint pos,FXint n);
327 
329  FXString& trunc(FXint pos);
330 
332  FXString& clear();
333 
335  FXint contains(FXchar ch) const;
336 
338  FXint contains(const FXchar* sub,FXint n) const;
339 
341  FXint contains(const FXchar* sub) const;
342 
344  FXint contains(const FXString& sub) const;
345 
347  FXString& substitute(FXchar org,FXchar sub,FXbool all=true);
348 
350  FXString& substitute(const FXchar* org,FXint olen,const FXchar *rep,FXint rlen,FXbool all=true);
351 
353  FXString& substitute(const FXchar* org,const FXchar *rep,FXbool all=true);
354 
356  FXString& substitute(const FXString& org,const FXString& rep,FXbool all=true);
357 
359  FXString& lower();
360 
362  FXString& upper();
363 
365  FXString& simplify();
366 
368  FXString& trim();
369 
371  FXString& trimBegin();
372 
374  FXString& trimEnd();
375 
377  FXString left(FXint n) const;
378 
380  FXString right(FXint n) const;
381 
383  FXString mid(FXint pos,FXint n) const;
384 
386  FXString section(FXchar delim,FXint start,FXint num=1) const;
387 
389  FXString section(const FXchar* delim,FXint n,FXint start,FXint num) const;
390 
392  FXString section(const FXchar* delim,FXint start,FXint num=1) const;
393 
395  FXString section(const FXString& delim,FXint start,FXint num=1) const;
396 
403  FXString before(FXchar ch,FXint n=1) const;
404 
411  FXString rbefore(FXchar ch,FXint n=1) const;
412 
419  FXString after(FXchar ch,FXint n=1) const;
420 
427  FXString rafter(FXchar ch,FXint n=1) const;
428 
430  FXint find(FXchar c,FXint pos=0) const;
431 
433  FXint rfind(FXchar c,FXint pos=2147483647) const;
434 
436  FXint find(FXchar c,FXint pos,FXint n) const;
437 
439  FXint rfind(FXchar c,FXint pos,FXint n) const;
440 
442  FXint find(const FXchar* substr,FXint n,FXint pos) const;
443 
445  FXint rfind(const FXchar* substr,FXint n,FXint pos) const;
446 
448  FXint find(const FXchar* substr,FXint pos=0) const;
449 
451  FXint rfind(const FXchar* substr,FXint pos=2147483647) const;
452 
454  FXint find(const FXString& substr,FXint pos=0) const;
455 
457  FXint rfind(const FXString& substr,FXint pos=2147483647) const;
458 
460  FXint find_first_of(const FXchar* set,FXint n,FXint pos) const;
461 
463  FXint find_first_of(const FXchar* set,FXint pos=0) const;
464 
466  FXint find_first_of(const FXString& set,FXint pos=0) const;
467 
469  FXint find_first_of(FXchar c,FXint pos=0) const;
470 
472  FXint find_last_of(const FXchar* set,FXint n,FXint pos) const;
473 
475  FXint find_last_of(const FXchar* set,FXint pos=2147483647) const;
476 
478  FXint find_last_of(const FXString& set,FXint pos=2147483647) const;
479 
481  FXint find_last_of(FXchar c,FXint pos=2147483647) const;
482 
484  FXint find_first_not_of(const FXchar* set,FXint n,FXint pos) const;
485 
487  FXint find_first_not_of(const FXchar* set,FXint pos=0) const;
488 
490  FXint find_first_not_of(const FXString& set,FXint pos=0) const;
491 
493  FXint find_first_not_of(FXchar c,FXint pos=0) const;
494 
496  FXint find_last_not_of(const FXchar* set,FXint n,FXint pos) const;
497 
499  FXint find_last_not_of(const FXchar* set,FXint pos=2147483647) const;
500 
502  FXint find_last_not_of(const FXString& set,FXint pos=2147483647) const;
503 
505  FXint find_last_not_of(FXchar c,FXint pos=2147483647) const;
506 
508  FXint scan(const FXchar* fmt,...) const FX_SCANF(2,3) ;
509  FXint vscan(const FXchar* fmt,va_list args) const;
510 
512  FXint format(const FXchar* fmt,...) FX_PRINTF(2,3) ;
513  FXint vformat(const FXchar* fmt,va_list args);
514 
516  FXint toInt(FXint base=10,FXbool* ok=nullptr) const;
517 
519  FXuint toUInt(FXint base=10,FXbool* ok=nullptr) const;
520 
522  FXlong toLong(FXint base=10,FXbool* ok=nullptr) const;
523 
525  FXulong toULong(FXint base=10,FXbool* ok=nullptr) const;
526 
528  FXfloat toFloat(FXbool* ok=nullptr) const;
529 
531  FXdouble toDouble(FXbool* ok=nullptr) const;
532 
534  FXString& fromInt(FXint number,FXint base=10);
535 
537  FXString& fromUInt(FXuint number,FXint base=10);
538 
540  FXString& fromLong(FXlong number,FXint base=10);
541 
543  FXString& fromULong(FXulong number,FXint base=10);
544 
546  FXString& fromFloat(FXfloat number,FXint prec=6,FXint fmt=2);
547 
549  FXString& fromDouble(FXdouble number,FXint prec=6,FXint fmt=2);
550 
555  static FXString value(FXint num,FXint base=10);
556  static FXString value(FXuint num,FXint base=10);
557 
562  static FXString value(FXlong num,FXint base=10);
563  static FXString value(FXulong num,FXint base=10);
564 
570  static FXString value(FXfloat num,FXint prec=6,FXint fmt=2);
571  static FXString value(FXdouble num,FXint prec=6,FXint fmt=2);
572 
576  static FXString value(const FXchar* fmt,...) FX_PRINTF(1,2) ;
577 
581  static FXString vvalue(const FXchar* fmt,va_list args);
582 
583 
585  FXuint hash() const;
586 
588  static FXuint hash(const FXchar* s);
589 
591  static FXuint hash(const FXchar* s,FXint n);
592 
594  static FXint compare(const FXchar* s1,const FXchar* s2);
595  static FXint compare(const FXchar* s1,const FXString& s2);
596  static FXint compare(const FXString& s1,const FXchar* s2);
597  static FXint compare(const FXString& s1,const FXString& s2);
598 
600  static FXint compare(const FXchar* s1,const FXchar* s2,FXint n);
601  static FXint compare(const FXchar* s1,const FXString& s2,FXint n);
602  static FXint compare(const FXString& s1,const FXchar* s2,FXint n);
603  static FXint compare(const FXString& s1,const FXString& s2,FXint n);
604 
606  static FXint comparecase(const FXchar* s1,const FXchar* s2);
607  static FXint comparecase(const FXchar* s1,const FXString& s2);
608  static FXint comparecase(const FXString& s1,const FXchar* s2);
609  static FXint comparecase(const FXString& s1,const FXString& s2);
610 
612  static FXint comparecase(const FXchar* s1,const FXchar* s2,FXint n);
613  static FXint comparecase(const FXchar* s1,const FXString& s2,FXint n);
614  static FXint comparecase(const FXString& s1,const FXchar* s2,FXint n);
615  static FXint comparecase(const FXString& s1,const FXString& s2,FXint n);
616 
618  static FXint comparenatural(const FXchar* s1,const FXchar* s2);
619  static FXint comparenatural(const FXchar* s1,const FXString& s2);
620  static FXint comparenatural(const FXString& s1,const FXchar* s2);
621  static FXint comparenatural(const FXString& s1,const FXString& s2);
622 
624  static FXint comparenaturalcase(const FXchar* s1,const FXchar* s2);
625  static FXint comparenaturalcase(const FXchar* s1,const FXString& s2);
626  static FXint comparenaturalcase(const FXString& s1,const FXchar* s2);
627  static FXint comparenaturalcase(const FXString& s1,const FXString& s2);
628 
633  static FXbool shouldEscape(const FXchar* str,FXchar lquote='\0',FXchar rquote='\0',FXint flag=0);
634  static FXbool shouldEscape(const FXchar* str,FXint num,FXchar lquote='\0',FXchar rquote='\0',FXint flag=0);
635  static FXbool shouldEscape(const FXString& str,FXchar lquote='\0',FXchar rquote='\0',FXint flag=0);
636 
646  static FXString escape(const FXchar* str,FXchar lquote='\0',FXchar rquote='\0',FXint flag=0);
647  static FXString escape(const FXchar* str,FXint num,FXchar lquote='\0',FXchar rquote='\0',FXint flag=0);
648  static FXString escape(const FXString& str,FXchar lquote='\0',FXchar rquote='\0',FXint flag=0);
649 
657  static FXString unescape(const FXchar* str,FXchar lquote='\0',FXchar rquote='\0');
658  static FXString unescape(const FXchar* str,FXint num,FXchar lquote='\0',FXchar rquote='\0');
659  static FXString unescape(const FXString& str,FXchar lquote='\0',FXchar rquote='\0');
660 
665  static FXString detab(const FXchar* str,FXint tabcols);
666  static FXString detab(const FXchar* str,FXint num,FXint tabcols);
667  static FXString detab(const FXString& str,FXint tabcols);
668 
673  static FXString entab(const FXchar* str,FXint tabcols);
674  static FXString entab(const FXchar* str,FXint num,FXint tabcols);
675  static FXString entab(const FXString& str,FXint tabcols);
676 
682  static FXint columns(const FXchar* str,FXint tabcols);
683  static FXint columns(const FXchar* str,FXint num,FXint tabcols);
684  static FXint columns(const FXString& str,FXint tabcols);
685 
693  static FXString tabbify(const FXchar* str,FXint tabcols,FXint indent,FXint outdent,FXint shift,FXbool tabs);
694  static FXString tabbify(const FXchar* str,FXint num,FXint tabcols,FXint indent,FXint outdent,FXint shift,FXbool tabs);
695  static FXString tabbify(const FXString& str,FXint tabcols,FXint indent,FXint outdent,FXint shift,FXbool tabs);
696 
700  static FXString normalize(const FXString& s);
701 
705  static FXString decompose(const FXString& s,FXbool canonical=true);
706 
711  static FXString compose(const FXString& s,FXbool canonical=true);
712 
714  friend inline FXString& swap(FXString& dst,FXString& src);
715 
717  friend FXAPI FXStream& operator<<(FXStream& store,const FXString& s);
718 
720  friend FXAPI FXStream& operator>>(FXStream& store,FXString& s);
721 
723  ~FXString();
724  };
725 
726 
728 inline FXString& swap(FXString& dst,FXString& src){
729  FXchar* t=dst.str; dst.str=src.str; src.str=t;
730  return dst;
731  }
732 
733 
735 static inline FXbool operator==(const FXString& s1,const FXString& s2){ return FXString::compare(s1.text(),s2.text())==0; }
736 static inline FXbool operator==(const FXString& s1,const FXchar* s2){ return FXString::compare(s1.text(),s2)==0; }
737 static inline FXbool operator==(const FXchar* s1,const FXString& s2){ return FXString::compare(s1,s2.text())==0; }
738 
740 static inline FXbool operator!=(const FXString& s1,const FXString& s2){ return FXString::compare(s1.text(),s2.text())!=0; }
741 static inline FXbool operator!=(const FXString& s1,const FXchar* s2){ return FXString::compare(s1.text(),s2)!=0; }
742 static inline FXbool operator!=(const FXchar* s1,const FXString& s2){ return FXString::compare(s1,s2.text())!=0; }
743 
745 static inline FXbool operator<(const FXString& s1,const FXString& s2){ return FXString::compare(s1.text(),s2.text())<0; }
746 static inline FXbool operator<(const FXString& s1,const FXchar* s2){ return FXString::compare(s1.text(),s2)<0; }
747 static inline FXbool operator<(const FXchar* s1,const FXString& s2){ return FXString::compare(s1,s2.text())<0; }
748 
750 static inline FXbool operator<=(const FXString& s1,const FXString& s2){ return FXString::compare(s1.text(),s2.text())<=0; }
751 static inline FXbool operator<=(const FXString& s1,const FXchar* s2){ return FXString::compare(s1.text(),s2)<=0; }
752 static inline FXbool operator<=(const FXchar* s1,const FXString& s2){ return FXString::compare(s1,s2.text())<=0; }
753 
755 static inline FXbool operator>(const FXString& s1,const FXString& s2){ return FXString::compare(s1.text(),s2.text())>0; }
756 static inline FXbool operator>(const FXString& s1,const FXchar* s2){ return FXString::compare(s1.text(),s2)>0; }
757 static inline FXbool operator>(const FXchar* s1,const FXString& s2){ return FXString::compare(s1,s2.text())>0; }
758 
760 static inline FXbool operator>=(const FXString& s1,const FXString& s2){ return FXString::compare(s1.text(),s2.text())>=0; }
761 static inline FXbool operator>=(const FXString& s1,const FXchar* s2){ return FXString::compare(s1.text(),s2)>=0; }
762 static inline FXbool operator>=(const FXchar* s1,const FXString& s2){ return FXString::compare(s1,s2.text())>=0; }
763 
765 extern FXAPI FXString operator+(const FXString& s1,const FXString& s2);
766 
768 extern FXAPI FXString operator+(const FXString& s1,const FXchar* s2);
769 extern FXAPI FXString operator+(const FXString& s1,const FXnchar* s2);
770 extern FXAPI FXString operator+(const FXString& s1,const FXwchar* s2);
771 
773 extern FXAPI FXString operator+(const FXchar* s1,const FXString& s2);
774 extern FXAPI FXString operator+(const FXnchar* s1,const FXString& s2);
775 extern FXAPI FXString operator+(const FXwchar* s1,const FXString& s2);
776 
778 extern FXAPI FXString operator+(const FXString& s,FXchar c);
779 extern FXAPI FXString operator+(FXchar c,const FXString& s);
780 
782 extern FXAPI FXStream& operator<<(FXStream& store,const FXString& s);
783 
785 extern FXAPI FXStream& operator>>(FXStream& store,FXString& s);
786 
788 extern FXAPI FXString& unixToDos(FXString& str);
789 
791 extern FXAPI FXString& dosToUnix(FXString& str);
792 
793 }
794 
795 #endif
FXchar & head()
Return a non-const reference to the first character.
Definition: FXString.h:143
FXchar & tail()
Return a non-const reference to the last character.
Definition: FXString.h:149
const FXchar * text() const
Get text contents as const pointer.
Definition: FXString.h:122
const FXchar & tail() const
Return a const reference to the last character.
Definition: FXString.h:152
const FXchar & at(FXint i) const
Return a const reference to the ith character.
Definition: FXString.h:140
FXchar & operator[](FXint i)
Return a non-const reference to the ith character.
Definition: FXString.h:131
FXchar * text()
Get text contents as pointer.
Definition: FXString.h:119
FXbool empty() const
See if string is empty.
Definition: FXString.h:125
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:81
FXchar & at(FXint i)
Return a non-const reference to the ith character.
Definition: FXString.h:137
FXbool operator!() const
See if string is empty.
Definition: FXString.h:128
FXint length() const
Length of text in bytes.
Definition: FXString.h:77
Definition: FX4Splitter.h:28
const FXchar & head() const
Return a const reference to the first character.
Definition: FXString.h:146
static FXint compare(const FXchar *s1, const FXchar *s2)
Compare.
const FXchar & operator[](FXint i) const
Return a const reference to the ith character.
Definition: FXString.h:134
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2022 Jeroen van der Zijp