Main Page | Namespace List | Class Hierarchy | Class List | Directories | 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.80.2.1  2005/02/04 05:19:08  csoutheren
00031  * Backported patches from Atlas-devel
00032  *
00033  * Revision 1.81  2004/12/22 04:04:36  dereksmithies
00034  * Modify description of parameters for PString::Replace()
00035  *
00036  * Revision 1.80  2004/11/23 11:33:08  csoutheren
00037  * Fixed problem with RemoveAt returning invalid pointer in some cases,
00038  * and added extra documentation on this case.
00039  * Thanks to Diego Tartara for pointing out this potential problem
00040  *
00041  * Revision 1.79  2004/10/21 13:04:20  rjongbloed
00042  * Fixed possibility of const operator[] on PStringArray returning a NULL reference. This
00043  *   function should return a non-lvalue PString anyway as it is const!
00044  *
00045  * Revision 1.78  2004/08/16 08:49:59  csoutheren
00046  * Removed error when compiling with gcc
00047  *
00048  * Revision 1.77  2004/08/16 06:40:59  csoutheren
00049  * Added adapters template to make device plugins available via the abstract factory interface
00050  *
00051  * Revision 1.76  2004/06/01 05:54:18  csoutheren
00052  * Added <vector> and <string>
00053  *
00054  * Revision 1.75  2004/06/01 05:21:38  csoutheren
00055  * Added conversions between std::string and PString, and vector<PString> and PStringArray
00056  *
00057  * Revision 1.74  2004/05/04 11:10:36  rjongbloed
00058  * Fixed usage of MakeEmpty() with PStringStream.
00059  *
00060  * Revision 1.73  2004/04/18 04:33:36  rjongbloed
00061  * Changed all operators that return BOOL to return standard type bool. This is primarily
00062  *   for improved compatibility with std STL usage removing many warnings.
00063  *
00064  * Revision 1.72  2004/04/11 13:26:25  csoutheren
00065  * Removed namespace problems and removed warnings for Windows <string>
00066  *
00067  * Revision 1.71  2004/04/09 06:38:10  rjongbloed
00068  * Fixed compatibility with STL based streams, eg as used by VC++2003
00069  *
00070  * Revision 1.70  2004/04/09 03:42:34  csoutheren
00071  * Removed all usages of "virtual inline" and "inline virtual"
00072  *
00073  * Revision 1.69  2004/04/03 06:54:22  rjongbloed
00074  * Many and various changes to support new Visual C++ 2003
00075  *
00076  * Revision 1.68  2004/02/23 00:44:38  csoutheren
00077  * A completely different, other regex include hack to avoid requiring
00078  * the sources when using a header-file only environment
00079  *
00080  * Revision 1.67  2004/02/23 00:26:05  csoutheren
00081  * Finally, a generic and elegant fix for the regex include hacks.  Thanks to Roger Hardiman
00082  *
00083  * Revision 1.66  2004/02/11 05:09:14  csoutheren
00084  * Fixed problems with regex libraries on Solaris, and with host OS numbering
00085  * being a quoted string rather than a number. Thanks to Chad Attermann
00086  * Fixed problems SSL detection problems thanks to Michal Zygmuntowicz
00087  *
00088  * Revision 1.65  2004/02/08 11:13:11  rjongbloed
00089  * Fixed crash in heavily loaded multi-threaded systems using simultaneous sorted
00090  *   lists, Thanks Federico Pinna, Fabrizio Ammollo and the gang at Reitek S.p.A.
00091  *
00092  * Revision 1.64  2004/01/18 13:43:48  rjongbloed
00093  * Fixed broken PString::MakeEmpty() function and moved implementations to .inl file.
00094  *
00095  * Revision 1.63  2004/01/17 18:15:24  csoutheren
00096  * Fixed multi-threading problem with PString::Empty
00097  * Created PString::MakeEmpty for efficient emptying of existing strings
00098  *
00099  * Revision 1.62  2004/01/16 13:24:37  csoutheren
00100  * Changed PString::Empty to be thread-safe
00101  * Fixed PContainer::SetMinSize and PAbstractArray::SetSize, thanks to 123@call2ua.com
00102  * Fixed PString::FindLast, thanks to Andreas Sikkema
00103  *
00104  * Revision 1.61  2003/12/13 23:08:46  csoutheren
00105  * Changed PRegularExpression to allow a copy constructor and operator =
00106  *
00107  * Revision 1.60  2003/12/10 03:28:50  csoutheren
00108  * Removed compile time warning under Linux
00109  *
00110  * Revision 1.59  2003/12/07 05:50:49  csoutheren
00111  * Blocked operator = for PRegularExpression
00112  *
00113  * Revision 1.58  2003/12/04 13:10:38  csoutheren
00114  * Made PRegularExpression copy constructor private to avoid accidental usage (and subsequent crash)
00115  *
00116  * Revision 1.57  2003/05/14 00:46:47  rjongbloed
00117  * Added constructor to string lists/arrays etc that takes a single PString.
00118  *
00119  * Revision 1.56  2003/03/31 01:23:56  robertj
00120  * Added ReadFrom functions for standard container classes such as
00121  *   PIntArray and PStringList etc
00122  *
00123  * Revision 1.55  2003/03/05 08:48:32  robertj
00124  * Added PStringArray::ToCharAray() function at suggestion of Ravelli Rossano
00125  *
00126  * Revision 1.54  2002/11/12 09:17:44  robertj
00127  * Added PString::NumCompare() as functional equivalent of strncmp().
00128  * Added PSortedStringList::GetNextStringsIndex() to do searches of binary
00129  *   tree on partal strings.
00130  *
00131  * Revision 1.53  2002/10/31 05:53:44  robertj
00132  * Now comprehensively stated that a PString is ALWAYS an 8 bit string as
00133  *   there are far too many inheerent assumptions every to make it 16 bit.
00134  * Added UTF-8/UCS-2 conversion functions to PString.
00135  *
00136  * Revision 1.52  2002/09/16 01:08:59  robertj
00137  * Added #define so can select if #pragma interface/implementation is used on
00138  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00139  *
00140  * Revision 1.51  2002/08/14 00:43:39  robertj
00141  * Added ability to have fixed maximum length PStringStream's so does not do
00142  *   unwanted malloc()'s while outputing data.
00143  *
00144  * Revision 1.50  2002/04/09 02:30:18  robertj
00145  * Removed GCC3 variable as __GNUC__ can be used instead, thanks jason Spence
00146  *
00147  * Revision 1.49  2002/02/15 04:29:31  robertj
00148  * Added PString::Empty() to return the primordial empty string. Saves on a
00149  *   couple of memory allocations for every empty string ever used.
00150  *
00151  * Revision 1.48  2002/01/26 23:55:55  craigs
00152  * Changed for GCC 3.0 compatibility, thanks to manty@manty.net
00153  *
00154  * Revision 1.47  2002/01/22 01:03:57  craigs
00155  * Added operator += and operator + functions to PStringArray and PStringList
00156  * Added AppendString operator to PStringArray
00157  *
00158  * Revision 1.46  2001/10/17 05:09:22  robertj
00159  * Added contructors and assigmnent operators so integer types can be
00160  *   automatically converted to strings.
00161  *
00162  * Revision 1.45  2001/08/11 07:57:30  rogerh
00163  * Add Mac OS Carbon changes from John Woods <jfw@jfwhome.funhouse.com>
00164  *
00165  * Revision 1.44  2001/04/18 04:10:15  robertj
00166  * Removed hash function for caseless strings as confuses mixed dictionaries.
00167  *
00168  * Revision 1.43  2001/04/18 01:20:58  robertj
00169  * Fixed problem with hash function for short strings, thanks Patrick Koorevaar.
00170  * Also fixed hash function for caseless strings.
00171  *
00172  * Revision 1.42  2001/02/21 03:38:37  robertj
00173  * Added ability to copy between various string lists/arrays etc during construction.
00174  *
00175  * Revision 1.41  2001/02/13 04:39:08  robertj
00176  * Fixed problem with operator= in container classes. Some containers will
00177  *   break unless the copy is virtual (eg PStringStream's buffer pointers) so
00178  *   needed to add a new AssignContents() function to all containers.
00179  *
00180  * Revision 1.40  1999/08/22 12:13:43  robertj
00181  * Fixed warning when using inlines on older GNU compiler
00182  *
00183  * Revision 1.39  1999/05/28 14:01:22  robertj
00184  * Added initialisers to string containers (list, sorted list and set).
00185  *
00186  * Revision 1.38  1999/03/09 09:34:05  robertj
00187  * Fixed typo's.
00188  *
00189  * Revision 1.37  1999/03/09 02:59:50  robertj
00190  * Changed comments to doc++ compatible documentation.
00191  *
00192  * Revision 1.36  1999/02/16 08:11:09  robertj
00193  * MSVC 6.0 compatibility changes.
00194  *
00195  * Revision 1.35  1998/09/23 06:21:12  robertj
00196  * Added open source copyright license.
00197  *
00198  * Revision 1.34  1998/01/26 00:33:46  robertj
00199  * Added FindRegEx function to PString that returns position and length.
00200  * Added Execute() functions to PRegularExpression that take PINDEX references instead of PIntArrays.
00201  * Added static function to PRegularExpression to escape all special operator characters in a string.
00202  *
00203  * Revision 1.33  1998/01/05 10:39:35  robertj
00204  * Fixed "typesafe" templates/macros for dictionaries, especially on GNU.
00205  *
00206  * Revision 1.32  1997/12/11 13:32:47  robertj
00207  * Added AsUnsigned() function to convert string to DWORD.
00208  *
00209  * Revision 1.31  1997/12/11 10:29:49  robertj
00210  * Added type correct Contains() function to dictionaries.
00211  *
00212  * Revision 1.30  1997/07/08 13:13:47  robertj
00213  * DLL support.
00214  *
00215  * Revision 1.29  1997/06/10 11:36:32  craigs
00216  * Added inline statements to allow compilation uder Unix
00217  *
00218  * Revision 1.28  1997/06/08 04:48:58  robertj
00219  * Added regular expressions.
00220  * Fixed non-template class descendent order.
00221  *
00222  * Revision 1.27  1997/05/16 12:10:12  robertj
00223  * Fixed G++ compatibility bug.
00224  *
00225  * Revision 1.26  1996/10/08 13:13:38  robertj
00226  * Added operator += and &= for char so no implicit PString construction.
00227  *
00228  * Revision 1.25  1996/09/14 12:52:39  robertj
00229  * Added operator! for !IsEmpty().
00230  *
00231  * Revision 1.24  1996/08/17 10:00:25  robertj
00232  * Changes for Windows DLL support.
00233  *
00234  * Revision 1.23  1996/05/26 03:27:02  robertj
00235  * Compatibility to GNU 2.7.x
00236  *
00237  * Revision 1.22  1996/03/31 08:51:22  robertj
00238  * Added RemoveAt() function to remove entries from dictionaries.
00239  *
00240  * Revision 1.21  1996/03/10 13:15:50  robertj
00241  * Added operator() to template version.
00242  *
00243  * Revision 1.20  1996/02/19 13:17:33  robertj
00244  * Removed PCaselessString hash function to fix dictionary match failure.
00245  * Added operator() to do string dictionary lookup with default value.
00246  *
00247  * Revision 1.19  1996/02/08 12:19:16  robertj
00248  * Added new operators to PString for case insensitive compare and spaced concatenate.
00249  *
00250  * Revision 1.18  1996/01/24 14:43:15  robertj
00251  * Added initialisers to string dictionaries.
00252  *
00253  * Revision 1.17  1996/01/23 13:15:17  robertj
00254  * Added Replace() function to strings.
00255  * Mac Metrowerks compiler support.
00256  * String searching algorithm rewrite.
00257  *
00258  * Revision 1.16  1996/01/02 12:04:31  robertj
00259  * Mac OS compatibility changes.
00260  * Removed requirement that PArray elements have parameterless constructor..
00261  *
00262  * Revision 1.15  1995/12/23 03:46:23  robertj
00263  * Added operators for include and exclude from string set.
00264  *
00265  * Revision 1.14  1995/10/14 15:02:56  robertj
00266  * Changed arrays to not break references, but strings still need to.
00267  *
00268  * Revision 1.13  1995/06/17 11:13:08  robertj
00269  * Documentation update.
00270  *
00271  * Revision 1.12  1995/06/17 00:43:40  robertj
00272  * Added flag for PStringArray constructor to create caseless strings.
00273  *
00274  * Revision 1.11  1995/06/04 12:34:57  robertj
00275  * Better C++ compatibility (with BC++)
00276  *
00277  * Revision 1.10  1995/04/02 09:27:23  robertj
00278  * Added "balloon" help.
00279  *
00280  * Revision 1.9  1995/03/14 12:42:16  robertj
00281  * Updated documentation to use HTML codes.
00282  *
00283  * Revision 1.8  1995/03/12  04:44:39  robertj
00284  * Fixed use of PCaselessString as dictionary key.
00285  *
00286  * Revision 1.7  1995/02/05  00:48:09  robertj
00287  * Fixed template version.
00288  *
00289  * Revision 1.6  1995/01/15  04:50:20  robertj
00290  * Added inlines on friend functions, required by GNU compiler.
00291  *
00292  * Revision 1.5  1995/01/10  11:43:41  robertj
00293  * Removed PString parameter in stdarg function for GNU C++ compatibility.
00294  *
00295  * Revision 1.4  1995/01/09  12:33:44  robertj
00296  * Removed unnecesary return value from I/O functions.
00297  * Changed function names due to Mac port.
00298  *
00299  * Revision 1.3  1994/12/21  11:53:21  robertj
00300  * Documentation and variable normalisation.
00301  *
00302  * Revision 1.2  1994/12/12  13:13:13  robertj
00303  * Fixed bugs in PString mods just made.
00304  *
00305  * Revision 1.1  1994/12/12  09:59:37  robertj
00306  * Initial revision
00307  *
00308  */
00309 
00310 #ifdef P_USE_PRAGMA
00311 #pragma interface
00312 #endif
00313 
00314 #include <string>
00315 #include <vector>
00316 
00318 // PString class
00319 
00320 class PStringArray;
00321 class PRegularExpression;
00322 
00357 class PString : public PCharArray {
00358   PCLASSINFO(PString, PCharArray);
00359 
00360 //  using namespace std;
00361 
00362   public:
00368     PINLINE PString();
00369 
00373     PINLINE PString(
00374       const PString & str  
00375     );
00376 
00379     PINLINE PString(
00380       const std::string & str
00381     );
00382 
00391     PString(
00392       const char * cstr 
00393     );
00394 
00399     PString(
00400       const WORD * ustr 
00401     );
00402 
00416     PString(
00417       const char * cstr,  
00418       PINDEX len          
00419     );
00420 
00431     PString(
00432       const WORD * ustr,  
00433       PINDEX len          
00434     );
00435 
00446     PString(
00447       const PWORDArray & ustr 
00448     );
00449 
00458     PString(
00459       char ch    
00460     );
00461 
00466     PString(
00467       short n   
00468     );
00469 
00474     PString(
00475       unsigned short n   
00476     );
00477 
00482     PString(
00483       int n   
00484     );
00485 
00490     PString(
00491       unsigned int n   
00492     );
00493 
00498     PString(
00499       long n   
00500     );
00501 
00506     PString(
00507       unsigned long n   
00508     );
00509 
00514     PString(
00515       PInt64 n   
00516     );
00517 
00522     PString(
00523       PUInt64 n   
00524     );
00525 
00526  
00527     enum ConversionType {
00528       Pascal,   // Data is a length byte followed by characters.
00529       Basic,    // Data is two length bytes followed by characters.
00530       Literal,  // Data is C language style string with \ escape codes.
00531       Signed,   // Convert a signed integer to a string.
00532       Unsigned, // Convert an unsigned integer to a string.
00533       Decimal,  // Convert a real number to a string in decimal format.
00534       Exponent, // Convert a real number to a string in exponent format.
00535       Printf,   // Formatted output, sprintf() style function.
00536       NumConversionTypes
00537     };
00538     /* Type of conversion to make in the conversion constructors.
00539      */
00540 
00541     /* Contruct a new string converting from the spcified data source into
00542        a string array.
00543      */
00544     PString(
00545       ConversionType type,  // Type of data source for conversion.
00546       const char * str,    // String to convert.
00547       ...                 // Extra parameters for #sprintf()# call.
00548     );
00549     PString(
00550       ConversionType type,  // Type of data source for conversion.
00551       long value,           // Integer value to convert.
00552       unsigned base = 10    // Number base to use for the integer conversion.
00553     );
00554     PString(
00555       ConversionType type,  // Type of data source for conversion.
00556       double value,         // Floating point value to convert.
00557       unsigned places       // Number of decimals in real number output.
00558     );
00559 
00567     PString & operator=(
00568       const PString & str  
00569     );
00570 
00580     PString & operator=(
00581       const char * cstr  
00582     );
00583 
00592     PString & operator=(
00593       char ch            
00594     );
00595 
00600     PString & operator=(
00601       short n   
00602     );
00603 
00608     PString & operator=(
00609       unsigned short n   
00610     );
00611 
00616     PString & operator=(
00617       int n   
00618     );
00619 
00624     PString & operator=(
00625       unsigned int n   
00626     );
00627 
00632     PString & operator=(
00633       long n   
00634     );
00635 
00640     PString & operator=(
00641       unsigned long n   
00642     );
00643 
00648     PString & operator=(
00649       PInt64 n   
00650     );
00651 
00656     PString & operator=(
00657       PUInt64 n   
00658     );
00659 
00662     virtual PString & MakeEmpty();
00663 
00666     static PString Empty();
00668 
00675     virtual PObject * Clone() const;
00676 
00686     virtual Comparison Compare(
00687       const PObject & obj   
00688     ) const;
00689 
00692     virtual void PrintOn(
00693       ostream & strm  
00694     ) const;
00695 
00701     virtual void ReadFrom(
00702       istream & strm  
00703     );
00704 
00718     virtual PINDEX HashFunction() const;
00720 
00735     virtual BOOL SetSize(
00736       PINDEX newSize  
00737     );
00738 
00747     virtual BOOL IsEmpty() const;
00748 
00757     virtual BOOL MakeUnique();
00759 
00760 
00773     BOOL MakeMinimumSize();
00774 
00783     PINLINE PINDEX GetLength() const;
00784 
00791     bool operator!() const;
00793 
00802     PString operator+(
00803       const PString & str   
00804     ) const;
00805 
00817     PString operator+(
00818       const char * cstr  
00819     ) const;
00820 
00832     PString operator+(
00833       char ch   
00834     ) const;
00835 
00847     friend PString operator+(
00848       const char * cstr,    
00849       const PString & str   
00850     );
00851 
00863     friend PString operator+(
00864       char  c,              
00865       const PString & str   
00866     );
00867 
00873     PString & operator+=(
00874       const PString & str   
00875     );
00876 
00886     PString & operator+=(
00887       const char * cstr  
00888     );
00889 
00899     PString & operator+=(
00900       char ch   
00901     );
00902 
00903 
00910     PString operator&(
00911       const PString & str   
00912     ) const;
00913 
00930     PString operator&(
00931       const char * cstr  
00932     ) const;
00933 
00950     PString operator&(
00951       char ch   
00952     ) const;
00953 
00970     friend PString operator&(
00971       const char * cstr,    
00972       const PString & str   
00973     );
00974 
00991     friend PString operator&(
00992       char  ch,              
00993       const PString & str   
00994     );
00995 
01001     PString & operator&=(
01002       const PString & str   
01003     );
01004 
01019     PString & operator&=(
01020       const char * cstr  
01021     );
01022 
01023 
01038     PString & operator&=(
01039       char ch  
01040     );
01042 
01043 
01051     bool operator*=(
01052       const PString & str  
01053     ) const;
01054 
01062     bool operator==(
01063       const PObject & str  
01064     ) const;
01065 
01073     bool operator!=(
01074       const PObject & str  
01075     ) const;
01076 
01084     bool operator<(
01085       const PObject & str  
01086     ) const;
01087 
01095     bool operator>(
01096       const PObject & str  
01097     ) const;
01098 
01106     bool operator<=(
01107       const PObject & str  
01108     ) const;
01109 
01117     bool operator>=(
01118       const PObject & str  
01119     ) const;
01120 
01121 
01132     bool operator*=(
01133       const char * cstr  
01134     ) const;
01135 
01146     bool operator==(
01147       const char * cstr  
01148     ) const;
01149 
01160     bool operator!=(
01161       const char * cstr  
01162     ) const;
01163 
01174     bool operator<(
01175       const char * cstr  
01176     ) const;
01177 
01188     bool operator>(
01189       const char * cstr  
01190     ) const;
01191 
01202     bool operator<=(
01203       const char * cstr  
01204     ) const;
01205 
01216     bool operator>=(
01217       const char * cstr  
01218     ) const;
01219 
01231     Comparison NumCompare(
01232       const PString & str,        
01233       PINDEX count = P_MAX_INDEX, 
01234       PINDEX offset = 0           
01235     ) const;
01236 
01248     Comparison NumCompare(
01249       const char * cstr,          
01250       PINDEX count = P_MAX_INDEX, 
01251       PINDEX offset = 0           
01252     ) const;
01254 
01255 
01259     PINDEX Find(
01260       char ch,              
01261       PINDEX offset = 0     
01262     ) const;
01263 
01265     PINDEX Find(
01266       const PString & str,  
01267       PINDEX offset = 0     
01268     ) const;
01269 
01270     /* Locate the position within the string of the character or substring. The
01271        search will begin at the character offset provided.
01272        
01273        If #offset# is beyond the length of the string, then the
01274        function will always return #P_MAX_INDEX#.
01275        
01276        The matching will be for identical character or string. If a search
01277        ignoring case is required then the string should be converted to a
01278        #PCaselessString# before the search is made.
01279 
01280        @return
01281        position of character or substring in the string, or P_MAX_INDEX if the
01282        character or substring is not in the string.
01283      */
01284     PINDEX Find(
01285       const char * cstr,    
01286       PINDEX offset = 0     
01287     ) const;
01288 
01290     PINDEX FindLast(
01291       char ch,                     
01292       PINDEX offset = P_MAX_INDEX  
01293     ) const;
01294 
01296     PINDEX FindLast(
01297       const PString & str,         
01298       PINDEX offset = P_MAX_INDEX  
01299     ) const;
01300 
01318     PINDEX FindLast(
01319       const char * cstr,           
01320       PINDEX offset = P_MAX_INDEX  
01321     ) const;
01322 
01324     PINDEX FindOneOf(
01325       const PString & set,  
01326       PINDEX offset = 0     
01327     ) const;
01328 
01343     PINDEX FindOneOf(
01344       const char * cset,    
01345       PINDEX offset = 0     
01346     ) const;
01347 
01358     PINDEX FindRegEx(
01359       const PRegularExpression & regex, 
01360       PINDEX offset = 0                 
01361     ) const;
01362 
01373     BOOL FindRegEx(
01374       const PRegularExpression & regex, 
01375       PINDEX & pos,                     
01376       PINDEX & len,                     
01377       PINDEX offset = 0,                
01378       PINDEX maxPos = P_MAX_INDEX       
01379     ) const;
01380 
01381 
01392     void Replace(
01393       const PString & target,   
01394       const PString & subs,     
01395       BOOL all = FALSE,         
01396       PINDEX offset = 0         
01397     );
01398 
01406     void Splice(
01407       const PString & str,  
01408       PINDEX pos,           
01409       PINDEX len = 0        
01410     );
01411 
01419     void Splice(
01420       const char * cstr,    
01421       PINDEX pos,           
01422       PINDEX len = 0        
01423     );
01424 
01431     void Delete(
01432       PINDEX start,   
01433       PINDEX len      
01434     );
01436 
01437 
01457     PString operator()(
01458       PINDEX start,  
01459       PINDEX end     
01460     ) const;
01461 
01476     PString Left(
01477       PINDEX len   
01478     ) const;
01479 
01494     PString Right(
01495       PINDEX len   
01496     ) const;
01497 
01514     PString Mid(
01515       PINDEX start,             
01516       PINDEX len = P_MAX_INDEX  
01517     ) const;
01518 
01519 
01527     PString LeftTrim() const;
01528 
01536     PString RightTrim() const;
01537 
01546     PString Trim() const;
01547 
01548 
01557     PString ToLower() const;
01558 
01567     PString ToUpper() const;
01568 
01569 
01571     PStringArray Tokenise(
01572       const PString & separators,
01574       BOOL onePerSeparator = TRUE
01576     ) const;
01599     PStringArray Tokenise(
01600       const char * cseparators,
01602       BOOL onePerSeparator = TRUE
01604     ) const;
01605 
01619     PStringArray Lines() const;
01621 
01638     PString & sprintf(
01639       const char * cfmt,   
01640       ...                  
01641     );
01642 
01657     friend PString psprintf(
01658       const char * cfmt,   
01659       ...                  
01660     );
01661 
01663     PString & vsprintf(
01664       const PString & fmt, 
01665       va_list args         
01666     );
01681     PString & vsprintf(
01682       const char * cfmt,   
01683       va_list args         
01684     );
01685 
01687     friend PString pvsprintf(
01688       const char * cfmt,   
01689       va_list args         
01690     );
01705     friend PString pvsprintf(
01706       const PString & fmt, 
01707       va_list args         
01708     );
01709 
01710 
01723     long AsInteger(
01724       unsigned base = 10    
01725     ) const;
01738     DWORD AsUnsigned(
01739       unsigned base = 10    
01740     ) const;
01754     PInt64 AsInt64(
01755       unsigned base = 10    
01756     ) const;
01770     PUInt64 AsUnsigned64(
01771       unsigned base = 10    
01772     ) const;
01773 
01784     double AsReal() const;
01785      
01789     PWORDArray AsUCS2() const;
01790 
01801     PBYTEArray ToPascal() const;
01802 
01811     PString ToLiteral() const;
01812 
01820     operator const unsigned char *() const;
01821 
01823 
01824 
01825   protected:
01826     void InternalFromUCS2(
01827       const WORD * ptr,
01828       PINDEX len
01829     );
01830     virtual Comparison InternalCompare(
01831       PINDEX offset,      // Offset into string to compare.
01832       char c              // Character to compare against.
01833     ) const;
01834     virtual Comparison InternalCompare(
01835       PINDEX offset,      // Offset into string to compare.
01836       PINDEX length,      // Number of characters to compare.
01837       const char * cstr   // C string to compare against.
01838     ) const;
01839     /* Internal function to compare the current string value against the
01840        specified C string.
01841 
01842        @return
01843        relative rank of the two strings.
01844      */
01845 
01846     PString(int dummy, const PString * str);
01847 };
01848 
01849 
01851 
01861 class PCaselessString : public PString
01862 {
01863   PCLASSINFO(PCaselessString, PString);
01864 
01865   public:
01868     PCaselessString();
01869 
01873     PCaselessString(
01874       const char * cstr   
01875     );
01876 
01881     PCaselessString(
01882       const PString & str  
01883     );
01884 
01885 
01893     PCaselessString & operator=(
01894       const PString & str  
01895     );
01896 
01906     PCaselessString & operator=(
01907       const char * cstr  
01908     );
01909 
01918     PCaselessString & operator=(
01919       char ch            
01920     );
01921 
01922 
01923   // Overrides from class PObject
01928     virtual PObject * Clone() const;
01929 
01930   protected:
01931   // Overrides from class PString
01932     virtual Comparison InternalCompare(
01933       PINDEX offset,      // Offset into string to compare.
01934       char c              // Character to compare against.
01935     ) const;
01936     virtual Comparison InternalCompare(
01937       PINDEX offset,      // Offset into string to compare.
01938       PINDEX length,      // Number of characters to compare.
01939       const char * cstr   // C string to compare against.
01940     ) const;
01941     /* Internal function to compare the current string value against the
01942        specified C string.
01943 
01944        @return
01945        relative rank of the two strings or characters.
01946      */
01947 
01948     PCaselessString(int dummy, const PCaselessString * str);
01949 };
01950 
01952 
01953 class PStringStream;
01954 
01961 class PStringStream : public PString, public iostream
01962 {
01963   PCLASSINFO(PStringStream, PString);
01964 
01965   public:
01971     PStringStream();
01972 
01977     PStringStream(
01978       PINDEX fixedBufferSize
01979     );
01980 
01987     PStringStream(
01988       const PString & str   
01989     );
01990 
01995     PStringStream(
01996       const char * cstr   
01997     );
01998 
02001     virtual PString & MakeEmpty();
02002 
02014     PStringStream & operator=(
02015       const PStringStream & strm
02016     );
02017 
02029     PStringStream & operator=(
02030       const PString & str  
02031     );
02032 
02048     PStringStream & operator=(
02049       const char * cstr  
02050     );
02051 
02060     PStringStream & operator=(
02061       char ch            
02062     );
02063 
02064 
02066     virtual ~PStringStream();
02067 
02068 
02069   protected:
02070     virtual void AssignContents(const PContainer & cont);
02071 
02072   private:
02073     PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
02074 
02075     class Buffer : public streambuf {
02076       public:
02077         Buffer(PStringStream & str, PINDEX size);
02078         Buffer(const Buffer & sbuf);
02079         Buffer & operator=(const Buffer & sbuf);
02080         virtual int overflow(int=EOF);
02081         virtual int underflow();
02082         virtual int sync();
02083 #if __USE_STL__
02084         virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
02085         virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
02086 #else
02087         virtual streampos seekoff(streamoff, ios::seek_dir, int);
02088 #endif
02089         PStringStream & string;
02090         BOOL            fixedBufferSize;
02091     };
02092 };
02093 
02094 
02095 class PStringList;
02096 class PSortedStringList;
02097 
02110 #ifdef DOC_PLUS_PLUS
02111 class PStringArray : public PArray {
02112 #endif
02113   PDECLARE_ARRAY(PStringArray, PString);
02114   public:
02121     PStringArray(
02122       PINDEX count,                 
02123       char const * const * strarr,  
02124       BOOL caseless = FALSE         
02125     );
02128     PStringArray(
02129       const PString & str  
02130     );
02133     PStringArray(
02134       const PStringList & list  
02135     );
02138     PStringArray(
02139       const PSortedStringList & list  
02140     );
02141 
02145     PStringArray(
02146       const std::vector<PString> & vec
02147     )
02148     {
02149       for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02150         AppendString(*r);
02151     }
02152 
02156     PStringArray(
02157       const std::vector<std::string> & vec
02158     )
02159     {
02160       for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02161         AppendString(PString(*r));
02162     }
02163 
02167     template <typename stlContainer>
02168     static PStringArray container(
02169       const stlContainer & vec
02170     )
02171     {
02172       PStringArray list;
02173       for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02174         list.AppendString(PString(*r));
02175       return list;
02176     }
02177 
02179 
02187     virtual void ReadFrom(
02188       istream &strm   // Stream to read the objects contents from.
02189     );
02191 
02200     PINDEX GetStringsIndex(
02201       const PString & str 
02202     ) const;
02203 
02204     PString operator[](
02205       PINDEX index  // Index position in the collection of the object.
02206     ) const;
02207 
02215     PString & operator[](
02216       PINDEX index  
02217     );
02218 
02221     PINDEX AppendString(
02222       const PString & str 
02223     );
02224 
02230     PStringArray & operator +=(const PStringArray & array);
02231     PStringArray & operator +=(const PString & str);
02232 
02233 
02240     PStringArray operator + (const PStringArray & array);
02241     PStringArray operator + (const PString & str);
02242 
02250     char ** ToCharArray(
02251       PCharArray * storage = NULL
02252     ) const;
02254 };
02255 
02256 
02269 #ifdef DOC_PLUS_PLUS
02270 class PStringList : public PList {
02271 #endif
02272 PDECLARE_LIST(PStringList, PString);
02273   public:
02278     PStringList(
02279       PINDEX count,                 
02280       char const * const * strarr,  
02281       BOOL caseless = FALSE         
02282     );
02285     PStringList(
02286       const PString & str  
02287     );
02290     PStringList(
02291       const PStringArray & array  
02292     );
02295     PStringList(
02296       const PSortedStringList & list  
02297     );
02299 
02307     virtual void ReadFrom(
02308       istream &strm   // Stream to read the objects contents from.
02309     );
02311 
02316     PINDEX AppendString(
02317       const PString & str 
02318     );
02319 
02322     PINDEX InsertString(
02323       const PString & before,   
02324       const PString & str       
02325     );
02326 
02330     PINDEX GetStringsIndex(
02331       const PString & str   
02332     ) const;
02333 
02339     PStringList & operator +=(const PStringList & list);
02340     PStringList & operator +=(const PString & str);
02341 
02342 
02349     PStringList operator + (const PStringList & array);
02350     PStringList operator + (const PString & str);
02351 
02355     template <typename stlContainer>
02356     static PStringList container(
02357       const stlContainer & vec
02358     )
02359     {
02360       PStringList list;
02361       for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02362         list.AppendString(PString(*r));
02363       return list;
02364     }
02366 };
02367 
02368 
02381 #ifdef DOC_PLUS_PLUS
02382 class PSortedStringList : public PSortedList {
02383 #endif
02384 PDECLARE_SORTED_LIST(PSortedStringList, PString);
02385   public:
02390     PSortedStringList(
02391       PINDEX count,                 
02392       char const * const * strarr,  
02393       BOOL caseless = FALSE         
02394     );
02397     PSortedStringList(
02398       const PString & str  
02399     );
02402     PSortedStringList(
02403       const PStringArray & array  
02404     );
02407     PSortedStringList(
02408       const PStringList & list  
02409     );
02411 
02419     virtual void ReadFrom(
02420       istream &strm   // Stream to read the objects contents from.
02421     );
02423 
02429     PINDEX AppendString(
02430       const PString & str 
02431     );
02432 
02436     PINDEX GetStringsIndex(
02437       const PString & str   
02438     ) const;
02439 
02444     PINDEX GetNextStringsIndex(
02445       const PString & str   
02446     ) const;
02448 
02449   protected:
02450     PINDEX InternalStringSelect(
02451       const char * str,
02452       PINDEX len,
02453       Element * thisElement
02454     ) const;
02455 };
02456 
02457 
02474 #ifdef DOC_PLUS_PLUS
02475 class PStringSet : public PSet {
02476 #endif
02477 PDECLARE_SET(PStringSet, PString, TRUE);
02478   public:
02483     PStringSet(
02484       PINDEX count,                 
02485       char const * const * strarr,  
02486       BOOL caseless = FALSE         
02487     );
02490     PStringSet(
02491       const PString & str  
02492     );
02494 
02502     virtual void ReadFrom(
02503       istream &strm   // Stream to read the objects contents from.
02504     );
02506 
02510     void Include(
02511       const PString & key 
02512     );
02514     PStringSet & operator+=(
02515       const PString & key 
02516     );
02518     void Exclude(
02519       const PString & key 
02520     );
02522     PStringSet & operator-=(
02523       const PString & key 
02524     );
02526 };
02527 
02528 
02529 #ifdef PHAS_TEMPLATES
02530 
02538 template <class K> class PStringDictionary : public PAbstractDictionary
02539 {
02540   PCLASSINFO(PStringDictionary, PAbstractDictionary);
02541 
02542   public:
02551     PStringDictionary()
02552       : PAbstractDictionary() { }
02554 
02561     virtual PObject * Clone() const
02562       { return PNEW PStringDictionary(0, this); }
02564 
02579     const PString & operator[](const K & key) const
02580       { return (const PString &)GetRefAt(key); }
02581 
02595     PString operator()(const K & key, const char * dflt = "") const
02596       { if (AbstractContains(key)) return (*this)[key]; return dflt; }
02597 
02606     BOOL Contains(
02607       const K & key   // Key to look for in the dictionary.
02608       ) const { return AbstractContains(key); }
02609 
02621     virtual PString * RemoveAt(
02622       const K & key   // Key for position in dictionary to get object.
02623     ) {
02624         PString * s = GetAt(key); AbstractSetAt(key, NULL);
02625         return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s;
02626       }
02627 
02634     virtual PString * GetAt(
02635       const K & key   // Key for position in dictionary to get object.
02636     ) const { return (PString *)AbstractGetAt(key); }
02637 
02646     virtual BOOL SetDataAt(
02647       PINDEX index,        // Ordinal index in the dictionary.
02648       const PString & str  // New string value to put into the dictionary.
02649     ) { return PAbstractDictionary::SetDataAt(index, PNEW PString(str)); }
02650 
02662     virtual BOOL SetAt(
02663       const K & key,       // Key for position in dictionary to add object.
02664       const PString & str  // New string value to put into the dictionary.
02665     ) { return AbstractSetAt(key, PNEW PString(str)); }
02666 
02678     const K & GetKeyAt(PINDEX index) const
02679       { return (const K &)AbstractGetKeyAt(index); }
02680 
02692     PString & GetDataAt(PINDEX index) const
02693       { return (PString &)AbstractGetDataAt(index); }
02695 
02696   protected:
02697     PStringDictionary(int dummy, const PStringDictionary * c)
02698       : PAbstractDictionary(dummy, c) { }
02699 };
02700 
02701 
02716 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02717   PDECLARE_CLASS(cls, PStringDictionary<K>) \
02718   protected: \
02719     cls(int dummy, const cls * c) \
02720       : PStringDictionary<K>(dummy, c) { } \
02721   public: \
02722     cls() \
02723       : PStringDictionary<K>() { } \
02724     virtual PObject * Clone() const \
02725       { return PNEW cls(0, this); } \
02726 
02727 
02740 #define PSTRING_DICTIONARY(cls, K) typedef PStringDictionary<K> cls
02741 
02742 
02743 #else // PHAS_TEMPLATES
02744 
02745 
02746 #define PSTRING_DICTIONARY(cls, K) \
02747   class cls : public PAbstractDictionary { \
02748   PCLASSINFO(cls, PAbstractDictionary) \
02749   protected: \
02750     inline cls(int dummy, const cls * c) \
02751       : PAbstractDictionary(dummy, c) { } \
02752   public: \
02753     inline cls() \
02754       : PAbstractDictionary() { } \
02755     inline PObject * Clone() const \
02756       { return PNEW cls(0, this); } \
02757     inline PString & operator[](const K & key) const \
02758       { return (PString &)GetRefAt(key); } \
02759     inline PString operator()(const K & key, const char * dflt = "") const \
02760       { if (Contains(key)) return (PString &)GetRefAt(key); return dflt; } \
02761     virtual BOOL Contains(const K & key) const \
02762       { return AbstractContains(key); } \
02763     virtual PString * RemoveAt(const K & key) \
02764       { PString * s = GetAt(key); AbstractSetAt(key, NULL); \
02765         return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s; } \
02766     virtual PString * GetAt(const K & key) const \
02767       { return (PString *)AbstractGetAt(key); } \
02768     virtual BOOL SetDataAt(PINDEX index, const PString & str) \
02769       { return PAbstractDictionary::SetDataAt(index,PNEW PString(str));} \
02770     virtual BOOL SetAt(const K & key, const PString & str) \
02771       { return AbstractSetAt(key, PNEW PString(str)); } \
02772     inline const K & GetKeyAt(PINDEX index) const \
02773       { return (const K &)AbstractGetKeyAt(index); } \
02774     inline PString & GetDataAt(PINDEX index) const \
02775       { return (PString &)AbstractGetDataAt(index); } \
02776   }
02777 
02778 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02779   PSTRING_DICTIONARY(cls##_PTemplate, K); \
02780   PDECLARE_CLASS(cls, cls##_PTemplate) \
02781   protected: \
02782     cls(int dummy, const cls * c) \
02783       : cls##_PTemplate(dummy, c) { } \
02784   public: \
02785     cls() \
02786       : cls##_PTemplate() { } \
02787     virtual PObject * Clone() const \
02788       { return PNEW cls(0, this); } \
02789 
02790 #endif // PHAS_TEMPLATES
02791 
02792 
02807 #ifdef DOC_PLUS_PLUS
02808 class POrdinalToString : public PStringDictionary {
02809 #endif
02810 PDECLARE_STRING_DICTIONARY(POrdinalToString, POrdinalKey);
02811   public:
02814 
02815     struct Initialiser {
02817       PINDEX key;
02819       const char * value;
02820     };
02823     POrdinalToString(
02824       PINDEX count,                
02825       const Initialiser * init     
02826     );
02828 
02836     virtual void ReadFrom(
02837       istream &strm   // Stream to read the objects contents from.
02838     );
02840 };
02841 
02854 #ifdef DOC_PLUS_PLUS
02855 class PStringToOrdinal : public POrdinalDictionary {
02856 #endif
02857 PDECLARE_ORDINAL_DICTIONARY(PStringToOrdinal, PString);
02858   public:
02861 
02862     struct Initialiser {
02864       const char * key;
02866       PINDEX value;
02867     };
02870     PStringToOrdinal(
02871       PINDEX count,                
02872       const Initialiser * init,    
02873       BOOL caseless = FALSE        
02874     );
02876 
02884     virtual void ReadFrom(
02885       istream &strm   // Stream to read the objects contents from.
02886     );
02888 };
02889 
02890 
02904 #ifdef DOC_PLUS_PLUS
02905 class PStringToString : public PStringDictionary {
02906 #endif
02907 PDECLARE_STRING_DICTIONARY(PStringToString, PString);
02908   public:
02911 
02912     struct Initialiser {
02914       const char * key;
02916       const char * value;
02917     };
02920     PStringToString(
02921       PINDEX count,                
02922       const Initialiser * init,    
02923       BOOL caselessKeys = FALSE,   
02924       BOOL caselessValues = FALSE  
02925     );
02927 
02935     virtual void ReadFrom(
02936       istream &strm   // Stream to read the objects contents from.
02937     );
02939 };
02940 
02941 
02947 class PRegularExpression : public PObject
02948 {
02949   PCLASSINFO(PRegularExpression, PObject);
02950 
02951   public:
02954 
02955     enum {
02957       Extended = 1,
02959       IgnoreCase = 2,
02964       AnchorNewLine = 4
02965     };
02967     enum {
02974       NotBeginningOfLine = 1,
02976       NotEndofLine = 2
02977     };
02978 
02980     PRegularExpression();
02981 
02984     PRegularExpression(
02985       const PString & pattern,    
02986       int flags = IgnoreCase      
02987     );
02988 
02991     PRegularExpression(
02992       const char * cpattern,      
02993       int flags = IgnoreCase      
02994     );
02995 
02999     PRegularExpression(
03000       const PRegularExpression &
03001     );
03002 
03006     PRegularExpression & operator =(
03007       const PRegularExpression &
03008     );
03009 
03011     ~PRegularExpression();
03013 
03016 
03017     enum ErrorCodes {
03019       NoError = 0,          
03021       NoMatch,                
03022 
03023       // POSIX regcomp return error codes.  (In the order listed in the standard.)
03025       BadPattern,                 
03027       CollateError,               
03029       BadClassType,               
03031       BadEscape,                    
03033       BadSubReg,        
03035       UnmatchedBracket, 
03037       UnmatchedParen,           
03039       UnmatchedBrace,           
03041       BadBR,                    
03043       RangeError,                 
03045       OutOfMemory,              
03047       BadRepitition,            
03048 
03049       /* Error codes we've added.  */
03051       PrematureEnd,             
03053       TooBig,           
03055       UnmatchedRParen,  
03057       NotCompiled
03058     };
03059 
03065     ErrorCodes GetErrorCode() const;
03066 
03073     PString GetErrorText() const;
03075 
03079     BOOL Compile(
03080       const PString & pattern,    
03081       int flags = IgnoreCase      
03082     );
03090     BOOL Compile(
03091       const char * cpattern,      
03092       int flags = IgnoreCase      
03093     );
03094 
03095 
03097     BOOL Execute(
03098       const PString & str,    
03099       PINDEX & start,         
03100       int flags = 0           
03101     ) const;
03103     BOOL Execute(
03104       const PString & str,    
03105       PINDEX & start,         
03106       PINDEX & len,           
03107       int flags = 0           
03108     ) const;
03110     BOOL Execute(
03111       const char * cstr,      
03112       PINDEX & start,         
03113       int flags = 0           
03114     ) const;
03116     BOOL Execute(
03117       const char * cstr,      
03118       PINDEX & start,         
03119       PINDEX & len,           
03120       int flags = 0           
03121     ) const;
03123     BOOL Execute(
03124       const PString & str,    
03125       PIntArray & starts,     
03126       int flags = 0           
03127     ) const;
03129     BOOL Execute(
03130       const PString & str,    
03131       PIntArray & starts,     
03132       PIntArray & ends,       
03133       int flags = 0           
03134     ) const;
03136     BOOL Execute(
03137       const char * cstr,      
03138       PIntArray & starts,     
03139       int flags = 0           
03140     ) const;
03156     BOOL Execute(
03157       const char * cstr,      
03158       PIntArray & starts,     
03159       PIntArray & ends,       
03160       int flags = 0           
03161     ) const;
03163 
03172     static PString EscapeString(
03173       const PString & str     
03174     );
03176 
03177   protected:
03178     PString patternSaved;
03179     int flagsSaved;
03180 
03181     void * expression;
03182     int lastError;
03183 };
03184 
03185 
03186 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 21 20:43:09 2005 for PWLib by  doxygen 1.4.1