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,2018 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  void 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,FXint n);
194 
196  FXString& assign(const FXnchar *s,FXint n);
197 
199  FXString& assign(const FXwchar *s,FXint n);
200 
202  FXString& assign(const FXchar* s);
203 
205  FXString& assign(const FXnchar* s);
206 
208  FXString& assign(const FXwchar* s);
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,FXint n);
221 
223  FXString& insert(FXint pos,const FXnchar* s,FXint n);
224 
226  FXString& insert(FXint pos,const FXwchar* s,FXint n);
227 
229  FXString& insert(FXint pos,const FXchar* s);
230 
232  FXString& insert(FXint pos,const FXnchar* s);
233 
235  FXString& insert(FXint pos,const FXwchar* s);
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,FXint n);
248 
250  FXString& prepend(const FXnchar* s,FXint n);
251 
253  FXString& prepend(const FXwchar* s,FXint n);
254 
256  FXString& prepend(const FXchar* s);
257 
259  FXString& prepend(const FXnchar* s);
260 
262  FXString& prepend(const FXwchar* s);
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,FXint n);
275 
277  FXString& append(const FXnchar* s,FXint n);
278 
280  FXString& append(const FXwchar* s,FXint n);
281 
283  FXString& append(const FXchar* s);
284 
286  FXString& append(const FXnchar* s);
287 
289  FXString& append(const FXwchar* s);
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,FXint n);
302 
304  FXString& replace(FXint pos,FXint r,const FXnchar* s,FXint n);
305 
307  FXString& replace(FXint pos,FXint r,const FXwchar* s,FXint n);
308 
310  FXString& replace(FXint pos,FXint r,const FXchar* s);
311 
313  FXString& replace(FXint pos,FXint r,const FXnchar* s);
314 
316  FXString& replace(FXint pos,FXint r,const FXwchar* s);
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=NULL) const;
519 
521  FXuint toUInt(FXint base=10,FXbool* ok=NULL) const;
522 
524  FXlong toLong(FXint base=10,FXbool* ok=NULL) const;
525 
527  FXulong toULong(FXint base=10,FXbool* ok=NULL) const;
528 
530  FXfloat toFloat(FXbool* ok=NULL) const;
531 
533  FXdouble toDouble(FXbool* ok=NULL) 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 
586  FXuint hash() const;
587 
589  static FXuint hash(const FXchar* s);
590 
592  friend inline FXString& swap(FXString& dst,FXString& src);
593 
595  friend FXAPI FXStream& operator<<(FXStream& store,const FXString& s);
596 
598  friend FXAPI FXStream& operator>>(FXStream& store,FXString& s);
599 
601  ~FXString();
602  };
603 
604 
606 inline FXString& swap(FXString& dst,FXString& src){
607  FXchar* t=dst.str; dst.str=src.str; src.str=t;
608  return dst;
609  }
610 
611 
613 extern FXAPI FXint compare(const FXchar* s1,const FXchar* s2);
614 extern FXAPI FXint compare(const FXchar* s1,const FXString& s2);
615 extern FXAPI FXint compare(const FXString& s1,const FXchar* s2);
616 extern FXAPI FXint compare(const FXString& s1,const FXString& s2);
617 
619 extern FXAPI FXint compare(const FXchar* s1,const FXchar* s2,FXint n);
620 extern FXAPI FXint compare(const FXchar* s1,const FXString& s2,FXint n);
621 extern FXAPI FXint compare(const FXString& s1,const FXchar* s2,FXint n);
622 extern FXAPI FXint compare(const FXString& s1,const FXString& s2,FXint n);
623 
625 extern FXAPI FXint comparecase(const FXchar* s1,const FXchar* s2);
626 extern FXAPI FXint comparecase(const FXchar* s1,const FXString& s2);
627 extern FXAPI FXint comparecase(const FXString& s1,const FXchar* s2);
628 extern FXAPI FXint comparecase(const FXString& s1,const FXString& s2);
629 
631 extern FXAPI FXint comparecase(const FXchar* s1,const FXchar* s2,FXint n);
632 extern FXAPI FXint comparecase(const FXchar* s1,const FXString& s2,FXint n);
633 extern FXAPI FXint comparecase(const FXString& s1,const FXchar* s2,FXint n);
634 extern FXAPI FXint comparecase(const FXString& s1,const FXString& s2,FXint n);
635 
637 extern FXAPI FXint compareversion(const FXchar* s1,const FXchar* s2);
638 extern FXAPI FXint compareversion(const FXchar* s1,const FXString& s2);
639 extern FXAPI FXint compareversion(const FXString& s1,const FXchar* s2);
640 extern FXAPI FXint compareversion(const FXString& s1,const FXString& s2);
641 
643 extern FXAPI FXint compareversioncase(const FXchar* s1,const FXchar* s2);
644 extern FXAPI FXint compareversioncase(const FXchar* s1,const FXString& s2);
645 extern FXAPI FXint compareversioncase(const FXString& s1,const FXchar* s2);
646 extern FXAPI FXint compareversioncase(const FXString& s1,const FXString& s2);
647 
649 extern FXAPI FXbool operator==(const FXString& s1,const FXString& s2);
650 extern FXAPI FXbool operator==(const FXString& s1,const FXchar* s2);
651 extern FXAPI FXbool operator==(const FXchar* s1,const FXString& s2);
652 
654 extern FXAPI FXbool operator!=(const FXString& s1,const FXString& s2);
655 extern FXAPI FXbool operator!=(const FXString& s1,const FXchar* s2);
656 extern FXAPI FXbool operator!=(const FXchar* s1,const FXString& s2);
657 
659 extern FXAPI FXbool operator<(const FXString& s1,const FXString& s2);
660 extern FXAPI FXbool operator<(const FXString& s1,const FXchar* s2);
661 extern FXAPI FXbool operator<(const FXchar* s1,const FXString& s2);
662 
664 extern FXAPI FXbool operator<=(const FXString& s1,const FXString& s2);
665 extern FXAPI FXbool operator<=(const FXString& s1,const FXchar* s2);
666 extern FXAPI FXbool operator<=(const FXchar* s1,const FXString& s2);
667 
669 extern FXAPI FXbool operator>(const FXString& s1,const FXString& s2);
670 extern FXAPI FXbool operator>(const FXString& s1,const FXchar* s2);
671 extern FXAPI FXbool operator>(const FXchar* s1,const FXString& s2);
672 
674 extern FXAPI FXbool operator>=(const FXString& s1,const FXString& s2);
675 extern FXAPI FXbool operator>=(const FXString& s1,const FXchar* s2);
676 extern FXAPI FXbool operator>=(const FXchar* s1,const FXString& s2);
677 
679 extern FXAPI FXString operator+(const FXString& s1,const FXString& s2);
680 
682 extern FXAPI FXString operator+(const FXString& s1,const FXchar* s2);
683 extern FXAPI FXString operator+(const FXString& s1,const FXnchar* s2);
684 extern FXAPI FXString operator+(const FXString& s1,const FXwchar* s2);
685 
687 extern FXAPI FXString operator+(const FXchar* s1,const FXString& s2);
688 extern FXAPI FXString operator+(const FXnchar* s1,const FXString& s2);
689 extern FXAPI FXString operator+(const FXwchar* s1,const FXString& s2);
690 
692 extern FXAPI FXString operator+(const FXString& s,FXchar c);
693 extern FXAPI FXString operator+(FXchar c,const FXString& s);
694 
696 extern FXAPI FXStream& operator<<(FXStream& store,const FXString& s);
697 
699 extern FXAPI FXStream& operator>>(FXStream& store,FXString& s);
700 
702 extern FXAPI FXString& unixToDos(FXString& str);
703 
705 extern FXAPI FXString& dosToUnix(FXString& str);
706 
711 extern FXAPI FXbool shouldEscape(const FXString& str,FXchar lquote=0,FXchar rquote=0,FXint flag=0);
712 
722 extern FXAPI FXString escape(const FXString& str,FXchar lquote=0,FXchar rquote=0,FXint flag=0);
723 
731 extern FXAPI FXString unescape(const FXString& str,FXchar lquote=0,FXchar rquote=0);
732 
733 
734 
736 extern FXAPI FXString normalize(const FXString& s);
737 
739 extern FXAPI FXString decompose(const FXString& s,FXbool canonical=true);
740 
742 extern FXAPI FXString compose(const FXString& s,FXbool canonical=true);
743 
744 }
745 
746 #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-2018 Jeroen van der Zijp