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,2004 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.10 2004/02/08 17:17:34 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 /// Return number of occurrences of ch in string 00191 FXint contains(FXwchar ch); 00192 00193 /// Return number of occurrences of string sub in string 00194 FXint contains(const FXwchar* sub,FXint n); 00195 00196 /// Return number of occurrences of string sub in string 00197 FXint contains(const FXwchar* sub); 00198 00199 /// Return number of occurrences of string sub in string 00200 FXint contains(const FXWString& sub); 00201 00202 /// Substitute one character by another 00203 FXWString& substitute(FXwchar org,FXwchar sub,FXbool all=TRUE); 00204 00205 /// Substitute one string by another 00206 FXWString& substitute(const FXwchar* org,FXint olen,const FXwchar *rep,FXint rlen,FXbool all=TRUE); 00207 00208 /// Substitute one string by another 00209 FXWString& substitute(const FXwchar* org,const FXwchar *rep,FXbool all=TRUE); 00210 00211 /// Substitute one string by another 00212 FXWString& substitute(const FXWString& org,const FXWString& rep,FXbool all=TRUE); 00213 00214 /// Simplify whitespace in string 00215 FXWString& simplify(); 00216 00217 /// Remove leading and trailing whitespace 00218 FXWString& trim(); 00219 00220 /// Remove leading whitespace 00221 FXWString& trimBegin(); 00222 00223 /// Remove trailing whitespace 00224 FXWString& trimEnd(); 00225 00226 /// Truncate string at pos 00227 FXWString& trunc(FXint pos); 00228 00229 /// Clear 00230 FXWString& clear(); 00231 00232 /// Get leftmost part 00233 FXWString left(FXint n) const; 00234 00235 /// Get rightmost part 00236 FXWString right(FXint n) const; 00237 00238 /// Get some part in the middle 00239 FXWString mid(FXint pos,FXint n) const; 00240 00241 /** 00242 * Return all characters before the n-th occurrence of ch, 00243 * searching from the beginning of the string. If the character 00244 * is not found, return the entire string. If n<=0, return 00245 * the empty string. 00246 */ 00247 FXWString before(FXwchar ch,FXint n=1) const; 00248 00249 /** 00250 * Return all characters before the n-th occurrence of ch, 00251 * searching from the end of the string. If the character 00252 * is not found, return the empty string. If n<=0, return 00253 * the entire string. 00254 */ 00255 FXWString rbefore(FXwchar ch,FXint n=1) const; 00256 00257 /** 00258 * Return all characters after the nth occurrence of ch, 00259 * searching from the beginning of the string. If the character 00260 * is not found, return the empty string. If n<=0, return 00261 * the entire string. 00262 */ 00263 FXWString after(FXwchar ch,FXint n=1) const; 00264 00265 /** 00266 * Return all characters after the nth occurrence of ch, 00267 * searching from the end of the string. If the character 00268 * is not found, return the entire string. If n<=0, return 00269 * the empty string. 00270 */ 00271 FXWString rafter(FXwchar ch,FXint n=1) const; 00272 00273 /// Find a character, searching forward; return position or -1 00274 FXint find(FXwchar c,FXint pos=0) const; 00275 00276 /// Find a character, searching backward; return position or -1 00277 FXint rfind(FXwchar c,FXint pos=2147483647) const; 00278 00279 // Find n-th occurrence of character, searching forward; return position or -1 00280 FXint find(FXwchar c,FXint pos,FXint n) const; 00281 00282 // Find n-th occurrence of character, searching backward; return position or -1 00283 FXint rfind(FXwchar c,FXint pos,FXint n) const; 00284 00285 /// Find a substring of length n, searching forward; return position or -1 00286 FXint find(const FXwchar* substr,FXint n,FXint pos) const; 00287 00288 /// Find a substring of length n, searching backward; return position or -1 00289 FXint rfind(const FXwchar* substr,FXint n,FXint pos) const; 00290 00291 /// Find a substring, searching forward; return position or -1 00292 FXint find(const FXwchar* substr,FXint pos=0) const; 00293 00294 /// Find a substring, searching backward; return position or -1 00295 FXint rfind(const FXwchar* substr,FXint pos=2147483647) const; 00296 00297 /// Find a substring, searching forward; return position or -1 00298 FXint find(const FXWString &substr,FXint pos=0) const; 00299 00300 /// Find a substring, searching backward; return position or -1 00301 FXint rfind(const FXWString &substr,FXint pos=2147483647) const; 00302 00303 /// Find first character in the set of size n, starting from pos; return position or -1 00304 FXint find_first_of(const FXwchar *set,FXint n,FXint pos) const; 00305 00306 /// Find first character in the set, starting from pos; return position or -1 00307 FXint find_first_of(const FXwchar *set,FXint pos=0) const; 00308 00309 /// Find first character in the set, starting from pos; return position or -1 00310 FXint find_first_of(const FXWString &set,FXint pos=0) const; 00311 00312 /// Find first character, starting from pos; return position or -1 00313 FXint find_first_of(FXwchar c,FXint pos=0) const; 00314 00315 /// Find last character in the set of size n, starting from pos; return position or -1 00316 FXint find_last_of(const FXwchar *set,FXint n,FXint pos) const; 00317 00318 /// Find last character in the set, starting from pos; return position or -1 00319 FXint find_last_of(const FXwchar *set,FXint pos=2147483647) const; 00320 00321 /// Find last character in the set, starting from pos; return position or -1 00322 FXint find_last_of(const FXWString &set,FXint pos=2147483647) const; 00323 00324 /// Find last character, starting from pos; return position or -1 00325 FXint find_last_of(FXwchar c,FXint pos=0) const; 00326 00327 /// Find first character NOT in the set of size n, starting from pos; return position or -1 00328 FXint find_first_not_of(const FXwchar *set,FXint n,FXint pos) const; 00329 00330 /// Find first character NOT in the set, starting from pos; return position or -1 00331 FXint find_first_not_of(const FXwchar *set,FXint pos=0) const; 00332 00333 /// Find first character NOT in the set, starting from pos; return position or -1 00334 FXint find_first_not_of(const FXWString &set,FXint pos=0) const; 00335 00336 /// Find first character NOT equal to c, starting from pos; return position or -1 00337 FXint find_first_not_of(FXwchar c,FXint pos=0) const; 00338 00339 /// Find last character NOT in the set of size n, starting from pos; return position or -1 00340 FXint find_last_not_of(const FXwchar *set,FXint n,FXint pos) const; 00341 00342 /// Find last character NOT in the set, starting from pos; return position or -1 00343 FXint find_last_not_of(const FXwchar *set,FXint pos=2147483647) const; 00344 00345 /// Find last character NOT in the set, starting from pos; return position or -1 00346 FXint find_last_not_of(const FXWString &set,FXint pos=2147483647) const; 00347 00348 /// Find last character NOT equal to c, starting from pos; return position or -1 00349 FXint find_last_not_of(FXwchar c,FXint pos=0) const; 00350 00351 /// Find number of occurrences of character in string 00352 FXint count(FXwchar c) const; 00353 00354 /// Format a string a-la printf 00355 // FXWString& format(const char *fmt,...) FX_PRINTF(2,3) ; 00356 // FXWString& vformat(const char *fmt,va_list args); 00357 00358 /// Scan a string a-la scanf 00359 // FXint scan(const char *fmt,...) const FX_SCANF(2,3) ; 00360 // FXint vscan(const char *fmt,va_list args) const; 00361 00362 /// Get hash value 00363 FXuint hash() const; 00364 00365 /// Compare 00366 friend FXAPI FXint compare(const FXwchar *s1,const FXwchar *s2); 00367 friend FXAPI FXint compare(const FXwchar *s1,const FXWString &s2); 00368 friend FXAPI FXint compare(const FXWString &s1,const FXwchar *s2); 00369 friend FXAPI FXint compare(const FXWString &s1,const FXWString &s2); 00370 00371 /// Compare up to n 00372 friend FXAPI FXint compare(const FXwchar *s1,const FXwchar *s2,FXint n); 00373 friend FXAPI FXint compare(const FXwchar *s1,const FXWString &s2,FXint n); 00374 friend FXAPI FXint compare(const FXWString &s1,const FXwchar *s2,FXint n); 00375 friend FXAPI FXint compare(const FXWString &s1,const FXWString &s2,FXint n); 00376 00377 /// Compare case insensitive 00378 friend FXAPI FXint comparecase(const FXwchar *s1,const FXwchar *s2); 00379 friend FXAPI FXint comparecase(const FXwchar *s1,const FXWString &s2); 00380 friend FXAPI FXint comparecase(const FXWString &s1,const FXwchar *s2); 00381 friend FXAPI FXint comparecase(const FXWString &s1,const FXWString &s2); 00382 00383 /// Compare case insensitive up to n 00384 friend FXAPI FXint comparecase(const FXwchar *s1,const FXwchar *s2,FXint n); 00385 friend FXAPI FXint comparecase(const FXwchar *s1,const FXWString &s2,FXint n); 00386 friend FXAPI FXint comparecase(const FXWString &s1,const FXwchar *s2,FXint n); 00387 friend FXAPI FXint comparecase(const FXWString &s1,const FXWString &s2,FXint n); 00388 00389 /// Comparison operators 00390 friend FXAPI FXbool operator==(const FXWString &s1,const FXWString &s2); 00391 friend FXAPI FXbool operator==(const FXWString &s1,const FXwchar *s2); 00392 friend FXAPI FXbool operator==(const FXwchar *s1,const FXWString &s2); 00393 00394 friend FXAPI FXbool operator!=(const FXWString &s1,const FXWString &s2); 00395 friend FXAPI FXbool operator!=(const FXWString &s1,const FXwchar *s2); 00396 friend FXAPI FXbool operator!=(const FXwchar *s1,const FXWString &s2); 00397 00398 friend FXAPI FXbool operator<(const FXWString &s1,const FXWString &s2); 00399 friend FXAPI FXbool operator<(const FXWString &s1,const FXwchar *s2); 00400 friend FXAPI FXbool operator<(const FXwchar *s1,const FXWString &s2); 00401 00402 friend FXAPI FXbool operator<=(const FXWString &s1,const FXWString &s2); 00403 friend FXAPI FXbool operator<=(const FXWString &s1,const FXwchar *s2); 00404 friend FXAPI FXbool operator<=(const FXwchar *s1,const FXWString &s2); 00405 00406 friend FXAPI FXbool operator>(const FXWString &s1,const FXWString &s2); 00407 friend FXAPI FXbool operator>(const FXWString &s1,const FXwchar *s2); 00408 friend FXAPI FXbool operator>(const FXwchar *s1,const FXWString &s2); 00409 00410 friend FXAPI FXbool operator>=(const FXWString &s1,const FXWString &s2); 00411 friend FXAPI FXbool operator>=(const FXWString &s1,const FXwchar *s2); 00412 friend FXAPI FXbool operator>=(const FXwchar *s1,const FXWString &s2); 00413 00414 /// Append operators 00415 FXWString& operator+=(const FXWString& s); 00416 FXWString& operator+=(const FXwchar* s); 00417 FXWString& operator+=(FXwchar c); 00418 00419 /// Concatenate two strings 00420 friend FXAPI FXWString operator+(const FXWString& s1,const FXWString& s2); 00421 friend FXAPI FXWString operator+(const FXWString& s1,const FXwchar* s2); 00422 friend FXAPI FXWString operator+(const FXwchar* s1,const FXWString& s2); 00423 00424 /// Concatenate with single character 00425 friend FXAPI FXWString operator+(const FXWString& s,FXwchar c); 00426 friend FXAPI FXWString operator+(FXwchar c,const FXWString& s); 00427 00428 /// Saving to a stream 00429 friend FXAPI FXStream& operator<<(FXStream& store,const FXWString& s); 00430 00431 /// Load from a stream 00432 friend FXAPI FXStream& operator>>(FXStream& store,FXWString& s); 00433 00434 /// Format a string a-la printf 00435 // friend FXAPI FXWString FXWStringFormat(const FXwchar *fmt,...) FX_PRINTF(1,2) ; 00436 // friend FXAPI FXWString FXWStringVFormat(const FXwchar *fmt,va_list args); 00437 00438 /** 00439 * Convert integer number to a string, using the given number 00440 * base, which must be between 2 and 16. 00441 */ 00442 // friend FXAPI FXWString FXWStringVal(FXint num,FXint base=10); 00443 // friend FXAPI FXWString FXWStringVal(FXuint num,FXint base=10); 00444 00445 /** 00446 * Convert real number to a string, using the given procision and 00447 * exponential notation mode, which may be FALSE (never), TRUE (always), or 00448 * MAYBE (when needed). 00449 */ 00450 // friend FXAPI FXWString FXWStringVal(FXfloat num,FXint prec=6,FXbool exp=MAYBE); 00451 // friend FXAPI FXWString FXWStringVal(FXdouble num,FXint prec=6,FXbool exp=MAYBE); 00452 00453 /// Convert string to a integer number, assuming given number base 00454 // friend FXAPI FXint FXIntVal(const FXWString& s,FXint base=10); 00455 // friend FXAPI FXuint FXUIntVal(const FXWString& s,FXint base=10); 00456 00457 /// Convert string into real number 00458 // friend FXAPI FXfloat FXFloatVal(const FXWString& s); 00459 // friend FXAPI FXdouble FXDoubleVal(const FXWString& s); 00460 00461 /// Swap two strings 00462 friend FXAPI void swap(FXWString& a,FXWString& b){ FXwchar *t=a.str; a.str=b.str; b.str=t; } 00463 00464 /// Delete 00465 ~FXWString(); 00466 }; 00467 00468 } 00469 00470 #endif

Copyright © 1997-2004 Jeroen van der Zijp