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

FXWString.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                    W i d e   S t r i n g   O b j e c t                        *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2002 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (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 GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXWString.h,v 1.6 2002/10/01 18:11:10 fox Exp $                          *
00023 ********************************************************************************/
00024 #ifndef FXWSTRING_H
00025 #define FXWSTRING_H
00026 
00027 namespace FX {
00028 
00029 
00030 
00031 //////////////////////////////  UNDER DEVELOPMENT  //////////////////////////////
00032 
00033 
00034 /**
00035 * FXWString provides a "wide" string class suitable for storing Unicode strings.
00036 */
00037 class FXAPI FXWString {
00038 private:
00039   FXwchar* str;
00040 public:
00041   static const FXwchar null[];
00042   static const FXwchar hex[17];
00043   static const FXwchar HEX[17];
00044 public:
00045 
00046   /// Create empty string
00047   FXWString();
00048 
00049   /// Copy construct
00050   FXWString(const FXWString& s);
00051 
00052   /// Construct and init
00053   FXWString(const FXwchar* s);
00054 
00055   /// Construct and init with substring
00056   FXWString(const FXwchar* s,FXint n);
00057 
00058   /// Construct and fill with constant
00059   FXWString(FXwchar c,FXint n);
00060 
00061   /// Construct string from two parts
00062   FXWString(const FXwchar *s1,const FXwchar* s2);
00063 
00064   /// Change the length of the string to len
00065   void length(FXint len);
00066 
00067   /// Length of text
00068   FXint length() const { return ((FXint*)str)[-1]; }
00069 
00070   /// Get text contents
00071   const FXwchar* text() const { return (const FXwchar*)str; }
00072 
00073   /// See if string is empty
00074   FXbool empty() const { return (((FXint*)str)[-1]==0); }
00075 
00076   /// Return a non-const reference to the ith character
00077   FXwchar& operator[](FXint i){ return str[i]; }
00078 
00079   /// Return a const reference to the ith character
00080   const FXwchar& operator[](FXint i) const { return str[i]; }
00081 
00082   /// Assign another string to this
00083   FXWString& operator=(const FXWString& s);
00084 
00085   /// Assign a C-style string to this
00086   FXWString& operator=(const FXwchar* s);
00087 
00088   /// Fill with a constant
00089   FXWString& fill(FXwchar c,FXint n);
00090 
00091   /// Fill up to current length
00092   FXWString& fill(FXwchar c);
00093 
00094   /// Convert to lower case
00095   FXWString& lower();
00096 
00097   /// Convert to upper case
00098   FXWString& upper();
00099 
00100   /// Return num partition(s) of string separated by delimiter delim
00101   FXWString section(FXwchar delim,FXint start,FXint num=1) const;
00102 
00103   /// Return num partition(s) of string separated by delimiters in delim
00104   FXWString section(const FXwchar* delim,FXint n,FXint start,FXint num=1) const;
00105 
00106   /// Return num partition(s) of string separated by delimiters in delim
00107   FXWString section(const FXwchar* delim,FXint start,FXint num=1) const;
00108 
00109   /// Return num partition(s) of string separated by delimiters in delim
00110   FXWString section(const FXWString& delim,FXint start,FXint num=1) const;
00111 
00112   /// Assign character c to this string
00113   FXWString& assign(FXwchar c);
00114 
00115   /// Assign n characters c to this string
00116   FXWString& assign(FXwchar c,FXint n);
00117 
00118   /// Assign first n characters of string s to this string
00119   FXWString& assign(const FXwchar *s,FXint n);
00120 
00121   /// Assign string s to this string
00122   FXWString& assign(const FXWString& s);
00123 
00124   /// Assign string s to this string
00125   FXWString& assign(const FXwchar *s);
00126 
00127   /// Insert character at specified position
00128   FXWString& insert(FXint pos,FXwchar c);
00129 
00130   /// Insert n characters c at specified position
00131   FXWString& insert(FXint pos,FXwchar c,FXint n);
00132 
00133   /// Insert first n characters of string at specified position
00134   FXWString& insert(FXint pos,const FXwchar* s,FXint n);
00135 
00136   /// Insert string at specified position
00137   FXWString& insert(FXint pos,const FXWString& s);
00138 
00139   /// Insert string at specified position
00140   FXWString& insert(FXint pos,const FXwchar* s);
00141 
00142   /// Prepend string with input character
00143   FXWString& prepend(FXwchar c);
00144 
00145   /// Prepend string with n characters c
00146   FXWString& prepend(FXwchar c,FXint n);
00147 
00148   /// Prepend string with first n characters of input string
00149   FXWString& prepend(const FXwchar *s,FXint n);
00150 
00151   /// Prepend string with input string
00152   FXWString& prepend(const FXWString& s);
00153 
00154   /// Prepend string with input string
00155   FXWString& prepend(const FXwchar *s);
00156 
00157   /// Append input character to this string
00158   FXWString& append(FXwchar c);
00159 
00160   /// Append input n characters c to this string
00161   FXWString& append(FXwchar c,FXint n);
00162 
00163   /// Append first n characters of input string to this string
00164   FXWString& append(const FXwchar *s,FXint n);
00165 
00166   /// Append input string to this string
00167   FXWString& append(const FXWString& s);
00168 
00169   /// Append input string to this string
00170   FXWString& append(const FXwchar *s);
00171 
00172   /// Replace a single character
00173   FXWString& replace(FXint pos,FXwchar c);
00174 
00175   /// Replace the m characters at pos with n characters c
00176   FXWString& replace(FXint pos,FXint m,FXwchar c,FXint n);
00177 
00178   /// Replaces the m characters at pos with first n characters of input string
00179   FXWString& replace(FXint pos,FXint m,const FXwchar *s,FXint n);
00180 
00181   /// Replace the m characters at pos with input string
00182   FXWString& replace(FXint pos,FXint m,const FXWString& s);
00183 
00184   /// Replace the m characters at pos with input string
00185   FXWString& replace(FXint pos,FXint m,const FXwchar *s);
00186 
00187   /// Remove substring
00188   FXWString& remove(FXint pos,FXint n=1);
00189 
00190   /// Substitute one character by another
00191   FXWString& substitute(FXwchar orig,FXwchar sub);
00192 
00193   /// Simplify whitespace in string
00194   FXWString& simplify();
00195 
00196   /// Remove leading and trailing whitespace
00197   FXWString& trim();
00198 
00199   /// Remove leading whitespace
00200   FXWString& trimBegin();
00201 
00202   /// Remove trailing whitespace
00203   FXWString& trimEnd();
00204 
00205   /// Truncate string at pos
00206   FXWString& trunc(FXint pos);
00207 
00208   /// Clear
00209   FXWString& clear();
00210 
00211   /// Get leftmost part
00212   FXWString left(FXint n) const;
00213 
00214   /// Get rightmost part
00215   FXWString right(FXint n) const;
00216 
00217   /// Get some part in the middle
00218   FXWString mid(FXint pos,FXint n) const;
00219 
00220   /**
00221   * Return all characters before the n-th occurrence of ch,
00222   * searching from the beginning of the string. If the character
00223   * is not found, return the entire string.  If n<=0, return
00224   * the empty string.
00225   */
00226   FXWString before(FXwchar ch,FXint n=1) const;
00227 
00228   /**
00229   * Return all characters before the n-th occurrence of ch,
00230   * searching from the end of the string. If the character
00231   * is not found, return the empty string. If n<=0, return
00232   * the entire string.
00233   */
00234   FXWString rbefore(FXwchar ch,FXint n=1) const;
00235 
00236   /**
00237   * Return all characters after the nth occurrence of ch,
00238   * searching from the beginning of the string. If the character
00239   * is not found, return the empty string.  If n<=0, return
00240   * the entire string.
00241   */
00242   FXWString after(FXwchar ch,FXint n=1) const;
00243 
00244   /**
00245   * Return all characters after the nth occurrence of ch,
00246   * searching from the end of the string. If the character
00247   * is not found, return the entire string. If n<=0, return
00248   * the empty string.
00249   */
00250   FXWString rafter(FXwchar ch,FXint n=1) const;
00251 
00252   /// Find a character, searching forward; return position or -1
00253   FXint find(FXwchar c,FXint pos=0) const;
00254 
00255   /// Find a character, searching backward; return position or -1
00256   FXint rfind(FXwchar c,FXint pos=2147483647) const;
00257 
00258   // Find n-th occurrence of character, searching forward; return position or -1
00259   FXint find(FXwchar c,FXint pos,FXint n) const;
00260 
00261   // Find n-th occurrence of character, searching backward; return position or -1
00262   FXint rfind(FXwchar c,FXint pos,FXint n) const;
00263 
00264   /// Find a substring of length n, searching forward; return position or -1
00265   FXint find(const FXwchar* substr,FXint n,FXint pos) const;
00266 
00267   /// Find a substring of length n, searching backward; return position or -1
00268   FXint rfind(const FXwchar* substr,FXint n,FXint pos) const;
00269 
00270   /// Find a substring, searching forward; return position or -1
00271   FXint find(const FXwchar* substr,FXint pos=0) const;
00272 
00273   /// Find a substring, searching backward; return position or -1
00274   FXint rfind(const FXwchar* substr,FXint pos=2147483647) const;
00275 
00276   /// Find a substring, searching forward; return position or -1
00277   FXint find(const FXWString &substr,FXint pos=0) const;
00278 
00279   /// Find a substring, searching backward; return position or -1
00280   FXint rfind(const FXWString &substr,FXint pos=2147483647) const;
00281 
00282   /// Find first character in the set of size n, starting from pos; return position or -1
00283   FXint find_first_of(const FXwchar *set,FXint n,FXint pos) const;
00284 
00285   /// Find first character in the set, starting from pos; return position or -1
00286   FXint find_first_of(const FXwchar *set,FXint pos=0) const;
00287 
00288   /// Find first character in the set, starting from pos; return position or -1
00289   FXint find_first_of(const FXWString &set,FXint pos=0) const;
00290 
00291   /// Find first character, starting from pos; return position or -1
00292   FXint find_first_of(FXwchar c,FXint pos=0) const;
00293 
00294   /// Find last character in the set of size n, starting from pos; return position or -1
00295   FXint find_last_of(const FXwchar *set,FXint n,FXint pos) const;
00296 
00297   /// Find last character in the set, starting from pos; return position or -1
00298   FXint find_last_of(const FXwchar *set,FXint pos=2147483647) const;
00299 
00300   /// Find last character in the set, starting from pos; return position or -1
00301   FXint find_last_of(const FXWString &set,FXint pos=2147483647) const;
00302 
00303   /// Find last character, starting from pos; return position or -1
00304   FXint find_last_of(FXwchar c,FXint pos=0) const;
00305 
00306   /// Find first character NOT in the set of size n, starting from pos; return position or -1
00307   FXint find_first_not_of(const FXwchar *set,FXint n,FXint pos) const;
00308 
00309   /// Find first character NOT in the set, starting from pos; return position or -1
00310   FXint find_first_not_of(const FXwchar *set,FXint pos=0) const;
00311 
00312   /// Find first character NOT in the set, starting from pos; return position or -1
00313   FXint find_first_not_of(const FXWString &set,FXint pos=0) const;
00314 
00315   /// Find first character NOT equal to c, starting from pos; return position or -1
00316   FXint find_first_not_of(FXwchar c,FXint pos=0) const;
00317 
00318   /// Find last character NOT in the set of size n, starting from pos; return position or -1
00319   FXint find_last_not_of(const FXwchar *set,FXint n,FXint pos) const;
00320 
00321   /// Find last character NOT in the set, starting from pos; return position or -1
00322   FXint find_last_not_of(const FXwchar *set,FXint pos=2147483647) const;
00323 
00324   /// Find last character NOT in the set, starting from pos; return position or -1
00325   FXint find_last_not_of(const FXWString &set,FXint pos=2147483647) const;
00326 
00327   /// Find last character NOT equal to c, starting from pos; return position or -1
00328   FXint find_last_not_of(FXwchar c,FXint pos=0) const;
00329 
00330   /// Find number of occurances of character in string
00331   FXint count(FXwchar c) const;
00332 
00333   /// Format a string a-la printf
00334   // FXWString& format(const char *fmt,...) FX_PRINTF(2,3) ;
00335   // FXWString& vformat(const char *fmt,va_list args);
00336 
00337   /// Scan a string a-la scanf
00338   // FXint scan(const char *fmt,...) const FX_SCANF(2,3) ;
00339   // FXint vscan(const char *fmt,va_list args) const;
00340 
00341   /// Get hash value
00342   FXuint hash() const;
00343 
00344   /// Compare
00345   friend FXAPI FXint compare(const FXwchar *s1,const FXwchar *s2);
00346   friend FXAPI FXint compare(const FXwchar *s1,const FXWString &s2);
00347   friend FXAPI FXint compare(const FXWString &s1,const FXwchar *s2);
00348   friend FXAPI FXint compare(const FXWString &s1,const FXWString &s2);
00349 
00350   /// Compare up to n
00351   friend FXAPI FXint compare(const FXwchar *s1,const FXwchar *s2,FXint n);
00352   friend FXAPI FXint compare(const FXwchar *s1,const FXWString &s2,FXint n);
00353   friend FXAPI FXint compare(const FXWString &s1,const FXwchar *s2,FXint n);
00354   friend FXAPI FXint compare(const FXWString &s1,const FXWString &s2,FXint n);
00355 
00356   /// Compare case insensitive
00357   friend FXAPI FXint comparecase(const FXwchar *s1,const FXwchar *s2);
00358   friend FXAPI FXint comparecase(const FXwchar *s1,const FXWString &s2);
00359   friend FXAPI FXint comparecase(const FXWString &s1,const FXwchar *s2);
00360   friend FXAPI FXint comparecase(const FXWString &s1,const FXWString &s2);
00361 
00362   /// Compare case insensitive up to n
00363   friend FXAPI FXint comparecase(const FXwchar *s1,const FXwchar *s2,FXint n);
00364   friend FXAPI FXint comparecase(const FXwchar *s1,const FXWString &s2,FXint n);
00365   friend FXAPI FXint comparecase(const FXWString &s1,const FXwchar *s2,FXint n);
00366   friend FXAPI FXint comparecase(const FXWString &s1,const FXWString &s2,FXint n);
00367 
00368   /// Comparison operators
00369   friend FXAPI FXbool operator==(const FXWString &s1,const FXWString &s2);
00370   friend FXAPI FXbool operator==(const FXWString &s1,const FXwchar *s2);
00371   friend FXAPI FXbool operator==(const FXwchar *s1,const FXWString &s2);
00372 
00373   friend FXAPI FXbool operator!=(const FXWString &s1,const FXWString &s2);
00374   friend FXAPI FXbool operator!=(const FXWString &s1,const FXwchar *s2);
00375   friend FXAPI FXbool operator!=(const FXwchar *s1,const FXWString &s2);
00376 
00377   friend FXAPI FXbool operator<(const FXWString &s1,const FXWString &s2);
00378   friend FXAPI FXbool operator<(const FXWString &s1,const FXwchar *s2);
00379   friend FXAPI FXbool operator<(const FXwchar *s1,const FXWString &s2);
00380 
00381   friend FXAPI FXbool operator<=(const FXWString &s1,const FXWString &s2);
00382   friend FXAPI FXbool operator<=(const FXWString &s1,const FXwchar *s2);
00383   friend FXAPI FXbool operator<=(const FXwchar *s1,const FXWString &s2);
00384 
00385   friend FXAPI FXbool operator>(const FXWString &s1,const FXWString &s2);
00386   friend FXAPI FXbool operator>(const FXWString &s1,const FXwchar *s2);
00387   friend FXAPI FXbool operator>(const FXwchar *s1,const FXWString &s2);
00388 
00389   friend FXAPI FXbool operator>=(const FXWString &s1,const FXWString &s2);
00390   friend FXAPI FXbool operator>=(const FXWString &s1,const FXwchar *s2);
00391   friend FXAPI FXbool operator>=(const FXwchar *s1,const FXWString &s2);
00392 
00393   /// Append operators
00394   FXWString& operator+=(const FXWString& s);
00395   FXWString& operator+=(const FXwchar* s);
00396   FXWString& operator+=(FXwchar c);
00397 
00398   /// Concatenate two strings
00399   friend FXAPI FXWString operator+(const FXWString& s1,const FXWString& s2);
00400   friend FXAPI FXWString operator+(const FXWString& s1,const FXwchar* s2);
00401   friend FXAPI FXWString operator+(const FXwchar* s1,const FXWString& s2);
00402 
00403   /// Concatenate with single character
00404   friend FXAPI FXWString operator+(const FXWString& s,FXwchar c);
00405   friend FXAPI FXWString operator+(FXwchar c,const FXWString& s);
00406 
00407   /// Saving to a stream
00408   friend FXAPI FXStream& operator<<(FXStream& store,const FXWString& s);
00409 
00410   /// Load from a stream
00411   friend FXAPI FXStream& operator>>(FXStream& store,FXWString& s);
00412 
00413   /// Format a string a-la printf
00414   // friend FXAPI FXWString FXWStringFormat(const FXwchar *fmt,...) FX_PRINTF(1,2) ;
00415   // friend FXAPI FXWString FXWStringVFormat(const FXwchar *fmt,va_list args);
00416 
00417   /**
00418   * Convert integer number to a string, using the given number
00419   * base, which must be between 2 and 16.
00420   */
00421   // friend FXAPI FXWString FXWStringVal(FXint num,FXint base=10);
00422   // friend FXAPI FXWString FXWStringVal(FXuint num,FXint base=10);
00423 
00424   /**
00425   * Convert real number to a string, using the given procision and
00426   * exponential notation mode, which may be FALSE (never), TRUE (always), or
00427   * MAYBE (when needed).
00428   */
00429   // friend FXAPI FXWString FXWStringVal(FXfloat num,FXint prec=6,FXbool exp=MAYBE);
00430   // friend FXAPI FXWString FXWStringVal(FXdouble num,FXint prec=6,FXbool exp=MAYBE);
00431 
00432   /// Convert string to a integer number, assuming given number base
00433   // friend FXAPI FXint FXIntVal(const FXWString& s,FXint base=10);
00434   // friend FXAPI FXuint FXUIntVal(const FXWString& s,FXint base=10);
00435 
00436   /// Convert string into real number
00437   // friend FXAPI FXfloat FXFloatVal(const FXWString& s);
00438   // friend FXAPI FXdouble FXDoubleVal(const FXWString& s);
00439 
00440   /// Swap two strings
00441   friend FXAPI void swap(FXWString& a,FXWString& b){ FXwchar *t=a.str; a.str=b.str; b.str=t; }
00442 
00443   /// Delete
00444  ~FXWString();
00445   };
00446 
00447 }
00448 
00449 #endif