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,2022 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  static const FXchar value2Digit[36];
49  static const FXschar digit2Value[256];
50 public:
51  static const FXschar utfBytes[256];
52 public:
53 
55  FXString();
56 
58  FXString(const FXString& s);
59 
61  FXString(const FXchar* s);
62 
64  FXString(const FXnchar* s);
65 
67  FXString(const FXwchar* s);
68 
70  FXString(const FXchar* s,FXint n);
71 
73  FXString(const FXnchar* s,FXint n);
74 
76  FXString(const FXwchar* s,FXint n);
77 
79  FXString(FXchar c,FXint n);
80 
82  FXint length() const { return *(((FXint*)str)-1); }
83 
85  FXbool length(FXint len);
86 
88  FXwchar wc(FXint p) const;
89 
91  FXint inc(FXint p) const;
92 
94  FXint inc(FXint p,FXint n) const;
95 
97  FXint dec(FXint p) const;
98 
100  FXint dec(FXint p,FXint n) const;
101 
103  FXint extent(FXint p) const { return utfBytes[(FXuchar)str[p]]; }
104 
106  FXint count() const;
107 
109  FXint count(FXint start,FXint end) const;
110 
112  FXint offset(FXint indx) const;
113 
115  FXint index(FXint offs) const;
116 
118  FXint validate(FXint p) const;
119 
121  FXchar* text(){ return str; }
122 
124  const FXchar* text() const { return str; }
125 
127  FXbool empty() const { return (((FXint*)str)[-1]==0); }
128 
130  FXbool operator!() const { return (((FXint*)str)[-1]==0); }
131 
133  FXchar& operator[](FXint i){ return str[i]; }
134 
136  const FXchar& operator[](FXint i) const { return str[i]; }
137 
139  FXchar& at(FXint i){ return str[i]; }
140 
142  const FXchar& at(FXint i) const { return str[i]; }
143 
145  FXchar& head(){ return str[0]; }
146 
148  const FXchar& head() const { return str[0]; }
149 
151  FXchar& tail(){ return str[length()-1]; }
152 
154  const FXchar& tail() const { return str[length()-1]; }
155 
157  FXString& operator=(const FXchar* s);
158 
160  FXString& operator=(const FXnchar* s);
161 
163  FXString& operator=(const FXwchar* s);
164 
166  FXString& operator=(const FXString& s);
167 
169  FXString& operator+=(FXchar c);
170 
172  FXString& operator+=(const FXchar* s);
173 
175  FXString& operator+=(const FXnchar* s);
176 
178  FXString& operator+=(const FXwchar* s);
179 
181  FXString& operator+=(const FXString& s);
182 
184  FXString& adopt(FXString& s);
185 
187  FXString& assign(FXchar c);
188 
190  FXString& assign(FXchar c,FXint n);
191 
193  FXString& assign(const FXchar* s);
194 
196  FXString& assign(const FXnchar* s);
197 
199  FXString& assign(const FXwchar* s);
200 
202  FXString& assign(const FXchar *s,FXint n);
203 
205  FXString& assign(const FXnchar *s,FXint n);
206 
208  FXString& assign(const FXwchar *s,FXint n);
209 
211  FXString& assign(const FXString& s);
212 
214  FXString& insert(FXint pos,FXchar c);
215 
217  FXString& insert(FXint pos,FXchar c,FXint n);
218 
220  FXString& insert(FXint pos,const FXchar* s);
221 
223  FXString& insert(FXint pos,const FXnchar* s);
224 
226  FXString& insert(FXint pos,const FXwchar* s);
227 
229  FXString& insert(FXint pos,const FXchar* s,FXint n);
230 
232  FXString& insert(FXint pos,const FXnchar* s,FXint n);
233 
235  FXString& insert(FXint pos,const FXwchar* s,FXint n);
236 
238  FXString& insert(FXint pos,const FXString& s);
239 
241  FXString& prepend(FXchar c);
242 
244  FXString& prepend(FXchar c,FXint n);
245 
247  FXString& prepend(const FXchar* s);
248 
250  FXString& prepend(const FXnchar* s);
251 
253  FXString& prepend(const FXwchar* s);
254 
256  FXString& prepend(const FXchar* s,FXint n);
257 
259  FXString& prepend(const FXnchar* s,FXint n);
260 
262  FXString& prepend(const FXwchar* s,FXint n);
263 
265  FXString& prepend(const FXString& s);
266 
268  FXString& append(FXchar c);
269 
271  FXString& append(FXchar c,FXint n);
272 
274  FXString& append(const FXchar* s);
275 
277  FXString& append(const FXnchar* s);
278 
280  FXString& append(const FXwchar* s);
281 
283  FXString& append(const FXchar* s,FXint n);
284 
286  FXString& append(const FXnchar* s,FXint n);
287 
289  FXString& append(const FXwchar* s,FXint n);
290 
292  FXString& append(const FXString& s);
293 
295  FXString& replace(FXint pos,FXchar c);
296 
298  FXString& replace(FXint pos,FXint r,FXchar c,FXint n);
299 
301  FXString& replace(FXint pos,FXint r,const FXchar* s);
302 
304  FXString& replace(FXint pos,FXint r,const FXnchar* s);
305 
307  FXString& replace(FXint pos,FXint r,const FXwchar* s);
308 
310  FXString& replace(FXint pos,FXint r,const FXchar* s,FXint n);
311 
313  FXString& replace(FXint pos,FXint r,const FXnchar* s,FXint n);
314 
316  FXString& replace(FXint pos,FXint r,const FXwchar* s,FXint n);
317 
319  FXString& replace(FXint pos,FXint r,const FXString& s);
320 
322  FXString& move(FXint dst,FXint src,FXint n);
323 
325  FXString& erase(FXint pos);
326 
328  FXString& erase(FXint pos,FXint n);
329 
331  FXString& trunc(FXint pos);
332 
334  FXString& clear();
335 
337  FXint contains(FXchar ch) const;
338 
340  FXint contains(const FXchar* sub,FXint n) const;
341 
343  FXint contains(const FXchar* sub) const;
344 
346  FXint contains(const FXString& sub) const;
347 
349  FXString& substitute(FXchar org,FXchar sub,FXbool all=true);
350 
352  FXString& substitute(const FXchar* org,FXint olen,const FXchar *rep,FXint rlen,FXbool all=true);
353 
355  FXString& substitute(const FXchar* org,const FXchar *rep,FXbool all=true);
356 
358  FXString& substitute(const FXString& org,const FXString& rep,FXbool all=true);
359 
361  FXString& lower();
362 
364  FXString& upper();
365 
367  FXString& simplify();
368 
370  FXString& trim();
371 
373  FXString& trimBegin();
374 
376  FXString& trimEnd();
377 
379  FXString left(FXint n) const;
380 
382  FXString right(FXint n) const;
383 
385  FXString mid(FXint pos,FXint n) const;
386 
388  FXString section(FXchar delim,FXint start,FXint num=1) const;
389 
391  FXString section(const FXchar* delim,FXint n,FXint start,FXint num) const;
392 
394  FXString section(const FXchar* delim,FXint start,FXint num=1) const;
395 
397  FXString section(const FXString& delim,FXint start,FXint num=1) const;
398 
405  FXString before(FXchar ch,FXint n=1) const;
406 
413  FXString rbefore(FXchar ch,FXint n=1) const;
414 
421  FXString after(FXchar ch,FXint n=1) const;
422 
429  FXString rafter(FXchar ch,FXint n=1) const;
430 
432  FXint find(FXchar c,FXint pos=0) const;
433 
435  FXint rfind(FXchar c,FXint pos=2147483647) const;
436 
438  FXint find(FXchar c,FXint pos,FXint n) const;
439 
441  FXint rfind(FXchar c,FXint pos,FXint n) const;
442 
444  FXint find(const FXchar* substr,FXint n,FXint pos) const;
445 
447  FXint rfind(const FXchar* substr,FXint n,FXint pos) const;
448 
450  FXint find(const FXchar* substr,FXint pos=0) const;
451 
453  FXint rfind(const FXchar* substr,FXint pos=2147483647) const;
454 
456  FXint find(const FXString& substr,FXint pos=0) const;
457 
459  FXint rfind(const FXString& substr,FXint pos=2147483647) const;
460 
462  FXint find_first_of(const FXchar* set,FXint n,FXint pos) const;
463 
465  FXint find_first_of(const FXchar* set,FXint pos=0) const;
466 
468  FXint find_first_of(const FXString& set,FXint pos=0) const;
469 
471  FXint find_first_of(FXchar c,FXint pos=0) const;
472 
474  FXint find_last_of(const FXchar* set,FXint n,FXint pos) const;
475 
477  FXint find_last_of(const FXchar* set,FXint pos=2147483647) const;
478 
480  FXint find_last_of(const FXString& set,FXint pos=2147483647) const;
481 
483  FXint find_last_of(FXchar c,FXint pos=0) const;
484 
486  FXint find_first_not_of(const FXchar* set,FXint n,FXint pos) const;
487 
489  FXint find_first_not_of(const FXchar* set,FXint pos=0) const;
490 
492  FXint find_first_not_of(const FXString& set,FXint pos=0) const;
493 
495  FXint find_first_not_of(FXchar c,FXint pos=0) const;
496 
498  FXint find_last_not_of(const FXchar* set,FXint n,FXint pos) const;
499 
501  FXint find_last_not_of(const FXchar* set,FXint pos=2147483647) const;
502 
504  FXint find_last_not_of(const FXString& set,FXint pos=2147483647) const;
505 
507  FXint find_last_not_of(FXchar c,FXint pos=0) const;
508 
510  FXint scan(const FXchar* fmt,...) const FX_SCANF(2,3) ;
511  FXint vscan(const FXchar* fmt,va_list args) const;
512 
514  FXint format(const FXchar* fmt,...) FX_PRINTF(2,3) ;
515  FXint vformat(const FXchar* fmt,va_list args);
516 
518  FXint toInt(FXint base=10,FXbool* ok=nullptr) const;
519 
521  FXuint toUInt(FXint base=10,FXbool* ok=nullptr) const;
522 
524  FXlong toLong(FXint base=10,FXbool* ok=nullptr) const;
525 
527  FXulong toULong(FXint base=10,FXbool* ok=nullptr) const;
528 
530  FXfloat toFloat(FXbool* ok=nullptr) const;
531 
533  FXdouble toDouble(FXbool* ok=nullptr) const;
534 
536  FXString& fromInt(FXint number,FXint base=10);
537 
539  FXString& fromUInt(FXuint number,FXint base=10);
540 
542  FXString& fromLong(FXlong number,FXint base=10);
543 
545  FXString& fromULong(FXulong number,FXint base=10);
546 
548  FXString& fromFloat(FXfloat number,FXint prec=6,FXint fmt=2);
549 
551  FXString& fromDouble(FXdouble number,FXint prec=6,FXint fmt=2);
552 
557  static FXString value(FXint num,FXint base=10);
558  static FXString value(FXuint num,FXint base=10);
559 
564  static FXString value(FXlong num,FXint base=10);
565  static FXString value(FXulong num,FXint base=10);
566 
572  static FXString value(FXfloat num,FXint prec=6,FXint fmt=2);
573  static FXString value(FXdouble num,FXint prec=6,FXint fmt=2);
574 
578  static FXString value(const FXchar* fmt,...) FX_PRINTF(1,2) ;
579 
583  static FXString vvalue(const FXchar* fmt,va_list args);
584 
585 
587  FXuint hash() const;
588 
590  static FXuint hash(const FXchar* s);
591 
596  static FXbool shouldEscape(const FXString& str,FXchar lquote=0,FXchar rquote=0,FXint flag=0);
597 
607  static FXString escape(const FXString& str,FXchar lquote=0,FXchar rquote=0,FXint flag=0);
608 
616  static FXString unescape(const FXString& str,FXchar lquote=0,FXchar rquote=0);
617 
622  static FXString detab(const FXString& text,FXint tabcols=8);
623 
628  static FXString entab(const FXString& text,FXint tabcols=8);
629 
637  static FXString tabbify(const FXString& text,FXint tabcols=8,FXint indent=0,FXint outdent=0,FXint shift=0,FXbool tabs=false);
638 
642  static FXString normalize(const FXString& s);
643 
647  static FXString decompose(const FXString& s,FXbool canonical=true);
648 
653  static FXString compose(const FXString& s,FXbool canonical=true);
654 
656  friend inline FXString& swap(FXString& dst,FXString& src);
657 
659  friend FXAPI FXStream& operator<<(FXStream& store,const FXString& s);
660 
662  friend FXAPI FXStream& operator>>(FXStream& store,FXString& s);
663 
665  ~FXString();
666  };
667 
668 
670 inline FXString& swap(FXString& dst,FXString& src){
671  FXchar* t=dst.str; dst.str=src.str; src.str=t;
672  return dst;
673  }
674 
675 
677 extern FXAPI FXint compare(const FXchar* s1,const FXchar* s2);
678 extern FXAPI FXint compare(const FXchar* s1,const FXString& s2);
679 extern FXAPI FXint compare(const FXString& s1,const FXchar* s2);
680 extern FXAPI FXint compare(const FXString& s1,const FXString& s2);
681 
683 extern FXAPI FXint compare(const FXchar* s1,const FXchar* s2,FXint n);
684 extern FXAPI FXint compare(const FXchar* s1,const FXString& s2,FXint n);
685 extern FXAPI FXint compare(const FXString& s1,const FXchar* s2,FXint n);
686 extern FXAPI FXint compare(const FXString& s1,const FXString& s2,FXint n);
687 
689 extern FXAPI FXint comparecase(const FXchar* s1,const FXchar* s2);
690 extern FXAPI FXint comparecase(const FXchar* s1,const FXString& s2);
691 extern FXAPI FXint comparecase(const FXString& s1,const FXchar* s2);
692 extern FXAPI FXint comparecase(const FXString& s1,const FXString& s2);
693 
695 extern FXAPI FXint comparecase(const FXchar* s1,const FXchar* s2,FXint n);
696 extern FXAPI FXint comparecase(const FXchar* s1,const FXString& s2,FXint n);
697 extern FXAPI FXint comparecase(const FXString& s1,const FXchar* s2,FXint n);
698 extern FXAPI FXint comparecase(const FXString& s1,const FXString& s2,FXint n);
699 
701 extern FXAPI FXint compareversion(const FXchar* s1,const FXchar* s2);
702 extern FXAPI FXint compareversion(const FXchar* s1,const FXString& s2);
703 extern FXAPI FXint compareversion(const FXString& s1,const FXchar* s2);
704 extern FXAPI FXint compareversion(const FXString& s1,const FXString& s2);
705 
707 extern FXAPI FXint compareversioncase(const FXchar* s1,const FXchar* s2);
708 extern FXAPI FXint compareversioncase(const FXchar* s1,const FXString& s2);
709 extern FXAPI FXint compareversioncase(const FXString& s1,const FXchar* s2);
710 extern FXAPI FXint compareversioncase(const FXString& s1,const FXString& s2);
711 
713 extern FXAPI FXbool operator==(const FXString& s1,const FXString& s2);
714 extern FXAPI FXbool operator==(const FXString& s1,const FXchar* s2);
715 extern FXAPI FXbool operator==(const FXchar* s1,const FXString& s2);
716 
718 extern FXAPI FXbool operator!=(const FXString& s1,const FXString& s2);
719 extern FXAPI FXbool operator!=(const FXString& s1,const FXchar* s2);
720 extern FXAPI FXbool operator!=(const FXchar* s1,const FXString& s2);
721 
723 extern FXAPI FXbool operator<(const FXString& s1,const FXString& s2);
724 extern FXAPI FXbool operator<(const FXString& s1,const FXchar* s2);
725 extern FXAPI FXbool operator<(const FXchar* s1,const FXString& s2);
726 
728 extern FXAPI FXbool operator<=(const FXString& s1,const FXString& s2);
729 extern FXAPI FXbool operator<=(const FXString& s1,const FXchar* s2);
730 extern FXAPI FXbool operator<=(const FXchar* s1,const FXString& s2);
731 
733 extern FXAPI FXbool operator>(const FXString& s1,const FXString& s2);
734 extern FXAPI FXbool operator>(const FXString& s1,const FXchar* s2);
735 extern FXAPI FXbool operator>(const FXchar* s1,const FXString& s2);
736 
738 extern FXAPI FXbool operator>=(const FXString& s1,const FXString& s2);
739 extern FXAPI FXbool operator>=(const FXString& s1,const FXchar* s2);
740 extern FXAPI FXbool operator>=(const FXchar* s1,const FXString& s2);
741 
743 extern FXAPI FXString operator+(const FXString& s1,const FXString& s2);
744 
746 extern FXAPI FXString operator+(const FXString& s1,const FXchar* s2);
747 extern FXAPI FXString operator+(const FXString& s1,const FXnchar* s2);
748 extern FXAPI FXString operator+(const FXString& s1,const FXwchar* s2);
749 
751 extern FXAPI FXString operator+(const FXchar* s1,const FXString& s2);
752 extern FXAPI FXString operator+(const FXnchar* s1,const FXString& s2);
753 extern FXAPI FXString operator+(const FXwchar* s1,const FXString& s2);
754 
756 extern FXAPI FXString operator+(const FXString& s,FXchar c);
757 extern FXAPI FXString operator+(FXchar c,const FXString& s);
758 
760 extern FXAPI FXStream& operator<<(FXStream& store,const FXString& s);
761 
763 extern FXAPI FXStream& operator>>(FXStream& store,FXString& s);
764 
766 extern FXAPI FXString& unixToDos(FXString& str);
767 
769 extern FXAPI FXString& dosToUnix(FXString& str);
770 
771 }
772 
773 #endif
FXchar & head()
Return a non-const reference to the first character.
Definition: FXString.h:145
FXint extent(FXint p) const
Return extent of utf8 character at position.
Definition: FXString.h:103
FXchar & tail()
Return a non-const reference to the last character.
Definition: FXString.h:151
const FXchar * text() const
Get text contents as const pointer.
Definition: FXString.h:124
const FXchar & tail() const
Return a const reference to the last character.
Definition: FXString.h:154
const FXchar & at(FXint i) const
Return a const reference to the ith character.
Definition: FXString.h:142
FXchar & operator[](FXint i)
Return a non-const reference to the ith character.
Definition: FXString.h:133
FXchar * text()
Get text contents as pointer.
Definition: FXString.h:121
FXbool empty() const
See if string is empty.
Definition: FXString.h:127
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:78
FXchar & at(FXint i)
Return a non-const reference to the ith character.
Definition: FXString.h:139
FXbool operator!() const
See if string is empty.
Definition: FXString.h:130
FXint length() const
Length of text in bytes.
Definition: FXString.h:82
Definition: FX4Splitter.h:28
const FXchar & head() const
Return a const reference to the first character.
Definition: FXString.h:148
const FXchar & operator[](FXint i) const
Return a const reference to the ith character.
Definition: FXString.h:136
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2022 Jeroen van der Zijp