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.85  2005/12/15 21:14:34  dsandras
00031  * Fixed from Alexander Larsson <alexl _AT__ redhat.com> for gcc 4.1 compilation. Thanks!
00032  *
00033  * Revision 1.84  2005/11/30 12:47:38  csoutheren
00034  * Removed tabs, reformatted some code, and changed tags for Doxygen
00035  *
00036  * Revision 1.83  2005/11/25 03:43:47  csoutheren
00037  * Fixed function argument comments to be compatible with Doxygen
00038  *
00039  * Revision 1.82  2005/09/18 11:05:36  dominance
00040  * include/ptlib/channel.h, include/ptlib/pstring.h, src/ptlib/common/contain.cxx,
00041  * src/ptlib/common/pchannel.cxx:
00042  *   correct the STL defined checking to use proper syntax.
00043  *
00044  * include/ptlib/object.h:
00045  *   re-add typedef to compile on mingw
00046  *
00047  * make/ptlib-config.in:
00048  *   import a long-standing fix from the Debian packs which allows usage of
00049  *   ptlib-config without manually adding -lpt for each of the subsequent
00050  *   projects
00051  *
00052  * Revision 1.81  2004/12/22 04:04:36  dereksmithies
00053  * Modify description of parameters for PString::Replace()
00054  *
00055  * Revision 1.80  2004/11/23 11:33:08  csoutheren
00056  * Fixed problem with RemoveAt returning invalid pointer in some cases,
00057  * and added extra documentation on this case.
00058  * Thanks to Diego Tartara for pointing out this potential problem
00059  *
00060  * Revision 1.79  2004/10/21 13:04:20  rjongbloed
00061  * Fixed possibility of const operator[] on PStringArray returning a NULL reference. This
00062  *   function should return a non-lvalue PString anyway as it is const!
00063  *
00064  * Revision 1.78  2004/08/16 08:49:59  csoutheren
00065  * Removed error when compiling with gcc
00066  *
00067  * Revision 1.77  2004/08/16 06:40:59  csoutheren
00068  * Added adapters template to make device plugins available via the abstract factory interface
00069  *
00070  * Revision 1.76  2004/06/01 05:54:18  csoutheren
00071  * Added <vector> and <string>
00072  *
00073  * Revision 1.75  2004/06/01 05:21:38  csoutheren
00074  * Added conversions between std::string and PString, and vector<PString> and PStringArray
00075  *
00076  * Revision 1.74  2004/05/04 11:10:36  rjongbloed
00077  * Fixed usage of MakeEmpty() with PStringStream.
00078  *
00079  * Revision 1.73  2004/04/18 04:33:36  rjongbloed
00080  * Changed all operators that return BOOL to return standard type bool. This is primarily
00081  *   for improved compatibility with std STL usage removing many warnings.
00082  *
00083  * Revision 1.72  2004/04/11 13:26:25  csoutheren
00084  * Removed namespace problems and removed warnings for Windows <string>
00085  *
00086  * Revision 1.71  2004/04/09 06:38:10  rjongbloed
00087  * Fixed compatibility with STL based streams, eg as used by VC++2003
00088  *
00089  * Revision 1.70  2004/04/09 03:42:34  csoutheren
00090  * Removed all usages of "virtual inline" and "inline virtual"
00091  *
00092  * Revision 1.69  2004/04/03 06:54:22  rjongbloed
00093  * Many and various changes to support new Visual C++ 2003
00094  *
00095  * Revision 1.68  2004/02/23 00:44:38  csoutheren
00096  * A completely different, other regex include hack to avoid requiring
00097  * the sources when using a header-file only environment
00098  *
00099  * Revision 1.67  2004/02/23 00:26:05  csoutheren
00100  * Finally, a generic and elegant fix for the regex include hacks.  Thanks to Roger Hardiman
00101  *
00102  * Revision 1.66  2004/02/11 05:09:14  csoutheren
00103  * Fixed problems with regex libraries on Solaris, and with host OS numbering
00104  * being a quoted string rather than a number. Thanks to Chad Attermann
00105  * Fixed problems SSL detection problems thanks to Michal Zygmuntowicz
00106  *
00107  * Revision 1.65  2004/02/08 11:13:11  rjongbloed
00108  * Fixed crash in heavily loaded multi-threaded systems using simultaneous sorted
00109  *   lists, Thanks Federico Pinna, Fabrizio Ammollo and the gang at Reitek S.p.A.
00110  *
00111  * Revision 1.64  2004/01/18 13:43:48  rjongbloed
00112  * Fixed broken PString::MakeEmpty() function and moved implementations to .inl file.
00113  *
00114  * Revision 1.63  2004/01/17 18:15:24  csoutheren
00115  * Fixed multi-threading problem with PString::Empty
00116  * Created PString::MakeEmpty for efficient emptying of existing strings
00117  *
00118  * Revision 1.62  2004/01/16 13:24:37  csoutheren
00119  * Changed PString::Empty to be thread-safe
00120  * Fixed PContainer::SetMinSize and PAbstractArray::SetSize, thanks to 123@call2ua.com
00121  * Fixed PString::FindLast, thanks to Andreas Sikkema
00122  *
00123  * Revision 1.61  2003/12/13 23:08:46  csoutheren
00124  * Changed PRegularExpression to allow a copy constructor and operator =
00125  *
00126  * Revision 1.60  2003/12/10 03:28:50  csoutheren
00127  * Removed compile time warning under Linux
00128  *
00129  * Revision 1.59  2003/12/07 05:50:49  csoutheren
00130  * Blocked operator = for PRegularExpression
00131  *
00132  * Revision 1.58  2003/12/04 13:10:38  csoutheren
00133  * Made PRegularExpression copy constructor private to avoid accidental usage (and subsequent crash)
00134  *
00135  * Revision 1.57  2003/05/14 00:46:47  rjongbloed
00136  * Added constructor to string lists/arrays etc that takes a single PString.
00137  *
00138  * Revision 1.56  2003/03/31 01:23:56  robertj
00139  * Added ReadFrom functions for standard container classes such as
00140  *   PIntArray and PStringList etc
00141  *
00142  * Revision 1.55  2003/03/05 08:48:32  robertj
00143  * Added PStringArray::ToCharAray() function at suggestion of Ravelli Rossano
00144  *
00145  * Revision 1.54  2002/11/12 09:17:44  robertj
00146  * Added PString::NumCompare() as functional equivalent of strncmp().
00147  * Added PSortedStringList::GetNextStringsIndex() to do searches of binary
00148  *   tree on partal strings.
00149  *
00150  * Revision 1.53  2002/10/31 05:53:44  robertj
00151  * Now comprehensively stated that a PString is ALWAYS an 8 bit string as
00152  *   there are far too many inheerent assumptions every to make it 16 bit.
00153  * Added UTF-8/UCS-2 conversion functions to PString.
00154  *
00155  * Revision 1.52  2002/09/16 01:08:59  robertj
00156  * Added #define so can select if #pragma interface/implementation is used on
00157  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00158  *
00159  * Revision 1.51  2002/08/14 00:43:39  robertj
00160  * Added ability to have fixed maximum length PStringStream's so does not do
00161  *   unwanted malloc()'s while outputing data.
00162  *
00163  * Revision 1.50  2002/04/09 02:30:18  robertj
00164  * Removed GCC3 variable as __GNUC__ can be used instead, thanks jason Spence
00165  *
00166  * Revision 1.49  2002/02/15 04:29:31  robertj
00167  * Added PString::Empty() to return the primordial empty string. Saves on a
00168  *   couple of memory allocations for every empty string ever used.
00169  *
00170  * Revision 1.48  2002/01/26 23:55:55  craigs
00171  * Changed for GCC 3.0 compatibility, thanks to manty@manty.net
00172  *
00173  * Revision 1.47  2002/01/22 01:03:57  craigs
00174  * Added operator += and operator + functions to PStringArray and PStringList
00175  * Added AppendString operator to PStringArray
00176  *
00177  * Revision 1.46  2001/10/17 05:09:22  robertj
00178  * Added contructors and assigmnent operators so integer types can be
00179  *   automatically converted to strings.
00180  *
00181  * Revision 1.45  2001/08/11 07:57:30  rogerh
00182  * Add Mac OS Carbon changes from John Woods <jfw@jfwhome.funhouse.com>
00183  *
00184  * Revision 1.44  2001/04/18 04:10:15  robertj
00185  * Removed hash function for caseless strings as confuses mixed dictionaries.
00186  *
00187  * Revision 1.43  2001/04/18 01:20:58  robertj
00188  * Fixed problem with hash function for short strings, thanks Patrick Koorevaar.
00189  * Also fixed hash function for caseless strings.
00190  *
00191  * Revision 1.42  2001/02/21 03:38:37  robertj
00192  * Added ability to copy between various string lists/arrays etc during construction.
00193  *
00194  * Revision 1.41  2001/02/13 04:39:08  robertj
00195  * Fixed problem with operator= in container classes. Some containers will
00196  *   break unless the copy is virtual (eg PStringStream's buffer pointers) so
00197  *   needed to add a new AssignContents() function to all containers.
00198  *
00199  * Revision 1.40  1999/08/22 12:13:43  robertj
00200  * Fixed warning when using inlines on older GNU compiler
00201  *
00202  * Revision 1.39  1999/05/28 14:01:22  robertj
00203  * Added initialisers to string containers (list, sorted list and set).
00204  *
00205  * Revision 1.38  1999/03/09 09:34:05  robertj
00206  * Fixed typo's.
00207  *
00208  * Revision 1.37  1999/03/09 02:59:50  robertj
00209  * Changed comments to doc++ compatible documentation.
00210  *
00211  * Revision 1.36  1999/02/16 08:11:09  robertj
00212  * MSVC 6.0 compatibility changes.
00213  *
00214  * Revision 1.35  1998/09/23 06:21:12  robertj
00215  * Added open source copyright license.
00216  *
00217  * Revision 1.34  1998/01/26 00:33:46  robertj
00218  * Added FindRegEx function to PString that returns position and length.
00219  * Added Execute() functions to PRegularExpression that take PINDEX references instead of PIntArrays.
00220  * Added static function to PRegularExpression to escape all special operator characters in a string.
00221  *
00222  * Revision 1.33  1998/01/05 10:39:35  robertj
00223  * Fixed "typesafe" templates/macros for dictionaries, especially on GNU.
00224  *
00225  * Revision 1.32  1997/12/11 13:32:47  robertj
00226  * Added AsUnsigned() function to convert string to DWORD.
00227  *
00228  * Revision 1.31  1997/12/11 10:29:49  robertj
00229  * Added type correct Contains() function to dictionaries.
00230  *
00231  * Revision 1.30  1997/07/08 13:13:47  robertj
00232  * DLL support.
00233  *
00234  * Revision 1.29  1997/06/10 11:36:32  craigs
00235  * Added inline statements to allow compilation uder Unix
00236  *
00237  * Revision 1.28  1997/06/08 04:48:58  robertj
00238  * Added regular expressions.
00239  * Fixed non-template class descendent order.
00240  *
00241  * Revision 1.27  1997/05/16 12:10:12  robertj
00242  * Fixed G++ compatibility bug.
00243  *
00244  * Revision 1.26  1996/10/08 13:13:38  robertj
00245  * Added operator += and &= for char so no implicit PString construction.
00246  *
00247  * Revision 1.25  1996/09/14 12:52:39  robertj
00248  * Added operator! for !IsEmpty().
00249  *
00250  * Revision 1.24  1996/08/17 10:00:25  robertj
00251  * Changes for Windows DLL support.
00252  *
00253  * Revision 1.23  1996/05/26 03:27:02  robertj
00254  * Compatibility to GNU 2.7.x
00255  *
00256  * Revision 1.22  1996/03/31 08:51:22  robertj
00257  * Added RemoveAt() function to remove entries from dictionaries.
00258  *
00259  * Revision 1.21  1996/03/10 13:15:50  robertj
00260  * Added operator() to template version.
00261  *
00262  * Revision 1.20  1996/02/19 13:17:33  robertj
00263  * Removed PCaselessString hash function to fix dictionary match failure.
00264  * Added operator() to do string dictionary lookup with default value.
00265  *
00266  * Revision 1.19  1996/02/08 12:19:16  robertj
00267  * Added new operators to PString for case insensitive compare and spaced concatenate.
00268  *
00269  * Revision 1.18  1996/01/24 14:43:15  robertj
00270  * Added initialisers to string dictionaries.
00271  *
00272  * Revision 1.17  1996/01/23 13:15:17  robertj
00273  * Added Replace() function to strings.
00274  * Mac Metrowerks compiler support.
00275  * String searching algorithm rewrite.
00276  *
00277  * Revision 1.16  1996/01/02 12:04:31  robertj
00278  * Mac OS compatibility changes.
00279  * Removed requirement that PArray elements have parameterless constructor..
00280  *
00281  * Revision 1.15  1995/12/23 03:46:23  robertj
00282  * Added operators for include and exclude from string set.
00283  *
00284  * Revision 1.14  1995/10/14 15:02:56  robertj
00285  * Changed arrays to not break references, but strings still need to.
00286  *
00287  * Revision 1.13  1995/06/17 11:13:08  robertj
00288  * Documentation update.
00289  *
00290  * Revision 1.12  1995/06/17 00:43:40  robertj
00291  * Added flag for PStringArray constructor to create caseless strings.
00292  *
00293  * Revision 1.11  1995/06/04 12:34:57  robertj
00294  * Better C++ compatibility (with BC++)
00295  *
00296  * Revision 1.10  1995/04/02 09:27:23  robertj
00297  * Added "balloon" help.
00298  *
00299  * Revision 1.9  1995/03/14 12:42:16  robertj
00300  * Updated documentation to use HTML codes.
00301  *
00302  * Revision 1.8  1995/03/12  04:44:39  robertj
00303  * Fixed use of PCaselessString as dictionary key.
00304  *
00305  * Revision 1.7  1995/02/05  00:48:09  robertj
00306  * Fixed template version.
00307  *
00308  * Revision 1.6  1995/01/15  04:50:20  robertj
00309  * Added inlines on friend functions, required by GNU compiler.
00310  *
00311  * Revision 1.5  1995/01/10  11:43:41  robertj
00312  * Removed PString parameter in stdarg function for GNU C++ compatibility.
00313  *
00314  * Revision 1.4  1995/01/09  12:33:44  robertj
00315  * Removed unnecesary return value from I/O functions.
00316  * Changed function names due to Mac port.
00317  *
00318  * Revision 1.3  1994/12/21  11:53:21  robertj
00319  * Documentation and variable normalisation.
00320  *
00321  * Revision 1.2  1994/12/12  13:13:13  robertj
00322  * Fixed bugs in PString mods just made.
00323  *
00324  * Revision 1.1  1994/12/12  09:59:37  robertj
00325  * Initial revision
00326  *
00327  */
00328 
00329 #ifdef P_USE_PRAGMA
00330 #pragma interface
00331 #endif
00332 
00333 #include <string>
00334 #include <vector>
00335 
00337 // PString class
00338 
00339 class PStringArray;
00340 class PRegularExpression;
00341 
00376 class PString : public PCharArray {
00377   PCLASSINFO(PString, PCharArray);
00378 
00379 //  using namespace std;
00380 
00381   public:
00387     PINLINE PString();
00388 
00392     PINLINE PString(
00393       const PString & str  
00394     );
00395 
00398     PINLINE PString(
00399       const std::string & str
00400     );
00401 
00410     PString(
00411       const char * cstr 
00412     );
00413 
00418     PString(
00419       const WORD * ustr 
00420     );
00421 
00435     PString(
00436       const char * cstr,  
00437       PINDEX len          
00438     );
00439 
00450     PString(
00451       const WORD * ustr,  
00452       PINDEX len          
00453     );
00454 
00465     PString(
00466       const PWORDArray & ustr 
00467     );
00468 
00477     PString(
00478       char ch    
00479     );
00480 
00485     PString(
00486       short n   
00487     );
00488 
00493     PString(
00494       unsigned short n   
00495     );
00496 
00501     PString(
00502       int n   
00503     );
00504 
00509     PString(
00510       unsigned int n   
00511     );
00512 
00517     PString(
00518       long n   
00519     );
00520 
00525     PString(
00526       unsigned long n   
00527     );
00528 
00533     PString(
00534       PInt64 n   
00535     );
00536 
00541     PString(
00542       PUInt64 n   
00543     );
00544 
00545  
00546     enum ConversionType {
00547       Pascal,   // Data is a length byte followed by characters.
00548       Basic,    // Data is two length bytes followed by characters.
00549       Literal,  // Data is C language style string with \ escape codes.
00550       Signed,   // Convert a signed integer to a string.
00551       Unsigned, // Convert an unsigned integer to a string.
00552       Decimal,  // Convert a real number to a string in decimal format.
00553       Exponent, // Convert a real number to a string in exponent format.
00554       Printf,   // Formatted output, sprintf() style function.
00555       NumConversionTypes
00556     };
00557     /* Type of conversion to make in the conversion constructors.
00558      */
00559 
00560     /* Contruct a new string converting from the spcified data source into
00561        a string array.
00562      */
00563     PString(
00564       ConversionType type,  
00565       const char * str,    
00566       ...                 
00567     );
00568     PString(
00569       ConversionType type,  
00570       long value,           
00571       unsigned base = 10    
00572     );
00573     PString(
00574       ConversionType type,  
00575       double value,         
00576       unsigned places       
00577     );
00578 
00586     PString & operator=(
00587       const PString & str  
00588     );
00589 
00599     PString & operator=(
00600       const char * cstr  
00601     );
00602 
00611     PString & operator=(
00612       char ch            
00613     );
00614 
00619     PString & operator=(
00620       short n   
00621     );
00622 
00627     PString & operator=(
00628       unsigned short n   
00629     );
00630 
00635     PString & operator=(
00636       int n   
00637     );
00638 
00643     PString & operator=(
00644       unsigned int n   
00645     );
00646 
00651     PString & operator=(
00652       long n   
00653     );
00654 
00659     PString & operator=(
00660       unsigned long n   
00661     );
00662 
00667     PString & operator=(
00668       PInt64 n   
00669     );
00670 
00675     PString & operator=(
00676       PUInt64 n   
00677     );
00678 
00681     virtual PString & MakeEmpty();
00682 
00685     static PString Empty();
00687 
00694     virtual PObject * Clone() const;
00695 
00705     virtual Comparison Compare(
00706       const PObject & obj   
00707     ) const;
00708 
00711     virtual void PrintOn(
00712       ostream & strm  
00713     ) const;
00714 
00720     virtual void ReadFrom(
00721       istream & strm  
00722     );
00723 
00737     virtual PINDEX HashFunction() const;
00739 
00754     virtual BOOL SetSize(
00755       PINDEX newSize  
00756     );
00757 
00766     virtual BOOL IsEmpty() const;
00767 
00776     virtual BOOL MakeUnique();
00778 
00779 
00792     BOOL MakeMinimumSize();
00793 
00802     PINLINE PINDEX GetLength() const;
00803 
00810     bool operator!() const;
00812 
00821     PString operator+(
00822       const PString & str   
00823     ) const;
00824 
00836     PString operator+(
00837       const char * cstr  
00838     ) const;
00839 
00851     PString operator+(
00852       char ch   
00853     ) const;
00854 
00866     friend PString operator+(
00867       const char * cstr,    
00868       const PString & str   
00869     );
00870 
00882     friend PString operator+(
00883       char  c,              
00884       const PString & str   
00885     );
00886 
00892     PString & operator+=(
00893       const PString & str   
00894     );
00895 
00905     PString & operator+=(
00906       const char * cstr  
00907     );
00908 
00918     PString & operator+=(
00919       char ch   
00920     );
00921 
00922 
00929     PString operator&(
00930       const PString & str   
00931     ) const;
00932 
00949     PString operator&(
00950       const char * cstr  
00951     ) const;
00952 
00969     PString operator&(
00970       char ch   
00971     ) const;
00972 
00989     friend PString operator&(
00990       const char * cstr,    
00991       const PString & str   
00992     );
00993 
01010     friend PString operator&(
01011       char  ch,              
01012       const PString & str   
01013     );
01014 
01020     PString & operator&=(
01021       const PString & str   
01022     );
01023 
01038     PString & operator&=(
01039       const char * cstr  
01040     );
01041 
01042 
01057     PString & operator&=(
01058       char ch  
01059     );
01061 
01062 
01070     bool operator*=(
01071       const PString & str  
01072     ) const;
01073 
01081     bool operator==(
01082       const PObject & str  
01083     ) const;
01084 
01092     bool operator!=(
01093       const PObject & str  
01094     ) const;
01095 
01103     bool operator<(
01104       const PObject & str  
01105     ) const;
01106 
01114     bool operator>(
01115       const PObject & str  
01116     ) const;
01117 
01125     bool operator<=(
01126       const PObject & str  
01127     ) const;
01128 
01136     bool operator>=(
01137       const PObject & str  
01138     ) const;
01139 
01140 
01151     bool operator*=(
01152       const char * cstr  
01153     ) const;
01154 
01165     bool operator==(
01166       const char * cstr  
01167     ) const;
01168 
01179     bool operator!=(
01180       const char * cstr  
01181     ) const;
01182 
01193     bool operator<(
01194       const char * cstr  
01195     ) const;
01196 
01207     bool operator>(
01208       const char * cstr  
01209     ) const;
01210 
01221     bool operator<=(
01222       const char * cstr  
01223     ) const;
01224 
01235     bool operator>=(
01236       const char * cstr  
01237     ) const;
01238 
01250     Comparison NumCompare(
01251       const PString & str,        
01252       PINDEX count = P_MAX_INDEX, 
01253       PINDEX offset = 0           
01254     ) const;
01255 
01267     Comparison NumCompare(
01268       const char * cstr,          
01269       PINDEX count = P_MAX_INDEX, 
01270       PINDEX offset = 0           
01271     ) const;
01273 
01274 
01278     PINDEX Find(
01279       char ch,              
01280       PINDEX offset = 0     
01281     ) const;
01282 
01284     PINDEX Find(
01285       const PString & str,  
01286       PINDEX offset = 0     
01287     ) const;
01288 
01289     /* Locate the position within the string of the character or substring. The
01290        search will begin at the character offset provided.
01291        
01292        If #offset# is beyond the length of the string, then the
01293        function will always return #P_MAX_INDEX#.
01294        
01295        The matching will be for identical character or string. If a search
01296        ignoring case is required then the string should be converted to a
01297        #PCaselessString# before the search is made.
01298 
01299        @return
01300        position of character or substring in the string, or P_MAX_INDEX if the
01301        character or substring is not in the string.
01302      */
01303     PINDEX Find(
01304       const char * cstr,    
01305       PINDEX offset = 0     
01306     ) const;
01307 
01309     PINDEX FindLast(
01310       char ch,                     
01311       PINDEX offset = P_MAX_INDEX  
01312     ) const;
01313 
01315     PINDEX FindLast(
01316       const PString & str,         
01317       PINDEX offset = P_MAX_INDEX  
01318     ) const;
01319 
01337     PINDEX FindLast(
01338       const char * cstr,           
01339       PINDEX offset = P_MAX_INDEX  
01340     ) const;
01341 
01343     PINDEX FindOneOf(
01344       const PString & set,  
01345       PINDEX offset = 0     
01346     ) const;
01347 
01362     PINDEX FindOneOf(
01363       const char * cset,    
01364       PINDEX offset = 0     
01365     ) const;
01366 
01377     PINDEX FindRegEx(
01378       const PRegularExpression & regex, 
01379       PINDEX offset = 0                 
01380     ) const;
01381 
01392     BOOL FindRegEx(
01393       const PRegularExpression & regex, 
01394       PINDEX & pos,                     
01395       PINDEX & len,                     
01396       PINDEX offset = 0,                
01397       PINDEX maxPos = P_MAX_INDEX       
01398     ) const;
01399 
01400 
01411     void Replace(
01412       const PString & target,   
01413       const PString & subs,     
01414       BOOL all = FALSE,         
01415       PINDEX offset = 0         
01416     );
01417 
01425     void Splice(
01426       const PString & str,  
01427       PINDEX pos,           
01428       PINDEX len = 0        
01429     );
01430 
01438     void Splice(
01439       const char * cstr,    
01440       PINDEX pos,           
01441       PINDEX len = 0        
01442     );
01443 
01450     void Delete(
01451       PINDEX start,   
01452       PINDEX len      
01453     );
01455 
01456 
01476     PString operator()(
01477       PINDEX start,  
01478       PINDEX end     
01479     ) const;
01480 
01495     PString Left(
01496       PINDEX len   
01497     ) const;
01498 
01513     PString Right(
01514       PINDEX len   
01515     ) const;
01516 
01533     PString Mid(
01534       PINDEX start,             
01535       PINDEX len = P_MAX_INDEX  
01536     ) const;
01537 
01538 
01546     PString LeftTrim() const;
01547 
01555     PString RightTrim() const;
01556 
01565     PString Trim() const;
01566 
01567 
01576     PString ToLower() const;
01577 
01586     PString ToUpper() const;
01587 
01588 
01590     PStringArray Tokenise(
01591       const PString & separators,
01593       BOOL onePerSeparator = TRUE
01595     ) const;
01618     PStringArray Tokenise(
01619       const char * cseparators,
01621       BOOL onePerSeparator = TRUE
01623     ) const;
01624 
01638     PStringArray Lines() const;
01640 
01657     PString & sprintf(
01658       const char * cfmt,   
01659       ...                  
01660     );
01661 
01676     friend PString psprintf(
01677       const char * cfmt,   
01678       ...                  
01679     );
01680 
01682     PString & vsprintf(
01683       const PString & fmt, 
01684       va_list args         
01685     );
01700     PString & vsprintf(
01701       const char * cfmt,   
01702       va_list args         
01703     );
01704 
01706     friend PString pvsprintf(
01707       const char * cfmt,   
01708       va_list args         
01709     );
01724     friend PString pvsprintf(
01725       const PString & fmt, 
01726       va_list args         
01727     );
01728 
01729 
01742     long AsInteger(
01743       unsigned base = 10    
01744     ) const;
01757     DWORD AsUnsigned(
01758       unsigned base = 10    
01759     ) const;
01773     PInt64 AsInt64(
01774       unsigned base = 10    
01775     ) const;
01789     PUInt64 AsUnsigned64(
01790       unsigned base = 10    
01791     ) const;
01792 
01803     double AsReal() const;
01804      
01808     PWORDArray AsUCS2() const;
01809 
01820     PBYTEArray ToPascal() const;
01821 
01830     PString ToLiteral() const;
01831 
01839     operator const unsigned char *() const;
01840 
01842 
01843 
01844   protected:
01845     void InternalFromUCS2(
01846       const WORD * ptr,
01847       PINDEX len
01848     );
01849     virtual Comparison InternalCompare(
01850       PINDEX offset,      // Offset into string to compare.
01851       char c              // Character to compare against.
01852     ) const;
01853     virtual Comparison InternalCompare(
01854       PINDEX offset,      // Offset into string to compare.
01855       PINDEX length,      // Number of characters to compare.
01856       const char * cstr   // C string to compare against.
01857     ) const;
01858     /* Internal function to compare the current string value against the
01859        specified C string.
01860 
01861        @return
01862        relative rank of the two strings.
01863      */
01864 
01865     PString(int dummy, const PString * str);
01866 };
01867 
01868 
01870 
01880 class PCaselessString : public PString
01881 {
01882   PCLASSINFO(PCaselessString, PString);
01883 
01884   public:
01887     PCaselessString();
01888 
01892     PCaselessString(
01893       const char * cstr   
01894     );
01895 
01900     PCaselessString(
01901       const PString & str  
01902     );
01903 
01904 
01912     PCaselessString & operator=(
01913       const PString & str  
01914     );
01915 
01925     PCaselessString & operator=(
01926       const char * cstr  
01927     );
01928 
01937     PCaselessString & operator=(
01938       char ch            
01939     );
01940 
01941 
01942   // Overrides from class PObject
01947     virtual PObject * Clone() const;
01948 
01949   protected:
01950   // Overrides from class PString
01951     virtual Comparison InternalCompare(
01952       PINDEX offset,      // Offset into string to compare.
01953       char c              // Character to compare against.
01954     ) const;
01955     virtual Comparison InternalCompare(
01956       PINDEX offset,      // Offset into string to compare.
01957       PINDEX length,      // Number of characters to compare.
01958       const char * cstr   // C string to compare against.
01959     ) const;
01960     /* Internal function to compare the current string value against the
01961        specified C string.
01962 
01963        @return
01964        relative rank of the two strings or characters.
01965      */
01966 
01967     PCaselessString(int dummy, const PCaselessString * str);
01968 };
01969 
01971 
01972 class PStringStream;
01973 
01980 class PStringStream : public PString, public iostream
01981 {
01982   PCLASSINFO(PStringStream, PString);
01983 
01984   public:
01990     PStringStream();
01991 
01996     PStringStream(
01997       PINDEX fixedBufferSize
01998     );
01999 
02006     PStringStream(
02007       const PString & str   
02008     );
02009 
02014     PStringStream(
02015       const char * cstr   
02016     );
02017 
02020     virtual PString & MakeEmpty();
02021 
02033     PStringStream & operator=(
02034       const PStringStream & strm
02035     );
02036 
02048     PStringStream & operator=(
02049       const PString & str  
02050     );
02051 
02067     PStringStream & operator=(
02068       const char * cstr  
02069     );
02070 
02079     PStringStream & operator=(
02080       char ch            
02081     );
02082 
02083 
02085     virtual ~PStringStream();
02086 
02087 
02088   protected:
02089     virtual void AssignContents(const PContainer & cont);
02090 
02091   private:
02092     PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
02093 
02094     class Buffer : public streambuf {
02095       public:
02096         Buffer(PStringStream & str, PINDEX size);
02097         Buffer(const Buffer & sbuf);
02098         Buffer & operator=(const Buffer & sbuf);
02099         virtual int overflow(int=EOF);
02100         virtual int underflow();
02101         virtual int sync();
02102 #ifdef __USE_STL__
02103         virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
02104         virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
02105 #else
02106         virtual streampos seekoff(streamoff, ios::seek_dir, int);
02107 #endif
02108         PStringStream & string;
02109         BOOL            fixedBufferSize;
02110     };
02111 };
02112 
02113 
02114 class PStringList;
02115 class PSortedStringList;
02116 
02129 #ifdef DOC_PLUS_PLUS
02130 class PStringArray : public PArray {
02131 #endif
02132   PDECLARE_ARRAY(PStringArray, PString);
02133   public:
02140     PStringArray(
02141       PINDEX count,                 
02142       char const * const * strarr,  
02143       BOOL caseless = FALSE         
02144     );
02147     PStringArray(
02148       const PString & str  
02149     );
02152     PStringArray(
02153       const PStringList & list  
02154     );
02157     PStringArray(
02158       const PSortedStringList & list  
02159     );
02160 
02164     PStringArray(
02165       const std::vector<PString> & vec
02166     )
02167     {
02168       for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02169         AppendString(*r);
02170     }
02171 
02175     PStringArray(
02176       const std::vector<std::string> & vec
02177     )
02178     {
02179       for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02180         AppendString(PString(*r));
02181     }
02182 
02186     template <typename stlContainer>
02187     static PStringArray container(
02188       const stlContainer & vec
02189     )
02190     {
02191       PStringArray list;
02192       for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02193         list.AppendString(PString(*r));
02194       return list;
02195     }
02196 
02198 
02206     virtual void ReadFrom(
02207       istream &strm   // Stream to read the objects contents from.
02208     );
02210 
02219     PINDEX GetStringsIndex(
02220       const PString & str 
02221     ) const;
02222 
02223     PString operator[](
02224       PINDEX il">Pnst PContainer & cont);
02090 
02091   private:
02092     PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
02093 
02094     class Buffer : public streambuf {
02095       public:
02096         Buffer(PStringStream & str, PINDEX size);
02097         Buffer(const Buffer & sbuf);
02098         Buffer & operator=(const Buffer & sbuf);
02099         virtual int overflow(int=EOF);
02100         virtual int underflow();
02101         virtual int sync();
02102 #ifdef __USE_STL__
02103         virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
02104         virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
02105 #else
02106         virtual streampos seekoff(streamoff, ios::seek_dir, int);
02107 #endif
02108         PStringStream & string;
02109         BOOL            fixedBufferSize;
02110     };
02111 };
02112 
02113 
02114 class PStringList;
02115 class PSortedStringList;
02116 
02129 #ifdef DOC_PLUS_PLUS
02130 class PStringArray : public PArray {
02131 #endif
02132   PDECLARE_ARRAY(PStringArray, PString);
02133   public:
02140     PStringArray(
02141       PINDEX count,                 
02142       char const * const * strarr,  
02143       BOOL caseless = FALSE         
02144     );
02147     PStringArray(
02148       const PString & str  
02149     );
02152     PStringArray(
02153       const PStringList & list  
02154     );
02157     PStringArray(
02158       const PSortedStringList & list  
02159     );
02160 
02164     PStringArray(
02165       const std::vector<PString> & vec
02166     )
02167     {
02168       for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02169         AppendString(*r);
02170     }
02171 
02175     PStringArray(
02176       const std::vector<std::string> & vec
02177     )
02178     {
02179       for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02180         AppendString(PString(*r));
02181     }
02182 
02186     template <typename stlContainer>
02187     static PStringArray container(
02188       const stlContainer & vec
02189     )
02190     {
02191       PStringArray list;
02192       for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02193         list.AppendString(PString(*r));
02194       return list;
02195     }
02196 
02198 
02206     virtual void ReadFrom(
02207       istream &strm   // Stream to read the objects contents from.
02208     );
02210 
02219     PINDEX GetStringsIndex(
02220       const PString & str 
02221     ) const;
02222 
02223     PString operator[](
02224       PINDEX il">Pnst PContainer & cont);
02090 
02091   private:
02092     PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
02093 
02094     class Buffer : public streambuf {
02095       public:
02096         Buffer(PStringStream & str, PINDEX size);
02097         Buffer(const Buffer & sbuf);
02098         Buffer & operator=(const Buffer & sbuf);
02099         virtual int overflow(int=EOF);
02100         virtual int underflow();
02101         virtual int sync();
02102 #ifdef __USE_STL__
02103         virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
02104         virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
02105 #else
02106         virtual streampos seekoff(streamoff, ios::seek_dir, int);
02107 #endif
02108         PStringStream & string;
02109         BOOL            fixedBufferSize;
02110     };
02111 };
02112 
02113 
02114 class PStringList;
02115 class PSortedStringList;
02116 
02129 #ifdef DOC_PLUS_PLUS
02130 class PStringArray : public PArray {
02131 #endif
02132   PDECLARE_ARRAY(PStringArray, PString);
02133   public:
02140     PStringArray(
02141       PINDEX count,                 
02142       char const * const * strarr,  
02143       BOOL caseless = FALSE         
02144     );
02147     PStringArray(
02148       const PString & str  
02149     );
02152     PStringArray(
02153       const PStringList & list  
02154     );
02157     PStringArray(
02158       const PSortedStringList & list  
02159     );
02160 
02164     PStringArray(
02165       const std::vector<PString> & vec
02166     )
02167     {
02168       for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02169         AppendString(*r);
02170     }
02171 
02175     PStringArray(
02176       const std::vector<std::string> & vec
02177     )
02178     {
02179       for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02180         AppendString(PString(*r));
02181     }
02182 
02186     template <typename stlContainer>
02187     static PStringArray container(
02188       const stlContainer & vec
02189     )
02190     {
02191       PStringArray list;
02192       for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02193         list.AppendString(PString(*r));
02194       return list;
02195     }
02196 
02198 
02206     virtual void ReadFrom(
02207       istream &strm   // Stream to read the objects contents from.
02208     );
02210 
02219     PINDEX GetStringsIndex(
02220       const PString & str 
02221     ) const;
02222 
02223     PString operator[](
02224       PINDEX il">Pnst PContainer & cont);
02090 
02091   private:
02092     PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
02093 
02094     class Buffer : public streambuf {
02095       public:
02096         Buffer(PStringStream & str, PINDEX size);
02097         Buffer(const Buffer & sbuf);
02098         Buffer & operator=(const Buffer & sbuf);
02099         virtual int overflow(int=EOF);
02100         virtual int underflow();
02101         virtual int sync();
02102 #ifdef __USE_STL__
02103         virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
02104         virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
02105 #else
02106         virtual streampos seekoff(streamoff, ios::seek_dir, int);
02107 #endif
02108         PStringStream & string;
02109         BOOL            fixedBufferSize;
02110     };
02111 };
02112 
02113 
02114 class PStringList;
02115 class PSortedStringList;
02116 
02129 #ifdef DOC_PLUS_PLUS
02130 class PStringArray : public PArray {
02131 #endif
02132   PDECLARE_ARRAY(PStringArray, PString);
02133   public:
02140     PStringArray(
02141       PINDEX count,                 
02142       char const * const * strarr,  
02143       BOOL caseless = FALSE         
02144     );
02147     PStringArray(
02148       const PString & str  
02149     );
02152     PStringArray(
02153       const PStringList & list  
02154     );
02157     PStringArray(
02158       const PSortedStringList & list  
02159     );
02160 
02164     PStringArray(
02165       const std::vector<PString> & vec
02166     )
02167     {
02168       for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02169         AppendString(*r);
02170     }
02171 
02175     PStringArray(
02176       const std::vector<std::string> & vec
02177     )
02178     {
02179       for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02180         AppendString(PString(*r));
02181     }
02182 
02186     template <typename stlContainer>
02187     static PStringArray container(
02188       const stlContainer & vec
02189     )
02190     {
02191       PStringArray list;
02192       for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02193         list.AppendString(PString(*r));
02194       return list;
02195     }
02196 
02198 
02206     virtual void ReadFrom(
02207       istream &strm   // Stream to read the objects contents from.
02208     );
02210 
02219     PINDEX GetStringsIndex(
02220       const PString & str 
02221     ) const;
02222 
02223     PString operator[](
02224       PINDEX il">Pnst PContainer & cont);
02090 
02091   private:
02092     PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
02093 
02094     class Buffer : public streambuf {
02095       public:
02096         Buffer(PStringStream & str, PINDEX size);
02097         Buffer(const Buffer & sbuf);
02098         Buffer & operator=(const Buffer & sbuf);
02099         virtual int overflow(int=EOF);
02100         virtual int underflow();
02101         virtual int sync();
02102 #ifdef __USE_STL__
02103         virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
02104         virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
02105 #else
02106         virtual streampos seekoff(streamoff, ios::seek_dir, int);
02107 #endif
02108         PStringStream & string;
02109         BOOL            fixedBufferSize;
02110     };
02111 };
02112 
02113 
02114 class PStringList;
02115 class PSortedStringList;
02116 
02129 #ifdef DOC_PLUS_PLUS
02130 class PStringArray : public PArray {
02131 #endif
02132   PDECLARE_ARRAY(PStringArray, PString);
02133   public:
02140     PStringArray(
02141       PINDEX count,                 
02142       char const * const * strarr,  
02143       BOOL caseless = FALSE         
02144     );
02147     PStringArray(
02148       const PString & str  
02149     );
02152     PStringArray(
02153       const PStringList & list  
02154     );
02157     PStringArray(
02158       const PSortedStringList & list  
02159     );
02160 
02164     PStringArray(
02165       const std::vector<PString> & vec
02166     )
02167     {
02168       for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02169         AppendString(*r);
02170     }
02171 
02175     PStringArray(
02176       const std::vector<std::string> & vec
02177     )
02178     {
02179       for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02180         AppendString(PString(*r));
02181     }
02182 
02186     template <typename stlContainer>
02187     static PStringArray container(
02188       const stlContainer & vec
02189     )
02190     {
02191       PStringArray list;
02192       for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02193         list.AppendString(PString(*r));
02194       return list;
02195     }
02196 
02198 
02206     virtual void ReadFrom(
02207       istream &strm   // Stream to read the objects contents from.
02208     );
02210 
02219     PINDEX GetStringsIndex(
02220       const PString & str 
02221     ) const;
02222 
02223     PString operator[](
02224       PINDEX il">Pnst PContainer & cont);
02090 
02091   private:
02092     PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
02093 
02094     class Buffer : public streambuf {
02095       public:
02096         Buffer(PStringStream & str, PINDEX size);
02097         Buffer(const Buffer & sbuf);
02098         Buffer & operator=(const Buffer & sbuf);
02099         virtual int overflow(int=EOF);
02100         virtual int underflow();
02101         virtual int sync();
02102 #ifdef __USE_STL__
02103         virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
02104         virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
02105 #else
02106         virtual streampos seekoff(streamoff, ios::seek_dir, int);
02107 #endif
02108         PStringStream & string;
02109         BOOL            fixedBufferSize;
02110     };
02111 };
02112 
02113 
02114 class PStringList;
02115 class PSortedStringList;
02116 
02129 #ifdef DOC_PLUS_PLUS
02130 class PStringArray : public PArray {
02131 #endif
02132   PDECLARE_ARRAY(PStringArray, PString);
02133   public:
02140     PStringArray(
02141       PINDEX count,                 
02142       char const * const * strarr,  
02143       BOOL caseless = FALSE         
02144     );
02147     PStringArray(
02148       const PString & str  
02149     );
02152     PStringArray(
02153       const PStringList & list  
02154     );
02157     PStringArray(
02158       const PSortedStringList & list  
02159     );
02160 
02164     PStringArray(
02165       const std::vector<PString> & vec
02166     )
02167     {
02168       for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02169         AppendString(*r);
02170     }
02171 
02175     PStringArray(
02176       const std::vector<std::string> & vec
02177     )
02178     {
02179       for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02180         AppendString(PString(*r));
02181     }
02182 
02186     template <typename stlContainer>
02187     static PStringArray container(
02188       const stlContainer & vec
02189     )
02190     {
02191       PStringArray list;
02192       for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02193         list.AppendString(PString(*r));
02194       return list;
02195     }
02196 
02198 
02206     virtual void ReadFrom(
02207       istream &strm   // Stream to read the objects contents from.
02208     );
02210 
02219     PINDEX GetStringsIndex(
02220       const PString & str 
02221     ) const;
02222 
02223     PString operator[](
02224       PINDEX il">Pnst PContainer & cont);
02090 
02091   private:
02092     PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
02093 
02094     class Buffer : public streambuf {
02095       public:
02096         Buffer(PStringStream & str, PINDEX size);
02097         Buffer(const Buffer & sbuf);
02098         Buffer & operator=(const Buffer & sbuf);
02099         virtual int overflow(int=EOF);
02100         virtual int underflow();
02101         virtual int sync();
02102 #ifdef __USE_STL__
02103         virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
02104         virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
02105 #else
02106         virtual streampos seekoff(streamoff, ios::seek_dir, int);
02107 #endif
02108         PStringStream & string;
02109         BOOL            fixedBufferSize;
02110     };
02111 };
02112 
02113 
02114 class PStringList;
02115 class PSortedStringList;
02116 
02129 #ifdef DOC_PLUS_PLUS
02130 class PStringArray : public PArray {
02131 #endif
02132   PDECLARE_ARRAY(PStringArray, PString);
02133   public:
02140     PStringArray(
02141       PINDEX count,                 
02142       char const * const * strarr,  
02143       BOOL caseless = FALSE         
02144     );
02147     PStringArray(
02148       const PString & str  
02149     );
02152     PStringArray(
02153       const PStringList & list  
02154     );
02157     PStringArray(
02158       const PSortedStringList & list  
02159     );
02160