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

/home/jeroen/FOX/fox/fox-1.7.33/include/FXString.h
00001 /********************************************************************************
00002 *                                                                               *
00003 *                           S t r i n g   O b j e c t                           *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2012 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXSTRING_H
00022 #define FXSTRING_H
00023 
00024 namespace FX {
00025 
00026 
00027 class FXStream;
00028 
00029 
00033 class FXAPI FXString {
00034 private:
00035   FXchar* str;
00036 public:
00037   static const FXchar null[];
00038 public:
00039   static const FXchar  value2Digit[36];
00040   static const FXschar digit2Value[256];
00041 public:
00042   static const FXschar utfBytes[256];
00043 public:
00044 
00046   FXString();
00047 
00049   FXString(const FXString& s);
00050 
00052   FXString(const FXchar* s);
00053 
00055   FXString(const FXnchar* s);
00056 
00058   FXString(const FXwchar* s);
00059 
00061   FXString(const FXchar* s,FXint n);
00062 
00064   FXString(const FXnchar* s,FXint n);
00065 
00067   FXString(const FXwchar* s,FXint n);
00068 
00070   FXString(FXchar c,FXint n);
00071 
00073   FXint length() const { return *(((FXint*)str)-1); }
00074 
00076   void length(FXint len);
00077 
00079   FXwchar wc(FXint p) const;
00080 
00082   FXint inc(FXint p) const;
00083 
00085   FXint inc(FXint p,FXint n) const;
00086 
00088   FXint dec(FXint p) const;
00089 
00091   FXint dec(FXint p,FXint n) const;
00092 
00094   FXint extent(FXint p) const { return utfBytes[(FXuchar)str[p]]; }
00095 
00097   FXint count() const;
00098 
00100   FXint count(FXint start,FXint end) const;
00101 
00103   FXint offset(FXint indx) const;
00104 
00106   FXint index(FXint offs) const;
00107 
00109   FXint validate(FXint p) const;
00110 
00112   FXchar* text(){ return str; }
00113   const FXchar* text() const { return str; }
00114 
00116   FXbool empty() const { return (((FXint*)str)[-1]==0); }
00117 
00119   FXbool operator!() const { return (((FXint*)str)[-1]==0); }
00120 
00122   FXchar& operator[](FXint i){ return str[i]; }
00123 
00125   const FXchar& operator[](FXint i) const { return str[i]; }
00126 
00128   FXchar& at(FXint i){ return str[i]; }
00129 
00131   const FXchar& at(FXint i) const { return str[i]; }
00132 
00134   FXchar& head(){ return str[0]; }
00135 
00137   const FXchar& head() const { return str[0]; }
00138 
00140   FXchar& tail(){ return str[length()-1]; }
00141 
00143   const FXchar& tail() const { return str[length()-1]; }
00144 
00146   FXString& operator=(const FXchar* s);
00147 
00149   FXString& operator=(const FXnchar* s);
00150 
00152   FXString& operator=(const FXwchar* s);
00153 
00155   FXString& operator=(const FXString& s);
00156 
00158   FXString& operator+=(FXchar c);
00159 
00161   FXString& operator+=(const FXchar* s);
00162 
00164   FXString& operator+=(const FXnchar* s);
00165 
00167   FXString& operator+=(const FXwchar* s);
00168 
00170   FXString& operator+=(const FXString& s);
00171 
00173   FXString& adopt(FXString& s);
00174 
00176   FXString& assign(FXchar c);
00177 
00179   FXString& assign(FXchar c,FXint n);
00180 
00182   FXString& assign(const FXchar *s,FXint n);
00183 
00185   FXString& assign(const FXnchar *s,FXint n);
00186 
00188   FXString& assign(const FXwchar *s,FXint n);
00189 
00191   FXString& assign(const FXchar* s);
00192 
00194   FXString& assign(const FXnchar* s);
00195 
00197   FXString& assign(const FXwchar* s);
00198 
00200   FXString& assign(const FXString& s);
00201 
00203   FXString& insert(FXint pos,FXchar c);
00204 
00206   FXString& insert(FXint pos,FXchar c,FXint n);
00207 
00209   FXString& insert(FXint pos,const FXchar* s,FXint n);
00210 
00212   FXString& insert(FXint pos,const FXnchar* s,FXint n);
00213 
00215   FXString& insert(FXint pos,const FXwchar* s,FXint n);
00216 
00218   FXString& insert(FXint pos,const FXchar* s);
00219 
00221   FXString& insert(FXint pos,const FXnchar* s);
00222 
00224   FXString& insert(FXint pos,const FXwchar* s);
00225 
00227   FXString& insert(FXint pos,const FXString& s);
00228 
00230   FXString& prepend(FXchar c);
00231 
00233   FXString& prepend(FXchar c,FXint n);
00234 
00236   FXString& prepend(const FXchar* s,FXint n);
00237 
00239   FXString& prepend(const FXnchar* s,FXint n);
00240 
00242   FXString& prepend(const FXwchar* s,FXint n);
00243 
00245   FXString& prepend(const FXchar* s);
00246 
00248   FXString& prepend(const FXnchar* s);
00249 
00251   FXString& prepend(const FXwchar* s);
00252 
00254   FXString& prepend(const FXString& s);
00255 
00257   FXString& append(FXchar c);
00258 
00260   FXString& append(FXchar c,FXint n);
00261 
00263   FXString& append(const FXchar* s,FXint n);
00264 
00266   FXString& append(const FXnchar* s,FXint n);
00267 
00269   FXString& append(const FXwchar* s,FXint n);
00270 
00272   FXString& append(const FXchar* s);
00273 
00275   FXString& append(const FXnchar* s);
00276 
00278   FXString& append(const FXwchar* s);
00279 
00281   FXString& append(const FXString& s);
00282 
00284   FXString& replace(FXint pos,FXchar c);
00285 
00287   FXString& replace(FXint pos,FXint r,FXchar c,FXint n);
00288 
00290   FXString& replace(FXint pos,FXint r,const FXchar* s,FXint n);
00291 
00293   FXString& replace(FXint pos,FXint r,const FXnchar* s,FXint n);
00294 
00296   FXString& replace(FXint pos,FXint r,const FXwchar* s,FXint n);
00297 
00299   FXString& replace(FXint pos,FXint r,const FXchar* s);
00300 
00302   FXString& replace(FXint pos,FXint r,const FXnchar* s);
00303 
00305   FXString& replace(FXint pos,FXint r,const FXwchar* s);
00306 
00308   FXString& replace(FXint pos,FXint r,const FXString& s);
00309 
00311   FXString& move(FXint dst,FXint src,FXint n);
00312 
00314   FXString& erase(FXint pos);
00315 
00317   FXString& erase(FXint pos,FXint n);
00318 
00320   FXString& trunc(FXint pos);
00321 
00323   FXString& clear();
00324 
00326   FXint contains(FXchar ch) const;
00327 
00329   FXint contains(const FXchar* sub,FXint n) const;
00330 
00332   FXint contains(const FXchar* sub) const;
00333 
00335   FXint contains(const FXString& sub) const;
00336 
00338   FXString& substitute(FXchar org,FXchar sub,FXbool all=true);
00339 
00341   FXString& substitute(const FXchar* org,FXint olen,const FXchar *rep,FXint rlen,FXbool all=true);
00342 
00344   FXString& substitute(const FXchar* org,const FXchar *rep,FXbool all=true);
00345 
00347   FXString& substitute(const FXString& org,const FXString& rep,FXbool all=true);
00348 
00350   FXString& lower();
00351 
00353   FXString& upper();
00354 
00356   FXString& simplify();
00357 
00359   FXString& trim();
00360 
00362   FXString& trimBegin();
00363 
00365   FXString& trimEnd();
00366 
00368   FXString left(FXint n) const;
00369 
00371   FXString right(FXint n) const;
00372 
00374   FXString mid(FXint pos,FXint n=2147483647) const;
00375 
00377   FXString section(FXchar delim,FXint start,FXint num=1) const;
00378 
00380   FXString section(const FXchar* delim,FXint n,FXint start,FXint num) const;
00381 
00383   FXString section(const FXchar* delim,FXint start,FXint num=1) const;
00384 
00386   FXString section(const FXString& delim,FXint start,FXint num=1) const;
00387 
00394   FXString before(FXchar ch,FXint n=1) const;
00395 
00402   FXString rbefore(FXchar ch,FXint n=1) const;
00403 
00410   FXString after(FXchar ch,FXint n=1) const;
00411 
00418   FXString rafter(FXchar ch,FXint n=1) const;
00419 
00421   FXint find(FXchar c,FXint pos=0) const;
00422 
00424   FXint rfind(FXchar c,FXint pos=2147483647) const;
00425 
00427   FXint find(FXchar c,FXint pos,FXint n) const;
00428 
00430   FXint rfind(FXchar c,FXint pos,FXint n) const;
00431 
00433   FXint find(const FXchar* substr,FXint n,FXint pos) const;
00434 
00436   FXint rfind(const FXchar* substr,FXint n,FXint pos) const;
00437 
00439   FXint find(const FXchar* substr,FXint pos=0) const;
00440 
00442   FXint rfind(const FXchar* substr,FXint pos=2147483647) const;
00443 
00445   FXint find(const FXString& substr,FXint pos=0) const;
00446 
00448   FXint rfind(const FXString& substr,FXint pos=2147483647) const;
00449 
00451   FXint find_first_of(const FXchar* set,FXint n,FXint pos) const;
00452 
00454   FXint find_first_of(const FXchar* set,FXint pos=0) const;
00455 
00457   FXint find_first_of(const FXString& set,FXint pos=0) const;
00458 
00460   FXint find_first_of(FXchar c,FXint pos=0) const;
00461 
00463   FXint find_last_of(const FXchar* set,FXint n,FXint pos) const;
00464 
00466   FXint find_last_of(const FXchar* set,FXint pos=2147483647) const;
00467 
00469   FXint find_last_of(const FXString& set,FXint pos=2147483647) const;
00470 
00472   FXint find_last_of(FXchar c,FXint pos=0) const;
00473 
00475   FXint find_first_not_of(const FXchar* set,FXint n,FXint pos) const;
00476 
00478   FXint find_first_not_of(const FXchar* set,FXint pos=0) const;
00479 
00481   FXint find_first_not_of(const FXString& set,FXint pos=0) const;
00482 
00484   FXint find_first_not_of(FXchar c,FXint pos=0) const;
00485 
00487   FXint find_last_not_of(const FXchar* set,FXint n,FXint pos) const;
00488 
00490   FXint find_last_not_of(const FXchar* set,FXint pos=2147483647) const;
00491 
00493   FXint find_last_not_of(const FXString& set,FXint pos=2147483647) const;
00494 
00496   FXint find_last_not_of(FXchar c,FXint pos=0) const;
00497 
00499   FXint scan(const FXchar* fmt,...) const FX_SCANF(2,3) ;
00500   FXint vscan(const FXchar* fmt,va_list args) const;
00501 
00503   FXint format(const FXchar* fmt,...) FX_PRINTF(2,3) ;
00504   FXint vformat(const FXchar* fmt,va_list args);
00505 
00507   FXint toInt(FXint base=10,FXbool* ok=NULL) const;
00508 
00510   FXuint toUInt(FXint base=10,FXbool* ok=NULL) const;
00511 
00513   FXlong toLong(FXint base=10,FXbool* ok=NULL) const;
00514 
00516   FXulong toULong(FXint base=10,FXbool* ok=NULL) const;
00517 
00519   FXfloat toFloat(FXbool* ok=NULL) const;
00520 
00522   FXdouble toDouble(FXbool* ok=NULL) const;
00523 
00525   FXString& fromInt(FXint number,FXint base=10);
00526 
00528   FXString& fromUInt(FXuint number,FXint base=10);
00529 
00531   FXString& fromLong(FXlong number,FXint base=10);
00532 
00534   FXString& fromULong(FXulong number,FXint base=10);
00535 
00537   FXString& fromFloat(FXfloat number,FXint prec=6,FXint fmt=2);
00538 
00540   FXString& fromDouble(FXdouble number,FXint prec=6,FXint fmt=2);
00541 
00546   static FXString value(FXint num,FXint base=10);
00547   static FXString value(FXuint num,FXint base=10);
00548 
00553   static FXString value(FXlong num,FXint base=10);
00554   static FXString value(FXulong num,FXint base=10);
00555 
00561   static FXString value(FXfloat num,FXint prec=6,FXint fmt=2);
00562   static FXString value(FXdouble num,FXint prec=6,FXint fmt=2);
00563 
00567   static FXString value(const FXchar* fmt,...) FX_PRINTF(1,2) ;
00568 
00572   static FXString vvalue(const FXchar* fmt,va_list args);
00573 
00575   FXuint hash() const;
00576 
00578   friend inline void swap(FXString& a,FXString& b);
00579 
00581   friend FXAPI FXStream& operator<<(FXStream& store,const FXString& s);
00582 
00584   friend FXAPI FXStream& operator>>(FXStream& store,FXString& s);
00585 
00587  ~FXString();
00588   };
00589 
00590 
00592 inline void swap(FXString& a,FXString& b){ FXchar *t=a.str; a.str=b.str; b.str=t; }
00593 
00594 
00596 extern FXAPI FXint compare(const FXchar* s1,const FXchar* s2);
00597 extern FXAPI FXint compare(const FXchar* s1,const FXString& s2);
00598 extern FXAPI FXint compare(const FXString& s1,const FXchar* s2);
00599 extern FXAPI FXint compare(const FXString& s1,const FXString& s2);
00600 
00602 extern FXAPI FXint compare(const FXchar* s1,const FXchar* s2,FXint n);
00603 extern FXAPI FXint compare(const FXchar* s1,const FXString& s2,FXint n);
00604 extern FXAPI FXint compare(const FXString& s1,const FXchar* s2,FXint n);
00605 extern FXAPI FXint compare(const FXString& s1,const FXString& s2,FXint n);
00606 
00608 extern FXAPI FXint comparecase(const FXchar* s1,const FXchar* s2);
00609 extern FXAPI FXint comparecase(const FXchar* s1,const FXString& s2);
00610 extern FXAPI FXint comparecase(const FXString& s1,const FXchar* s2);
00611 extern FXAPI FXint comparecase(const FXString& s1,const FXString& s2);
00612 
00614 extern FXAPI FXint comparecase(const FXchar* s1,const FXchar* s2,FXint n);
00615 extern FXAPI FXint comparecase(const FXchar* s1,const FXString& s2,FXint n);
00616 extern FXAPI FXint comparecase(const FXString& s1,const FXchar* s2,FXint n);
00617 extern FXAPI FXint comparecase(const FXString& s1,const FXString& s2,FXint n);
00618 
00620 extern FXAPI FXint compareversion(const FXchar* s1,const FXchar* s2);
00621 extern FXAPI FXint compareversion(const FXchar* s1,const FXString& s2);
00622 extern FXAPI FXint compareversion(const FXString& s1,const FXchar* s2);
00623 extern FXAPI FXint compareversion(const FXString& s1,const FXString& s2);
00624 
00626 extern FXAPI FXint compareversioncase(const FXchar* s1,const FXchar* s2);
00627 extern FXAPI FXint compareversioncase(const FXchar* s1,const FXString& s2);
00628 extern FXAPI FXint compareversioncase(const FXString& s1,const FXchar* s2);
00629 extern FXAPI FXint compareversioncase(const FXString& s1,const FXString& s2);
00630 
00632 extern FXAPI FXbool operator==(const FXString& s1,const FXString& s2);
00633 extern FXAPI FXbool operator==(const FXString& s1,const FXchar* s2);
00634 extern FXAPI FXbool operator==(const FXchar* s1,const FXString& s2);
00635 
00637 extern FXAPI FXbool operator!=(const FXString& s1,const FXString& s2);
00638 extern FXAPI FXbool operator!=(const FXString& s1,const FXchar* s2);
00639 extern FXAPI FXbool operator!=(const FXchar* s1,const FXString& s2);
00640 
00642 extern FXAPI FXbool operator<(const FXString& s1,const FXString& s2);
00643 extern FXAPI FXbool operator<(const FXString& s1,const FXchar* s2);
00644 extern FXAPI FXbool operator<(const FXchar* s1,const FXString& s2);
00645 
00647 extern FXAPI FXbool operator<=(const FXString& s1,const FXString& s2);
00648 extern FXAPI FXbool operator<=(const FXString& s1,const FXchar* s2);
00649 extern FXAPI FXbool operator<=(const FXchar* s1,const FXString& s2);
00650 
00652 extern FXAPI FXbool operator>(const FXString& s1,const FXString& s2);
00653 extern FXAPI FXbool operator>(const FXString& s1,const FXchar* s2);
00654 extern FXAPI FXbool operator>(const FXchar* s1,const FXString& s2);
00655 
00657 extern FXAPI FXbool operator>=(const FXString& s1,const FXString& s2);
00658 extern FXAPI FXbool operator>=(const FXString& s1,const FXchar* s2);
00659 extern FXAPI FXbool operator>=(const FXchar* s1,const FXString& s2);
00660 
00662 extern FXAPI FXString operator+(const FXString& s1,const FXString& s2);
00663 
00665 extern FXAPI FXString operator+(const FXString& s1,const FXchar* s2);
00666 extern FXAPI FXString operator+(const FXString& s1,const FXnchar* s2);
00667 extern FXAPI FXString operator+(const FXString& s1,const FXwchar* s2);
00668 
00670 extern FXAPI FXString operator+(const FXchar* s1,const FXString& s2);
00671 extern FXAPI FXString operator+(const FXnchar* s1,const FXString& s2);
00672 extern FXAPI FXString operator+(const FXwchar* s1,const FXString& s2);
00673 
00675 extern FXAPI FXString operator+(const FXString& s,FXchar c);
00676 extern FXAPI FXString operator+(FXchar c,const FXString& s);
00677 
00679 extern FXAPI FXStream& operator<<(FXStream& store,const FXString& s);
00680 
00682 extern FXAPI FXStream& operator>>(FXStream& store,FXString& s);
00683 
00685 extern FXAPI FXString fromAscii(const FXString& s);
00686 
00688 extern FXAPI FXString toAscii(const FXString& s);
00689 
00691 extern FXAPI FXString& unixToDos(FXString& str);
00692 
00694 extern FXAPI FXString& dosToUnix(FXString& str);
00695 
00697 extern FXAPI FXbool shouldEscape(const FXString& str,FXchar lquote=0,FXchar rquote=0,FXbool flag=false);
00698 
00700 extern FXAPI FXString escape(const FXString& str,FXchar lquote=0,FXchar rquote=0,FXbool flag=false);
00701 
00703 extern FXAPI FXString unescape(const FXString& str,FXchar lquote=0,FXchar rquote=0);
00704 
00706 extern FXAPI FXString normalize(const FXString& s);
00707 
00709 extern FXAPI FXString decompose(const FXString& s,FXbool canonical=true);
00710 
00712 extern FXAPI FXString compose(const FXString& s,FXbool canonical=true);
00713 
00714 }
00715 
00716 #endif

Copyright © 1997-2011 Jeroen van der Zijp