Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

pstring.h

Go to the documentation of this file.
00001 /* 00002 * pstring.h 00003 * 00004 * Character string class. 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 1993-1998 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Portions are Copyright (C) 1993 Free Software Foundation, Inc. 00025 * All Rights Reserved. 00026 * 00027 * Contributor(s): ______________________________________. 00028 * 00029 * $Log: pstring.h,v $ 00030 * Revision 1.76 2004/06/01 05:54:18 csoutheren 00031 * Added <vector> and <string> 00032 * 00033 * Revision 1.75 2004/06/01 05:21:38 csoutheren 00034 * Added conversions between std::string and PString, and vector<PString> and PStringArray 00035 * 00036 * Revision 1.74 2004/05/04 11:10:36 rjongbloed 00037 * Fixed usage of MakeEmpty() with PStringStream. 00038 * 00039 * Revision 1.73 2004/04/18 04:33:36 rjongbloed 00040 * Changed all operators that return BOOL to return standard type bool. This is primarily 00041 * for improved compatibility with std STL usage removing many warnings. 00042 * 00043 * Revision 1.72 2004/04/11 13:26:25 csoutheren 00044 * Removed namespace problems and removed warnings for Windows <string> 00045 * 00046 * Revision 1.71 2004/04/09 06:38:10 rjongbloed 00047 * Fixed compatibility with STL based streams, eg as used by VC++2003 00048 * 00049 * Revision 1.70 2004/04/09 03:42:34 csoutheren 00050 * Removed all usages of "virtual inline" and "inline virtual" 00051 * 00052 * Revision 1.69 2004/04/03 06:54:22 rjongbloed 00053 * Many and various changes to support new Visual C++ 2003 00054 * 00055 * Revision 1.68 2004/02/23 00:44:38 csoutheren 00056 * A completely different, other regex include hack to avoid requiring 00057 * the sources when using a header-file only environment 00058 * 00059 * Revision 1.67 2004/02/23 00:26:05 csoutheren 00060 * Finally, a generic and elegant fix for the regex include hacks. Thanks to Roger Hardiman 00061 * 00062 * Revision 1.66 2004/02/11 05:09:14 csoutheren 00063 * Fixed problems with regex libraries on Solaris, and with host OS numbering 00064 * being a quoted string rather than a number. Thanks to Chad Attermann 00065 * Fixed problems SSL detection problems thanks to Michal Zygmuntowicz 00066 * 00067 * Revision 1.65 2004/02/08 11:13:11 rjongbloed 00068 * Fixed crash in heavily loaded multi-threaded systems using simultaneous sorted 00069 * lists, Thanks Federico Pinna, Fabrizio Ammollo and the gang at Reitek S.p.A. 00070 * 00071 * Revision 1.64 2004/01/18 13:43:48 rjongbloed 00072 * Fixed broken PString::MakeEmpty() function and moved implementations to .inl file. 00073 * 00074 * Revision 1.63 2004/01/17 18:15:24 csoutheren 00075 * Fixed multi-threading problem with PString::Empty 00076 * Created PString::MakeEmpty for efficient emptying of existing strings 00077 * 00078 * Revision 1.62 2004/01/16 13:24:37 csoutheren 00079 * Changed PString::Empty to be thread-safe 00080 * Fixed PContainer::SetMinSize and PAbstractArray::SetSize, thanks to 123@call2ua.com 00081 * Fixed PString::FindLast, thanks to Andreas Sikkema 00082 * 00083 * Revision 1.61 2003/12/13 23:08:46 csoutheren 00084 * Changed PRegularExpression to allow a copy constructor and operator = 00085 * 00086 * Revision 1.60 2003/12/10 03:28:50 csoutheren 00087 * Removed compile time warning under Linux 00088 * 00089 * Revision 1.59 2003/12/07 05:50:49 csoutheren 00090 * Blocked operator = for PRegularExpression 00091 * 00092 * Revision 1.58 2003/12/04 13:10:38 csoutheren 00093 * Made PRegularExpression copy constructor private to avoid accidental usage (and subsequent crash) 00094 * 00095 * Revision 1.57 2003/05/14 00:46:47 rjongbloed 00096 * Added constructor to string lists/arrays etc that takes a single PString. 00097 * 00098 * Revision 1.56 2003/03/31 01:23:56 robertj 00099 * Added ReadFrom functions for standard container classes such as 00100 * PIntArray and PStringList etc 00101 * 00102 * Revision 1.55 2003/03/05 08:48:32 robertj 00103 * Added PStringArray::ToCharAray() function at suggestion of Ravelli Rossano 00104 * 00105 * Revision 1.54 2002/11/12 09:17:44 robertj 00106 * Added PString::NumCompare() as functional equivalent of strncmp(). 00107 * Added PSortedStringList::GetNextStringsIndex() to do searches of binary 00108 * tree on partal strings. 00109 * 00110 * Revision 1.53 2002/10/31 05:53:44 robertj 00111 * Now comprehensively stated that a PString is ALWAYS an 8 bit string as 00112 * there are far too many inheerent assumptions every to make it 16 bit. 00113 * Added UTF-8/UCS-2 conversion functions to PString. 00114 * 00115 * Revision 1.52 2002/09/16 01:08:59 robertj 00116 * Added #define so can select if #pragma interface/implementation is used on 00117 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00118 * 00119 * Revision 1.51 2002/08/14 00:43:39 robertj 00120 * Added ability to have fixed maximum length PStringStream's so does not do 00121 * unwanted malloc()'s while outputing data. 00122 * 00123 * Revision 1.50 2002/04/09 02:30:18 robertj 00124 * Removed GCC3 variable as __GNUC__ can be used instead, thanks jason Spence 00125 * 00126 * Revision 1.49 2002/02/15 04:29:31 robertj 00127 * Added PString::Empty() to return the primordial empty string. Saves on a 00128 * couple of memory allocations for every empty string ever used. 00129 * 00130 * Revision 1.48 2002/01/26 23:55:55 craigs 00131 * Changed for GCC 3.0 compatibility, thanks to manty@manty.net 00132 * 00133 * Revision 1.47 2002/01/22 01:03:57 craigs 00134 * Added operator += and operator + functions to PStringArray and PStringList 00135 * Added AppendString operator to PStringArray 00136 * 00137 * Revision 1.46 2001/10/17 05:09:22 robertj 00138 * Added contructors and assigmnent operators so integer types can be 00139 * automatically converted to strings. 00140 * 00141 * Revision 1.45 2001/08/11 07:57:30 rogerh 00142 * Add Mac OS Carbon changes from John Woods <jfw@jfwhome.funhouse.com> 00143 * 00144 * Revision 1.44 2001/04/18 04:10:15 robertj 00145 * Removed hash function for caseless strings as confuses mixed dictionaries. 00146 * 00147 * Revision 1.43 2001/04/18 01:20:58 robertj 00148 * Fixed problem with hash function for short strings, thanks Patrick Koorevaar. 00149 * Also fixed hash function for caseless strings. 00150 * 00151 * Revision 1.42 2001/02/21 03:38:37 robertj 00152 * Added ability to copy between various string lists/arrays etc during construction. 00153 * 00154 * Revision 1.41 2001/02/13 04:39:08 robertj 00155 * Fixed problem with operator= in container classes. Some containers will 00156 * break unless the copy is virtual (eg PStringStream's buffer pointers) so 00157 * needed to add a new AssignContents() function to all containers. 00158 * 00159 * Revision 1.40 1999/08/22 12:13:43 robertj 00160 * Fixed warning when using inlines on older GNU compiler 00161 * 00162 * Revision 1.39 1999/05/28 14:01:22 robertj 00163 * Added initialisers to string containers (list, sorted list and set). 00164 * 00165 * Revision 1.38 1999/03/09 09:34:05 robertj 00166 * Fixed typo's. 00167 * 00168 * Revision 1.37 1999/03/09 02:59:50 robertj 00169 * Changed comments to doc++ compatible documentation. 00170 * 00171 * Revision 1.36 1999/02/16 08:11:09 robertj 00172 * MSVC 6.0 compatibility changes. 00173 * 00174 * Revision 1.35 1998/09/23 06:21:12 robertj 00175 * Added open source copyright license. 00176 * 00177 * Revision 1.34 1998/01/26 00:33:46 robertj 00178 * Added FindRegEx function to PString that returns position and length. 00179 * Added Execute() functions to PRegularExpression that take PINDEX references instead of PIntArrays. 00180 * Added static function to PRegularExpression to escape all special operator characters in a string. 00181 * 00182 * Revision 1.33 1998/01/05 10:39:35 robertj 00183 * Fixed "typesafe" templates/macros for dictionaries, especially on GNU. 00184 * 00185 * Revision 1.32 1997/12/11 13:32:47 robertj 00186 * Added AsUnsigned() function to convert string to DWORD. 00187 * 00188 * Revision 1.31 1997/12/11 10:29:49 robertj 00189 * Added type correct Contains() function to dictionaries. 00190 * 00191 * Revision 1.30 1997/07/08 13:13:47 robertj 00192 * DLL support. 00193 * 00194 * Revision 1.29 1997/06/10 11:36:32 craigs 00195 * Added inline statements to allow compilation uder Unix 00196 * 00197 * Revision 1.28 1997/06/08 04:48:58 robertj 00198 * Added regular expressions. 00199 * Fixed non-template class descendent order. 00200 * 00201 * Revision 1.27 1997/05/16 12:10:12 robertj 00202 * Fixed G++ compatibility bug. 00203 * 00204 * Revision 1.26 1996/10/08 13:13:38 robertj 00205 * Added operator += and &= for char so no implicit PString construction. 00206 * 00207 * Revision 1.25 1996/09/14 12:52:39 robertj 00208 * Added operator! for !IsEmpty(). 00209 * 00210 * Revision 1.24 1996/08/17 10:00:25 robertj 00211 * Changes for Windows DLL support. 00212 * 00213 * Revision 1.23 1996/05/26 03:27:02 robertj 00214 * Compatibility to GNU 2.7.x 00215 * 00216 * Revision 1.22 1996/03/31 08:51:22 robertj 00217 * Added RemoveAt() function to remove entries from dictionaries. 00218 * 00219 * Revision 1.21 1996/03/10 13:15:50 robertj 00220 * Added operator() to template version. 00221 * 00222 * Revision 1.20 1996/02/19 13:17:33 robertj 00223 * Removed PCaselessString hash function to fix dictionary match failure. 00224 * Added operator() to do string dictionary lookup with default value. 00225 * 00226 * Revision 1.19 1996/02/08 12:19:16 robertj 00227 * Added new operators to PString for case insensitive compare and spaced concatenate. 00228 * 00229 * Revision 1.18 1996/01/24 14:43:15 robertj 00230 * Added initialisers to string dictionaries. 00231 * 00232 * Revision 1.17 1996/01/23 13:15:17 robertj 00233 * Added Replace() function to strings. 00234 * Mac Metrowerks compiler support. 00235 * String searching algorithm rewrite. 00236 * 00237 * Revision 1.16 1996/01/02 12:04:31 robertj 00238 * Mac OS compatibility changes. 00239 * Removed requirement that PArray elements have parameterless constructor.. 00240 * 00241 * Revision 1.15 1995/12/23 03:46:23 robertj 00242 * Added operators for include and exclude from string set. 00243 * 00244 * Revision 1.14 1995/10/14 15:02:56 robertj 00245 * Changed arrays to not break references, but strings still need to. 00246 * 00247 * Revision 1.13 1995/06/17 11:13:08 robertj 00248 * Documentation update. 00249 * 00250 * Revision 1.12 1995/06/17 00:43:40 robertj 00251 * Added flag for PStringArray constructor to create caseless strings. 00252 * 00253 * Revision 1.11 1995/06/04 12:34:57 robertj 00254 * Better C++ compatibility (with BC++) 00255 * 00256 * Revision 1.10 1995/04/02 09:27:23 robertj 00257 * Added "balloon" help. 00258 * 00259 * Revision 1.9 1995/03/14 12:42:16 robertj 00260 * Updated documentation to use HTML codes. 00261 * 00262 * Revision 1.8 1995/03/12 04:44:39 robertj 00263 * Fixed use of PCaselessString as dictionary key. 00264 * 00265 * Revision 1.7 1995/02/05 00:48:09 robertj 00266 * Fixed template version. 00267 * 00268 * Revision 1.6 1995/01/15 04:50:20 robertj 00269 * Added inlines on friend functions, required by GNU compiler. 00270 * 00271 * Revision 1.5 1995/01/10 11:43:41 robertj 00272 * Removed PString parameter in stdarg function for GNU C++ compatibility. 00273 * 00274 * Revision 1.4 1995/01/09 12:33:44 robertj 00275 * Removed unnecesary return value from I/O functions. 00276 * Changed function names due to Mac port. 00277 * 00278 * Revision 1.3 1994/12/21 11:53:21 robertj 00279 * Documentation and variable normalisation. 00280 * 00281 * Revision 1.2 1994/12/12 13:13:13 robertj 00282 * Fixed bugs in PString mods just made. 00283 * 00284 * Revision 1.1 1994/12/12 09:59:37 robertj 00285 * Initial revision 00286 * 00287 */ 00288 00289 #ifdef P_USE_PRAGMA 00290 #pragma interface 00291 #endif 00292 00293 #include <string> 00294 #include <vector> 00295 00297 // PString class 00298 00299 class PStringArray; 00300 class PRegularExpression; 00301 00336 class PString : public PCharArray { 00337 PCLASSINFO(PString, PCharArray); 00338 00339 // using namespace std; 00340 00341 public: 00347 PINLINE PString(); 00348 00352 PINLINE PString( 00353 const PString & str 00354 ); 00355 00358 PINLINE PString( 00359 const std::string & str 00360 ); 00361 00370 PString( 00371 const char * cstr 00372 ); 00373 00378 PString( 00379 const WORD * ustr 00380 ); 00381 00395 PString( 00396 const char * cstr, 00397 PINDEX len 00398 ); 00399 00410 PString( 00411 const WORD * ustr, 00412 PINDEX len 00413 ); 00414 00425 PString( 00426 const PWORDArray & ustr 00427 ); 00428 00437 PString( 00438 char ch 00439 ); 00440 00445 PString( 00446 short n 00447 ); 00448 00453 PString( 00454 unsigned short n 00455 ); 00456 00461 PString( 00462 int n 00463 ); 00464 00469 PString( 00470 unsigned int n 00471 ); 00472 00477 PString( 00478 long n 00479 ); 00480 00485 PString( 00486 unsigned long n 00487 ); 00488 00493 PString( 00494 PInt64 n 00495 ); 00496 00501 PString( 00502 PUInt64 n 00503 ); 00504 00505 00506 enum ConversionType { 00507 Pascal, // Data is a length byte followed by characters. 00508 Basic, // Data is two length bytes followed by characters. 00509 Literal, // Data is C language style string with \ escape codes. 00510 Signed, // Convert a signed integer to a string. 00511 Unsigned, // Convert an unsigned integer to a string. 00512 Decimal, // Convert a real number to a string in decimal format. 00513 Exponent, // Convert a real number to a string in exponent format. 00514 Printf, // Formatted output, sprintf() style function. 00515 NumConversionTypes 00516 }; 00517 /* Type of conversion to make in the conversion constructors. 00518 */ 00519 00520 /* Contruct a new string converting from the spcified data source into 00521 a string array. 00522 */ 00523 PString( 00524 ConversionType type, // Type of data source for conversion. 00525 const char * str, // String to convert. 00526 ... // Extra parameters for #sprintf()# call. 00527 ); 00528 PString( 00529 ConversionType type, // Type of data source for conversion. 00530 long value, // Integer value to convert. 00531 unsigned base = 10 // Number base to use for the integer conversion. 00532 ); 00533 PString( 00534 ConversionType type, // Type of data source for conversion. 00535 double value, // Floating point value to convert. 00536 unsigned places // Number of decimals in real number output. 00537 ); 00538 00546 PString & operator=( 00547 const PString & str 00548 ); 00549 00559 PString & operator=( 00560 const char * cstr 00561 ); 00562 00571 PString & operator=( 00572 char ch 00573 ); 00574 00579 PString & operator=( 00580 short n 00581 ); 00582 00587 PString & operator=( 00588 unsigned short n 00589 ); 00590 00595 PString & operator=( 00596 int n 00597 ); 00598 00603 PString & operator=( 00604 unsigned int n 00605 ); 00606 00611 PString & operator=( 00612 long n 00613 ); 00614 00619 PString & operator=( 00620 unsigned long n 00621 ); 00622 00627 PString & operator=( 00628 PInt64 n 00629 ); 00630 00635 PString & operator=( 00636 PUInt64 n 00637 ); 00638 00641 virtual PString & MakeEmpty(); 00642 00645 static PString Empty(); 00647 00654 virtual PObject * Clone() const; 00655 00665 virtual Comparison Compare( 00666 const PObject & obj 00667 ) const; 00668 00671 virtual void PrintOn( 00672 ostream & strm 00673 ) const; 00674 00680 virtual void ReadFrom( 00681 istream & strm 00682 ); 00683 00697 virtual PINDEX HashFunction() const; 00699 00714 virtual BOOL SetSize( 00715 PINDEX newSize 00716 ); 00717 00726 virtual BOOL IsEmpty() const; 00727 00736 virtual BOOL MakeUnique(); 00738 00739 00752 BOOL MakeMinimumSize(); 00753 00762 PINLINE PINDEX GetLength() const; 00763 00770 bool operator!() const; 00772 00781 PString operator+( 00782 const PString & str 00783 ) const; 00784 00796 PString operator+( 00797 const char * cstr 00798 ) const; 00799 00811 PString operator+( 00812 char ch 00813 ) const; 00814 00826 friend PString operator+( 00827 const char * cstr, 00828 const PString & str 00829 ); 00830 00842 friend PString operator+( 00843 char c, 00844 const PString & str 00845 ); 00846 00852 PString & operator+=( 00853 const PString & str 00854 ); 00855 00865 PString & operator+=( 00866 const char * cstr 00867 ); 00868 00878 PString & operator+=( 00879 char ch 00880 ); 00881 00882 00889 PString operator&( 00890 const PString & str 00891 ) const; 00892 00909 PString operator&( 00910 const char * cstr 00911 ) const; 00912 00929 PString operator&( 00930 char ch 00931 ) const; 00932 00949 friend PString operator&( 00950 const char * cstr, 00951 const PString & str 00952 ); 00953 00970 friend PString operator&( 00971 char ch, 00972 const PString & str 00973 ); 00974 00980 PString & operator&=( 00981 const PString & str 00982 ); 00983 00998 PString & operator&=( 00999 const char * cstr 01000 ); 01001 01002 01017 PString & operator&=( 01018 char ch 01019 ); 01021 01022 01030 bool operator*=( 01031 const PString & str 01032 ) const; 01033 01041 bool operator==( 01042 const PObject & str 01043 ) const; 01044 01052 bool operator!=( 01053 const PObject & str 01054 ) const; 01055 01063 bool operator<( 01064 const PObject & str 01065 ) const; 01066 01074 bool operator>( 01075 const PObject & str 01076 ) const; 01077 01085 bool operator<=( 01086 const PObject & str 01087 ) const; 01088 01096 bool operator>=( 01097 const PObject & str 01098 ) const; 01099 01100 01111 bool operator*=( 01112 const char * cstr 01113 ) const; 01114 01125 bool operator==( 01126 const char * cstr 01127 ) const; 01128 01139 bool operator!=( 01140 const char * cstr 01141 ) const; 01142 01153 bool operator<( 01154 const char * cstr 01155 ) const; 01156 01167 bool operator>( 01168 const char * cstr 01169 ) const; 01170 01181 bool operator<=( 01182 const char * cstr 01183 ) const; 01184 01195 bool operator>=( 01196 const char * cstr 01197 ) const; 01198 01210 Comparison NumCompare( 01211 const PString & str, 01212 PINDEX count = P_MAX_INDEX, 01213 PINDEX offset = 0 01214 ) const; 01215 01227 Comparison NumCompare( 01228 const char * cstr, 01229 PINDEX count = P_MAX_INDEX, 01230 PINDEX offset = 0 01231 ) const; 01233 01234 01238 PINDEX Find( 01239 char ch, 01240 PINDEX offset = 0 01241 ) const; 01242 01244 PINDEX Find( 01245 const PString & str, 01246 PINDEX offset = 0 01247 ) const; 01248 01249 /* Locate the position within the string of the character or substring. The 01250 search will begin at the character offset provided. 01251 01252 If #offset# is beyond the length of the string, then the 01253 function will always return #P_MAX_INDEX#. 01254 01255 The matching will be for identical character or string. If a search 01256 ignoring case is required then the string should be converted to a 01257 #PCaselessString# before the search is made. 01258 01259 @return 01260 position of character or substring in the string, or P_MAX_INDEX if the 01261 character or substring is not in the string. 01262 */ 01263 PINDEX Find( 01264 const char * cstr, 01265 PINDEX offset = 0 01266 ) const; 01267 01269 PINDEX FindLast( 01270 char ch, 01271 PINDEX offset = P_MAX_INDEX 01272 ) const; 01273 01275 PINDEX FindLast( 01276 const PString & str, 01277 PINDEX offset = P_MAX_INDEX 01278 ) const; 01279 01297 PINDEX FindLast( 01298 const char * cstr, 01299 PINDEX offset = P_MAX_INDEX 01300 ) const; 01301 01303 PINDEX FindOneOf( 01304 const PString & set, 01305 PINDEX offset = 0 01306 ) const; 01307 01322 PINDEX FindOneOf( 01323 const char * cset, 01324 PINDEX offset = 0 01325 ) const; 01326 01337 PINDEX FindRegEx( 01338 const PRegularExpression & regex, 01339 PINDEX offset = 0 01340 ) const; 01341 01352 BOOL FindRegEx( 01353 const PRegularExpression & regex, 01354 PINDEX & pos, 01355 PINDEX & len, 01356 PINDEX offset = 0, 01357 PINDEX maxPos = P_MAX_INDEX 01358 ) const; 01359 01360 01371 void Replace( 01372 const PString & target, 01373 const PString & subs, 01374 BOOL all = FALSE, 01375 PINDEX offset = 0 01376 ); 01377 01385 void Splice( 01386 const PString & str, 01387 PINDEX pos, 01388 PINDEX len = 0 01389 ); 01390 01398 void Splice( 01399 const char * cstr, 01400 PINDEX pos, 01401 PINDEX len = 0 01402 ); 01403 01410 void Delete( 01411 PINDEX start, 01412 PINDEX len 01413 ); 01415 01416 01436 PString operator()( 01437 PINDEX start, 01438 PINDEX end 01439 ) const; 01440 01455 PString Left( 01456 PINDEX len 01457 ) const; 01458 01473 PString Right( 01474 PINDEX len 01475 ) const; 01476 01493 PString Mid( 01494 PINDEX start, 01495 PINDEX len = P_MAX_INDEX 01496 ) const; 01497 01498 01506 PString LeftTrim() const; 01507 01515 PString RightTrim() const; 01516 01525 PString Trim() const; 01526 01527 01536 PString ToLower() const; 01537 01546 PString ToUpper() const; 01547 01548 01550 PStringArray Tokenise( 01551 const PString & separators, 01553 BOOL onePerSeparator = TRUE 01555 ) const; 01578 PStringArray Tokenise( 01579 const char * cseparators, 01581 BOOL onePerSeparator = TRUE 01583 ) const; 01584 01598 PStringArray Lines() const; 01600 01617 PString & sprintf( 01618 const char * cfmt, 01619 ... 01620 ); 01621 01636 friend PString psprintf( 01637 const char * cfmt, 01638 ... 01639 ); 01640 01642 PString & vsprintf( 01643 const PString & fmt, 01644 va_list args 01645 ); 01660 PString & vsprintf( 01661 const char * cfmt, 01662 va_list args 01663 ); 01664 01666 friend PString pvsprintf( 01667 const char * cfmt, 01668 va_list args 01669 ); 01684 friend PString pvsprintf( 01685 const PString & fmt, 01686 va_list args 01687 ); 01688 01689 01702 long AsInteger( 01703 unsigned base = 10 01704 ) const; 01717 DWORD AsUnsigned( 01718 unsigned base = 10 01719 ) const; 01733 PInt64 AsInt64( 01734 unsigned base = 10 01735 ) const; 01749 PUInt64 AsUnsigned64( 01750 unsigned base = 10 01751 ) const; 01752 01763 double AsReal() const; 01764 01768 PWORDArray AsUCS2() const; 01769 01780 PBYTEArray ToPascal() const; 01781 01790 PString ToLiteral() const; 01791 01799 operator const unsigned char *() const; 01800 01802 01803 01804 protected: 01805 void InternalFromUCS2( 01806 const WORD * ptr, 01807 PINDEX len 01808 ); 01809 virtual Comparison InternalCompare( 01810 PINDEX offset, // Offset into string to compare. 01811 char c // Character to compare against. 01812 ) const; 01813 virtual Comparison InternalCompare( 01814 PINDEX offset, // Offset into string to compare. 01815 PINDEX length, // Number of characters to compare. 01816 const char * cstr // C string to compare against. 01817 ) const; 01818 /* Internal function to compare the current string value against the 01819 specified C string. 01820 01821 @return 01822 relative rank of the two strings. 01823 */ 01824 01825 PString(int dummy, const PString * str); 01826 }; 01827 01828 01830 01840 class PCaselessString : public PString 01841 { 01842 PCLASSINFO(PCaselessString, PString); 01843 01844 public: 01847 PCaselessString(); 01848 01852 PCaselessString( 01853 const char * cstr 01854 ); 01855 01860 PCaselessString( 01861 const PString & str 01862 ); 01863 01864 01872 PCaselessString & operator=( 01873 const PString & str 01874 ); 01875 01885 PCaselessString & operator=( 01886 const char * cstr 01887 ); 01888 01897 PCaselessString & operator=( 01898 char ch 01899 ); 01900 01901 01902 // Overrides from class PObject 01907 virtual PObject * Clone() const; 01908 01909 protected: 01910 // Overrides from class PString 01911 virtual Comparison InternalCompare( 01912 PINDEX offset, // Offset into string to compare. 01913 char c // Character to compare against. 01914 ) const; 01915 virtual Comparison InternalCompare( 01916 PINDEX offset, // Offset into string to compare. 01917 PINDEX length, // Number of characters to compare. 01918 const char * cstr // C string to compare against. 01919 ) const; 01920 /* Internal function to compare the current string value against the 01921 specified C string. 01922 01923 @return 01924 relative rank of the two strings or characters. 01925 */ 01926 01927 PCaselessString(int dummy, const PCaselessString * str); 01928 }; 01929 01931 01932 class PStringStream; 01933 01940 class PStringStream : public PString, public iostream 01941 { 01942 PCLASSINFO(PStringStream, PString); 01943 01944 public: 01950 PStringStream(); 01951 01956 PStringStream( 01957 PINDEX fixedBufferSize 01958 ); 01959 01966 PStringStream( 01967 const PString & str 01968 ); 01969 01974 PStringStream( 01975 const char * cstr 01976 ); 01977 01980 virtual PString & MakeEmpty(); 01981 01993 PStringStream & operator=( 01994 const PStringStream & strm 01995 ); 01996 02008 PStringStream & operator=( 02009 const PString & str 02010 ); 02011 02027 PStringStream & operator=( 02028 const char * cstr 02029 ); 02030 02039 PStringStream & operator=( 02040 char ch 02041 ); 02042 02043 02045 virtual ~PStringStream(); 02046 02047 02048 protected: 02049 virtual void AssignContents(const PContainer & cont); 02050 02051 private: 02052 PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { } 02053 02054 class Buffer : public streambuf { 02055 public: 02056 Buffer(PStringStream & str, PINDEX size); 02057 Buffer(const Buffer & sbuf); 02058 Buffer & operator=(const Buffer & sbuf); 02059 virtual int overflow(int=EOF); 02060 virtual int underflow(); 02061 virtual int sync(); 02062 #if __USE_STL__ 02063 virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out); 02064 virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out); 02065 #else 02066 virtual streampos seekoff(streamoff, ios::seek_dir, int); 02067 #endif 02068 PStringStream & string; 02069 BOOL fixedBufferSize; 02070 }; 02071 }; 02072 02073 02074 class PStringList; 02075 class PSortedStringList; 02076 02089 #ifdef DOC_PLUS_PLUS 02090 class PStringArray : public PArray { 02091 #endif 02092 PDECLARE_ARRAY(PStringArray, PString); 02093 public: 02100 PStringArray( 02101 PINDEX count, 02102 char const * const * strarr, 02103 BOOL caseless = FALSE 02104 ); 02107 PStringArray( 02108 const PString & str 02109 ); 02112 PStringArray( 02113 const PStringList & list 02114 ); 02117 PStringArray( 02118 const PSortedStringList & list 02119 ); 02120 02124 PStringArray( 02125 const std::vector<PString> & vec 02126 ) 02127 { 02128 for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r) 02129 AppendString(*r); 02130 } 02131 02135 PStringArray( 02136 const std::vector<std::string> & vec 02137 ) 02138 { 02139 for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r) 02140 AppendString(PString(*r)); 02141 } 02143 02151 virtual void ReadFrom( 02152 istream &strm // Stream to read the objects contents from. 02153 ); 02155 02164 PINDEX GetStringsIndex( 02165 const PString & str 02166 ) const; 02167 02168 inline PString & operator[]( 02169 PINDEX index // Index position in the collection of the object. 02170 ) const { return PStringArray_PTemplate::operator[](index); } 02171 02179 PString & operator[]( 02180 PINDEX index 02181 ); 02182 02185 PINDEX AppendString( 02186 const PString & str 02187 ); 02188 02194 PStringArray & operator +=(const PStringArray & array); 02195 PStringArray & operator +=(const PString & str); 02196 02197 02204 PStringArray operator + (const PStringArray & array); 02205 PStringArray operator + (const PString & str); 02206 02214 char ** ToCharArray( 02215 PCharArray * storage = NULL 02216 ) const; 02218 }; 02219 02220 02233 #ifdef DOC_PLUS_PLUS 02234 class PStringList : public PList { 02235 #endif 02236 PDECLARE_LIST(PStringList, PString); 02237 public: 02242 PStringList( 02243 PINDEX count, 02244 char const * const * strarr, 02245 BOOL caseless = FALSE 02246 ); 02249 PStringList( 02250 const PString & str 02251 ); 02254 PStringList( 02255 const PStringArray & array 02256 ); 02259 PStringList( 02260 const PSortedStringList & list 02261 ); 02263 02271 virtual void ReadFrom( 02272 istream &strm // Stream to read the objects contents from. 02273 ); 02275 02280 PINDEX AppendString( 02281 const PString & str 02282 ); 02283 02286 PINDEX InsertString( 02287 const PString & before, 02288 const PString & str 02289 ); 02290 02294 PINDEX GetStringsIndex( 02295 const PString & str 02296 ) const; 02297 02303 PStringList & operator +=(const PStringList & list); 02304 PStringList & operator +=(const PString & str); 02305 02306 02313 PStringList operator + (const PStringList & array); 02314 PStringList operator + (const PString & str); 02315 02317 }; 02318 02319 02332 #ifdef DOC_PLUS_PLUS 02333 class PSortedStringList : public PSortedList { 02334 #endif 02335 PDECLARE_SORTED_LIST(PSortedStringList, PString); 02336 public: 02341 PSortedStringList( 02342 PINDEX count, 02343 char const * const * strarr, 02344 BOOL caseless = FALSE 02345 ); 02348 PSortedStringList( 02349 const PString & str 02350 ); 02353 PSortedStringList( 02354 const PStringArray & array 02355 ); 02358 PSortedStringList( 02359 const PStringList & list 02360 ); 02362 02370 virtual void ReadFrom( 02371 istream &strm // Stream to read the objects contents from. 02372 ); 02374 02380 PINDEX AppendString( 02381 const PString & str 02382 ); 02383 02387 PINDEX GetStringsIndex( 02388 const PString & str 02389 ) const; 02390 02395 PINDEX GetNextStringsIndex( 02396 const PString & str 02397 ) const; 02399 02400 protected: 02401 PINDEX InternalStringSelect( 02402 const char * str, 02403 PINDEX len, 02404 Element * thisElement 02405 ) const; 02406 }; 02407 02408 02425 #ifdef DOC_PLUS_PLUS 02426 class PStringSet : public PSet { 02427 #endif 02428 PDECLARE_SET(PStringSet, PString, TRUE); 02429 public: 02434 PStringSet( 02435 PINDEX count, 02436 char const * const * strarr, 02437 BOOL caseless = FALSE 02438 ); 02441 PStringSet( 02442 const PString & str 02443 ); 02445 02453 virtual void ReadFrom( 02454 istream &strm // Stream to read the objects contents from. 02455 ); 02457 02461 void Include( 02462 const PString & key 02463 ); 02465 PStringSet & operator+=( 02466 const PString & key 02467 ); 02469 void Exclude( 02470 const PString & key 02471 ); 02473 PStringSet & operator-=( 02474 const PString & key 02475 ); 02477 }; 02478 02479 02480 #ifdef PHAS_TEMPLATES 02481 02489 template <class K> class PStringDictionary : public PAbstractDictionary 02490 { 02491 PCLASSINFO(PStringDictionary, PAbstractDictionary); 02492 02493 public: 02502 PStringDictionary() 02503 : PAbstractDictionary() { } 02505 02512 virtual PObject * Clone() const 02513 { return PNEW PStringDictionary(0, this); } 02515 02530 const PString & operator[](const K & key) const 02531 { return (const PString &)GetRefAt(key); } 02532 02546 PString operator()(const K & key, const char * dflt = "") const 02547 { if (AbstractContains(key)) return (*this)[key]; return dflt; } 02548 02557 BOOL Contains( 02558 const K & key // Key to look for in the dictionary. 02559 ) const { return AbstractContains(key); } 02560 02569 virtual PString * RemoveAt( 02570 const K & key // Key for position in dictionary to get object. 02571 ) { PString * s = GetAt(key); AbstractSetAt(key, NULL); return s; } 02572 02579 virtual PString * GetAt( 02580 const K & key // Key for position in dictionary to get object. 02581 ) const { return (PString *)AbstractGetAt(key); } 02582 02591 virtual BOOL SetDataAt( 02592 PINDEX index, // Ordinal index in the dictionary. 02593 const PString & str // New string value to put into the dictionary. 02594 ) { return PAbstractDictionary::SetDataAt(index, PNEW PString(str)); } 02595 02607 virtual BOOL SetAt( 02608 const K & key, // Key for position in dictionary to add object. 02609 const PString & str // New string value to put into the dictionary. 02610 ) { return AbstractSetAt(key, PNEW PString(str)); } 02611 02623 const K & GetKeyAt(PINDEX index) const 02624 { return (const K &)AbstractGetKeyAt(index); } 02625 02637 PString & GetDataAt(PINDEX index) const 02638 { return (PString &)AbstractGetDataAt(index); } 02640 02641 protected: 02642 PStringDictionary(int dummy, const PStringDictionary * c) 02643 : PAbstractDictionary(dummy, c) { } 02644 }; 02645 02646 02661 #define PDECLARE_STRING_DICTIONARY(cls, K) \ 02662 PDECLARE_CLASS(cls, PStringDictionary<K>) \ 02663 protected: \ 02664 cls(int dummy, const cls * c) \ 02665 : PStringDictionary<K>(dummy, c) { } \ 02666 public: \ 02667 cls() \ 02668 : PStringDictionary<K>() { } \ 02669 virtual PObject * Clone() const \ 02670 { return PNEW cls(0, this); } \ 02671 02672 02685 #define PSTRING_DICTIONARY(cls, K) typedef PStringDictionary<K> cls 02686 02687 02688 #else // PHAS_TEMPLATES 02689 02690 02691 #define PSTRING_DICTIONARY(cls, K) \ 02692 class cls : public PAbstractDictionary { \ 02693 PCLASSINFO(cls, PAbstractDictionary) \ 02694 protected: \ 02695 inline cls(int dummy, const cls * c) \ 02696 : PAbstractDictionary(dummy, c) { } \ 02697 public: \ 02698 inline cls() \ 02699 : PAbstractDictionary() { } \ 02700 inline PObject * Clone() const \ 02701 { return PNEW cls(0, this); } \ 02702 inline PString & operator[](const K & key) const \ 02703 { return (PString &)GetRefAt(key); } \ 02704 inline PString operator()(const K & key, const char * dflt = "") const \ 02705 { if (Contains(key)) return (PString &)GetRefAt(key); return dflt; } \ 02706 virtual BOOL Contains(const K & key) const \ 02707 { return AbstractContains(key); } \ 02708 virtual PString * RemoveAt(const K & key) \ 02709 { PString * s = GetAt(key); AbstractSetAt(key, NULL); return s; } \ 02710 virtual PString * GetAt(const K & key) const \ 02711 { return (PString *)AbstractGetAt(key); } \ 02712 virtual BOOL SetDataAt(PINDEX index, const PString & str) \ 02713 { return PAbstractDictionary::SetDataAt(index,PNEW PString(str));} \ 02714 virtual BOOL SetAt(const K & key, const PString & str) \ 02715 { return AbstractSetAt(key, PNEW PString(str)); } \ 02716 inline const K & GetKeyAt(PINDEX index) const \ 02717 { return (const K &)AbstractGetKeyAt(index); } \ 02718 inline PString & GetDataAt(PINDEX index) const \ 02719 { return (PString &)AbstractGetDataAt(index); } \ 02720 } 02721 02722 #define PDECLARE_STRING_DICTIONARY(cls, K) \ 02723 PSTRING_DICTIONARY(cls##_PTemplate, K); \ 02724 PDECLARE_CLASS(cls, cls##_PTemplate) \ 02725 protected: \ 02726 cls(int dummy, const cls * c) \ 02727 : cls##_PTemplate(dummy, c) { } \ 02728 public: \ 02729 cls() \ 02730 : cls##_PTemplate() { } \ 02731 virtual PObject * Clone() const \ 02732 { return PNEW cls(0, this); } \ 02733 02734 #endif // PHAS_TEMPLATES 02735 02736 02751 #ifdef DOC_PLUS_PLUS 02752 class POrdinalToString : public PStringDictionary { 02753 #endif 02754 PDECLARE_STRING_DICTIONARY(POrdinalToString, POrdinalKey); 02755 public: 02758 02759 struct Initialiser { 02761 PINDEX key; 02763 const char * value; 02764 }; 02767 POrdinalToString( 02768 PINDEX count, 02769 const Initialiser * init 02770 ); 02772 02780 virtual void ReadFrom( 02781 istream &strm // Stream to read the objects contents from. 02782 ); 02784 }; 02785 02798 #ifdef DOC_PLUS_PLUS 02799 class PStringToOrdinal : public POrdinalDictionary { 02800 #endif 02801 PDECLARE_ORDINAL_DICTIONARY(PStringToOrdinal, PString); 02802 public: 02805 02806 struct Initialiser { 02808 const char * key; 02810 PINDEX value; 02811 }; 02814 PStringToOrdinal( 02815 PINDEX count, 02816 const Initialiser * init, 02817 BOOL caseless = FALSE 02818 ); 02820 02828 virtual void ReadFrom( 02829 istream &strm // Stream to read the objects contents from. 02830 ); 02832 }; 02833 02834 02848 #ifdef DOC_PLUS_PLUS 02849 class PStringToString : public PStringDictionary { 02850 #endif 02851 PDECLARE_STRING_DICTIONARY(PStringToString, PString); 02852 public: 02855 02856 struct Initialiser { 02858 const char * key; 02860 const char * value; 02861 }; 02864 PStringToString( 02865 PINDEX count, 02866 const Initialiser * init, 02867 BOOL caselessKeys = FALSE, 02868 BOOL caselessValues = FALSE 02869 ); 02871 02879 virtual void ReadFrom( 02880 istream &strm // Stream to read the objects contents from. 02881 ); 02883 }; 02884 02885 02891 class PRegularExpression : public PObject 02892 { 02893 PCLASSINFO(PRegularExpression, PObject); 02894 02895 public: 02898 02899 enum { 02901 Extended = 1, 02903 IgnoreCase = 2, 02908 AnchorNewLine = 4 02909 }; 02911 enum { 02918 NotBeginningOfLine = 1, 02920 NotEndofLine = 2 02921 }; 02922 02924 PRegularExpression(); 02925 02928 PRegularExpression( 02929 const PString & pattern, 02930 int flags = IgnoreCase 02931 ); 02932 02935 PRegularExpression( 02936 const char * cpattern, 02937 int flags = IgnoreCase 02938 ); 02939 02943 PRegularExpression( 02944 const PRegularExpression & 02945 ); 02946 02950 PRegularExpression & operator =( 02951 const PRegularExpression & 02952 ); 02953 02955 ~PRegularExpression(); 02957 02960 02961 enum ErrorCodes { 02963 NoError = 0, 02965 NoMatch, 02966 02967 // POSIX regcomp return error codes. (In the order listed in the standard.) 02969 BadPattern, 02971 CollateError, 02973 BadClassType, 02975 BadEscape, 02977 BadSubReg, 02979 UnmatchedBracket, 02981 UnmatchedParen, 02983 UnmatchedBrace, 02985 BadBR, 02987 RangeError, 02989 OutOfMemory, 02991 BadRepitition, 02992 02993 /* Error codes we've added. */ 02995 PrematureEnd, 02997 TooBig, 02999 UnmatchedRParen, 03001 NotCompiled 03002 }; 03003 03009 ErrorCodes GetErrorCode() const; 03010 03017 PString GetErrorText() const; 03019 03023 BOOL Compile( 03024 const PString & pattern, 03025 int flags = IgnoreCase 03026 ); 03034 BOOL Compile( 03035 const char * cpattern, 03036 int flags = IgnoreCase 03037 ); 03038 03039 03041 BOOL Execute( 03042 const PString & str, 03043 PINDEX & start, 03044 int flags = 0 03045 ) const; 03047 BOOL Execute( 03048 const PString & str, 03049 PINDEX & start, 03050 PINDEX & len, 03051 int flags = 0 03052 ) const; 03054 BOOL Execute( 03055 const char * cstr, 03056 PINDEX & start, 03057 int flags = 0 03058 ) const; 03060 BOOL Execute( 03061 const char * cstr, 03062 PINDEX & start, 03063 PINDEX & len, 03064 int flags = 0 03065 ) const; 03067 BOOL Execute( 03068 const PString & str, 03069 PIntArray & starts, 03070 int flags = 0 03071 ) const; 03073 BOOL Execute( 03074 const PString & str, 03075 PIntArray & starts, 03076 PIntArray & ends, 03077 int flags = 0 03078 ) const; 03080 BOOL Execute( 03081 const char * cstr, 03082 PIntArray & starts, 03083 int flags = 0 03084 ) const; 03100 BOOL Execute( 03101 const char * cstr, 03102 PIntArray & starts, 03103 PIntArray & ends, 03104 int flags = 0 03105 ) const; 03107 03116 static PString EscapeString( 03117 const PString & str 03118 ); 03120 03121 protected: 03122 PString patternSaved; 03123 int flagsSaved; 03124 03125 void * expression; 03126 int lastError; 03127 }; 03128 03129 03130 // End Of File ///////////////////////////////////////////////////////////////

Generated on Sat Jul 24 15:35:56 2004 for PWLib by doxygen 1.3.7