Prevented memory leak detection from considering anything
[pwlib.git] / include / ptlib / pstring.h
blobb4f2eaf86e379292b6636a98c53d4e2c9c477cde
1 /*
2 * pstring.h
4 * Character string class.
6 * Portable Windows Library
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
27 * Contributor(s): ______________________________________.
29 * $Log$
30 * Revision 1.93 2007/06/29 02:47:28 rjongbloed
31 * Added PString::FindSpan() function (strspn equivalent) with slightly nicer semantics.
33 * Revision 1.92 2007/04/08 01:53:16 ykiryanov
34 * Build to support ptlib dll creation
36 * Revision 1.91 2006/08/11 08:18:57 csoutheren
37 * Add PCaselessString constructor for std::string
39 * Revision 1.90 2006/08/11 04:44:48 csoutheren
40 * Add operator to convert PString to std::string
42 * Revision 1.89 2006/07/10 09:15:28 shorne
43 * Corrected PString::Tokenize() documentation Thx. David Corrie
45 * Revision 1.88 2006/06/30 00:56:31 csoutheren
46 * Applied 1494931 - various pwlib bug fixes and enhancement
47 * Thanks to Frederich Heem
49 * Revision 1.87 2006/06/21 03:28:41 csoutheren
50 * Various cleanups thanks for Frederic Heem
52 * Revision 1.86 2006/04/09 07:05:40 rjongbloed
53 * Moved output stream operator for PString from sockets code to string code and fixed
54 * its implemetation to continue to use PrintOn. Why it was added is unknown, probably
55 * a compiler issue, but it should not be in a random source file!
57 * Revision 1.85 2005/12/15 21:14:34 dsandras
58 * Fixed from Alexander Larsson <alexl _AT__ redhat.com> for gcc 4.1 compilation. Thanks!
60 * Revision 1.84 2005/11/30 12:47:38 csoutheren
61 * Removed tabs, reformatted some code, and changed tags for Doxygen
63 * Revision 1.83 2005/11/25 03:43:47 csoutheren
64 * Fixed function argument comments to be compatible with Doxygen
66 * Revision 1.82 2005/09/18 11:05:36 dominance
67 * include/ptlib/channel.h, include/ptlib/pstring.h, src/ptlib/common/contain.cxx,
68 * src/ptlib/common/pchannel.cxx:
69 * correct the STL defined checking to use proper syntax.
71 * include/ptlib/object.h:
72 * re-add typedef to compile on mingw
74 * make/ptlib-config.in:
75 * import a long-standing fix from the Debian packs which allows usage of
76 * ptlib-config without manually adding -lpt for each of the subsequent
77 * projects
79 * Revision 1.81 2004/12/22 04:04:36 dereksmithies
80 * Modify description of parameters for PString::Replace()
82 * Revision 1.80 2004/11/23 11:33:08 csoutheren
83 * Fixed problem with RemoveAt returning invalid pointer in some cases,
84 * and added extra documentation on this case.
85 * Thanks to Diego Tartara for pointing out this potential problem
87 * Revision 1.79 2004/10/21 13:04:20 rjongbloed
88 * Fixed possibility of const operator[] on PStringArray returning a NULL reference. This
89 * function should return a non-lvalue PString anyway as it is const!
91 * Revision 1.78 2004/08/16 08:49:59 csoutheren
92 * Removed error when compiling with gcc
94 * Revision 1.77 2004/08/16 06:40:59 csoutheren
95 * Added adapters template to make device plugins available via the abstract factory interface
97 * Revision 1.76 2004/06/01 05:54:18 csoutheren
98 * Added <vector> and <string>
100 * Revision 1.75 2004/06/01 05:21:38 csoutheren
101 * Added conversions between std::string and PString, and vector<PString> and PStringArray
103 * Revision 1.74 2004/05/04 11:10:36 rjongbloed
104 * Fixed usage of MakeEmpty() with PStringStream.
106 * Revision 1.73 2004/04/18 04:33:36 rjongbloed
107 * Changed all operators that return BOOL to return standard type bool. This is primarily
108 * for improved compatibility with std STL usage removing many warnings.
110 * Revision 1.72 2004/04/11 13:26:25 csoutheren
111 * Removed namespace problems and removed warnings for Windows <string>
113 * Revision 1.71 2004/04/09 06:38:10 rjongbloed
114 * Fixed compatibility with STL based streams, eg as used by VC++2003
116 * Revision 1.70 2004/04/09 03:42:34 csoutheren
117 * Removed all usages of "virtual inline" and "inline virtual"
119 * Revision 1.69 2004/04/03 06:54:22 rjongbloed
120 * Many and various changes to support new Visual C++ 2003
122 * Revision 1.68 2004/02/23 00:44:38 csoutheren
123 * A completely different, other regex include hack to avoid requiring
124 * the sources when using a header-file only environment
126 * Revision 1.67 2004/02/23 00:26:05 csoutheren
127 * Finally, a generic and elegant fix for the regex include hacks. Thanks to Roger Hardiman
129 * Revision 1.66 2004/02/11 05:09:14 csoutheren
130 * Fixed problems with regex libraries on Solaris, and with host OS numbering
131 * being a quoted string rather than a number. Thanks to Chad Attermann
132 * Fixed problems SSL detection problems thanks to Michal Zygmuntowicz
134 * Revision 1.65 2004/02/08 11:13:11 rjongbloed
135 * Fixed crash in heavily loaded multi-threaded systems using simultaneous sorted
136 * lists, Thanks Federico Pinna, Fabrizio Ammollo and the gang at Reitek S.p.A.
138 * Revision 1.64 2004/01/18 13:43:48 rjongbloed
139 * Fixed broken PString::MakeEmpty() function and moved implementations to .inl file.
141 * Revision 1.63 2004/01/17 18:15:24 csoutheren
142 * Fixed multi-threading problem with PString::Empty
143 * Created PString::MakeEmpty for efficient emptying of existing strings
145 * Revision 1.62 2004/01/16 13:24:37 csoutheren
146 * Changed PString::Empty to be thread-safe
147 * Fixed PContainer::SetMinSize and PAbstractArray::SetSize, thanks to 123@call2ua.com
148 * Fixed PString::FindLast, thanks to Andreas Sikkema
150 * Revision 1.61 2003/12/13 23:08:46 csoutheren
151 * Changed PRegularExpression to allow a copy constructor and operator =
153 * Revision 1.60 2003/12/10 03:28:50 csoutheren
154 * Removed compile time warning under Linux
156 * Revision 1.59 2003/12/07 05:50:49 csoutheren
157 * Blocked operator = for PRegularExpression
159 * Revision 1.58 2003/12/04 13:10:38 csoutheren
160 * Made PRegularExpression copy constructor private to avoid accidental usage (and subsequent crash)
162 * Revision 1.57 2003/05/14 00:46:47 rjongbloed
163 * Added constructor to string lists/arrays etc that takes a single PString.
165 * Revision 1.56 2003/03/31 01:23:56 robertj
166 * Added ReadFrom functions for standard container classes such as
167 * PIntArray and PStringList etc
169 * Revision 1.55 2003/03/05 08:48:32 robertj
170 * Added PStringArray::ToCharAray() function at suggestion of Ravelli Rossano
172 * Revision 1.54 2002/11/12 09:17:44 robertj
173 * Added PString::NumCompare() as functional equivalent of strncmp().
174 * Added PSortedStringList::GetNextStringsIndex() to do searches of binary
175 * tree on partal strings.
177 * Revision 1.53 2002/10/31 05:53:44 robertj
178 * Now comprehensively stated that a PString is ALWAYS an 8 bit string as
179 * there are far too many inheerent assumptions every to make it 16 bit.
180 * Added UTF-8/UCS-2 conversion functions to PString.
182 * Revision 1.52 2002/09/16 01:08:59 robertj
183 * Added #define so can select if #pragma interface/implementation is used on
184 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
186 * Revision 1.51 2002/08/14 00:43:39 robertj
187 * Added ability to have fixed maximum length PStringStream's so does not do
188 * unwanted malloc()'s while outputing data.
190 * Revision 1.50 2002/04/09 02:30:18 robertj
191 * Removed GCC3 variable as __GNUC__ can be used instead, thanks jason Spence
193 * Revision 1.49 2002/02/15 04:29:31 robertj
194 * Added PString::Empty() to return the primordial empty string. Saves on a
195 * couple of memory allocations for every empty string ever used.
197 * Revision 1.48 2002/01/26 23:55:55 craigs
198 * Changed for GCC 3.0 compatibility, thanks to manty@manty.net
200 * Revision 1.47 2002/01/22 01:03:57 craigs
201 * Added operator += and operator + functions to PStringArray and PStringList
202 * Added AppendString operator to PStringArray
204 * Revision 1.46 2001/10/17 05:09:22 robertj
205 * Added contructors and assigmnent operators so integer types can be
206 * automatically converted to strings.
208 * Revision 1.45 2001/08/11 07:57:30 rogerh
209 * Add Mac OS Carbon changes from John Woods <jfw@jfwhome.funhouse.com>
211 * Revision 1.44 2001/04/18 04:10:15 robertj
212 * Removed hash function for caseless strings as confuses mixed dictionaries.
214 * Revision 1.43 2001/04/18 01:20:58 robertj
215 * Fixed problem with hash function for short strings, thanks Patrick Koorevaar.
216 * Also fixed hash function for caseless strings.
218 * Revision 1.42 2001/02/21 03:38:37 robertj
219 * Added ability to copy between various string lists/arrays etc during construction.
221 * Revision 1.41 2001/02/13 04:39:08 robertj
222 * Fixed problem with operator= in container classes. Some containers will
223 * break unless the copy is virtual (eg PStringStream's buffer pointers) so
224 * needed to add a new AssignContents() function to all containers.
226 * Revision 1.40 1999/08/22 12:13:43 robertj
227 * Fixed warning when using inlines on older GNU compiler
229 * Revision 1.39 1999/05/28 14:01:22 robertj
230 * Added initialisers to string containers (list, sorted list and set).
232 * Revision 1.38 1999/03/09 09:34:05 robertj
233 * Fixed typo's.
235 * Revision 1.37 1999/03/09 02:59:50 robertj
236 * Changed comments to doc++ compatible documentation.
238 * Revision 1.36 1999/02/16 08:11:09 robertj
239 * MSVC 6.0 compatibility changes.
241 * Revision 1.35 1998/09/23 06:21:12 robertj
242 * Added open source copyright license.
244 * Revision 1.34 1998/01/26 00:33:46 robertj
245 * Added FindRegEx function to PString that returns position and length.
246 * Added Execute() functions to PRegularExpression that take PINDEX references instead of PIntArrays.
247 * Added static function to PRegularExpression to escape all special operator characters in a string.
249 * Revision 1.33 1998/01/05 10:39:35 robertj
250 * Fixed "typesafe" templates/macros for dictionaries, especially on GNU.
252 * Revision 1.32 1997/12/11 13:32:47 robertj
253 * Added AsUnsigned() function to convert string to DWORD.
255 * Revision 1.31 1997/12/11 10:29:49 robertj
256 * Added type correct Contains() function to dictionaries.
258 * Revision 1.30 1997/07/08 13:13:47 robertj
259 * DLL support.
261 * Revision 1.29 1997/06/10 11:36:32 craigs
262 * Added inline statements to allow compilation uder Unix
264 * Revision 1.28 1997/06/08 04:48:58 robertj
265 * Added regular expressions.
266 * Fixed non-template class descendent order.
268 * Revision 1.27 1997/05/16 12:10:12 robertj
269 * Fixed G++ compatibility bug.
271 * Revision 1.26 1996/10/08 13:13:38 robertj
272 * Added operator += and &= for char so no implicit PString construction.
274 * Revision 1.25 1996/09/14 12:52:39 robertj
275 * Added operator! for !IsEmpty().
277 * Revision 1.24 1996/08/17 10:00:25 robertj
278 * Changes for Windows DLL support.
280 * Revision 1.23 1996/05/26 03:27:02 robertj
281 * Compatibility to GNU 2.7.x
283 * Revision 1.22 1996/03/31 08:51:22 robertj
284 * Added RemoveAt() function to remove entries from dictionaries.
286 * Revision 1.21 1996/03/10 13:15:50 robertj
287 * Added operator() to template version.
289 * Revision 1.20 1996/02/19 13:17:33 robertj
290 * Removed PCaselessString hash function to fix dictionary match failure.
291 * Added operator() to do string dictionary lookup with default value.
293 * Revision 1.19 1996/02/08 12:19:16 robertj
294 * Added new operators to PString for case insensitive compare and spaced concatenate.
296 * Revision 1.18 1996/01/24 14:43:15 robertj
297 * Added initialisers to string dictionaries.
299 * Revision 1.17 1996/01/23 13:15:17 robertj
300 * Added Replace() function to strings.
301 * Mac Metrowerks compiler support.
302 * String searching algorithm rewrite.
304 * Revision 1.16 1996/01/02 12:04:31 robertj
305 * Mac OS compatibility changes.
306 * Removed requirement that PArray elements have parameterless constructor..
308 * Revision 1.15 1995/12/23 03:46:23 robertj
309 * Added operators for include and exclude from string set.
311 * Revision 1.14 1995/10/14 15:02:56 robertj
312 * Changed arrays to not break references, but strings still need to.
314 * Revision 1.13 1995/06/17 11:13:08 robertj
315 * Documentation update.
317 * Revision 1.12 1995/06/17 00:43:40 robertj
318 * Added flag for PStringArray constructor to create caseless strings.
320 * Revision 1.11 1995/06/04 12:34:57 robertj
321 * Better C++ compatibility (with BC++)
323 * Revision 1.10 1995/04/02 09:27:23 robertj
324 * Added "balloon" help.
326 * Revision 1.9 1995/03/14 12:42:16 robertj
327 * Updated documentation to use HTML codes.
329 * Revision 1.8 1995/03/12 04:44:39 robertj
330 * Fixed use of PCaselessString as dictionary key.
332 * Revision 1.7 1995/02/05 00:48:09 robertj
333 * Fixed template version.
335 * Revision 1.6 1995/01/15 04:50:20 robertj
336 * Added inlines on friend functions, required by GNU compiler.
338 * Revision 1.5 1995/01/10 11:43:41 robertj
339 * Removed PString parameter in stdarg function for GNU C++ compatibility.
341 * Revision 1.4 1995/01/09 12:33:44 robertj
342 * Removed unnecesary return value from I/O functions.
343 * Changed function names due to Mac port.
345 * Revision 1.3 1994/12/21 11:53:21 robertj
346 * Documentation and variable normalisation.
348 * Revision 1.2 1994/12/12 13:13:13 robertj
349 * Fixed bugs in PString mods just made.
351 * Revision 1.1 1994/12/12 09:59:37 robertj
352 * Initial revision
355 #ifndef __PSTRING__
356 #define __PSTRING__
358 #ifdef P_USE_PRAGMA
359 #pragma interface
360 #endif
362 #include <string>
363 #include <vector>
364 #include <ptlib/array.h>
366 ///////////////////////////////////////////////////////////////////////////////
367 // PString class
369 class PStringArray;
370 class PRegularExpression;
372 /**The character string class. It supports a wealth of additional functions
373 for string processing and conversion. Operators are provided so that
374 strings can virtually be treated as a basic type.
376 An important feature of the string class, which is not present in other
377 container classes, is that when the string contents is changed, that is
378 resized or elements set, the string is "dereferenced", and a duplicate
379 made of its contents. That is this instance of the array is disconnected
380 from all other references to the string data, if any, and a new string array
381 contents created. For example consider the following:
382 \begin{verbatim}
383 PString s1 = "String"; // New array allocated and set to "String"
384 PString s2 = s1; // s2 has pointer to same array as s1
385 // and reference count is 2 for both
386 s1[0] = 's'; // Breaks references into different strings
387 \end{verbatim}
388 at the end s1 is "string" and s2 is "String" both with reference count of 1.
390 The functions that will "break" a reference are #SetSize()#,
391 #SetMinSize()#, #GetPointer()#, #SetAt()# and
392 #operator[]#.
394 Note that the array is a '\0' terminated string as in C strings. Thus the
395 memory allocated, and the length of the string may be different values.
397 Also note that the PString is inherently an 8 bit string. The character set
398 is not defined for most operations and it may be any 8 bit character set.
399 However when conversions are being made to or from 2 byte formats then the
400 PString is assumed to be the UTF-8 format. The 2 byte format is nominally
401 UCS-2 (aka BMP string) and while it is not exactly the same as UNICODE
402 they are compatible enough for them to be treated the same for most real
403 world usage.
406 class PString : public PCharArray {
407 PCLASSINFO(PString, PCharArray);
409 // using namespace std;
411 public:
412 /**@name Construction */
413 //@{
414 /**Construct an empty string. This will have one character in it which is
415 the '\0' character.
417 PINLINE PString();
419 /**Create a new reference to the specified string. The string memory is not
420 copied, only the pointer to the data.
422 PINLINE PString(
423 const PString & str ///< String to create new reference to.
426 /**Create a new string from the specified std::string
428 PINLINE PString(
429 const std::string & str
432 /**Create a string from the C string array. This is most commonly used with
433 a literal string, eg "hello". A new memory block is allocated of a size
434 sufficient to take the length of the string and its terminating
435 '\0' character.
437 If UCS-2 is used then each char from the char pointer is mapped to a
438 single UCS-2 character.
440 PString(
441 const char * cstr ///< Standard '\0' terminated C string.
444 /**Create a string from the UCS-2 string array.
445 A new memory block is allocated of a size sufficient to take the length
446 of the string and its terminating '\0' character.
448 PString(
449 const WORD * ustr ///< UCS-2 null terminated string.
452 /**Create a string from the array. A new memory block is allocated of
453 a size equal to #len# plus one which is sufficient to take
454 the string and a terminating '\0' character.
456 If UCS-2 is used then each char from the char pointer is mapped to a
457 single UCS-2 character.
459 Note that this function will allow a string with embedded '\0'
460 characters to be created, but most of the functions here will be unable
461 to access characters beyond the first '\0'. Furthermore, if the
462 #MakeMinimumSize()# function is called, all data beyond that first
463 #'\0'# character will be lost.
465 PString(
466 const char * cstr, ///< Pointer to a string of characters.
467 PINDEX len ///< Length of the string in bytes.
470 /**Create a string from the UCS-2 array. A new memory block is allocated
471 of a size equal to #len# plus one which is sufficient to take
472 the string and a terminating '\0' character.
474 Note that this function will allow a string with embedded '\0'
475 characters to be created, but most of the functions here will be unable
476 to access characters beyond the first '\0'. Furthermore, if the
477 #MakeMinimumSize()# function is called, all data beyond that first
478 #'\0'# character will be lost.
480 PString(
481 const WORD * ustr, ///< Pointer to a string of UCS-2 characters.
482 PINDEX len ///< Length of the string in bytes.
485 /**Create a string from the UCS-2 array. A new memory block is allocated
486 of a size equal to #len# plus one which is sufficient to take
487 the string and a terminating '\0' character.
489 Note that this function will allow a string with embedded '\0'
490 characters to be created, but most of the functions here will be unable
491 to access characters beyond the first '\0'. Furthermore, if the
492 #MakeMinimumSize()# function is called, all data beyond that first
493 #'\0'# character will be lost.
495 PString(
496 const PWORDArray & ustr ///< UCS-2 null terminated string.
499 /**Create a string from the single character. This is most commonly used
500 as a type conversion constructor when a literal character, eg 'A' is
501 used in a string expression. A new memory block is allocated of two
502 characters to take the char and its terminating '\0' character.
504 If UCS-2 is used then the char is mapped to a single UCS-2
505 character.
507 PString(
508 char ch ///< Single character to initialise string.
511 /**Create a string from the integer type.
512 This will create a simple base 10, shortest length conversion of the
513 integer (with sign character if appropriate) into the string.
515 PString(
516 short n ///< Integer to convert
519 /**Create a string from the integer type.
520 This will create a simple base 10, shortest length conversion of the
521 integer (with sign character if appropriate) into the string.
523 PString(
524 unsigned short n ///< Integer to convert
527 /**Create a string from the integer type.
528 This will create a simple base 10, shortest length conversion of the
529 integer (with sign character if appropriate) into the string.
531 PString(
532 int n ///< Integer to convert
535 /**Create a string from the integer type.
536 This will create a simple base 10, shortest length conversion of the
537 integer (with sign character if appropriate) into the string.
539 PString(
540 unsigned int n ///< Integer to convert
543 /**Create a string from the integer type.
544 This will create a simple base 10, shortest length conversion of the
545 integer (with sign character if appropriate) into the string.
547 PString(
548 long n ///< Integer to convert
551 /**Create a string from the integer type.
552 This will create a simple base 10, shortest length conversion of the
553 integer (with sign character if appropriate) into the string.
555 PString(
556 unsigned long n ///< Integer to convert
559 /**Create a string from the integer type.
560 This will create a simple base 10, shortest length conversion of the
561 integer (with sign character if appropriate) into the string.
563 PString(
564 PInt64 n ///< Integer to convert
567 /**Create a string from the integer type.
568 This will create a simple base 10, shortest length conversion of the
569 integer (with sign character if appropriate) into the string.
571 PString(
572 PUInt64 n ///< Integer to convert
576 enum ConversionType {
577 Pascal, // Data is a length byte followed by characters.
578 Basic, // Data is two length bytes followed by characters.
579 Literal, // Data is C language style string with \ escape codes.
580 Signed, // Convert a signed integer to a string.
581 Unsigned, // Convert an unsigned integer to a string.
582 Decimal, // Convert a real number to a string in decimal format.
583 Exponent, // Convert a real number to a string in exponent format.
584 Printf, // Formatted output, sprintf() style function.
585 NumConversionTypes
587 /* Type of conversion to make in the conversion constructors.
590 /* Contruct a new string converting from the spcified data source into
591 a string array.
593 PString(
594 ConversionType type, ///< Type of data source for conversion.
595 const char * str, ///< String to convert.
596 ... ///< Extra parameters for #sprintf()# call.
598 PString(
599 ConversionType type, ///< Type of data source for conversion.
600 long value, ///< Integer value to convert.
601 unsigned base = 10 ///< Number base to use for the integer conversion.
603 PString(
604 ConversionType type, ///< Type of data source for conversion.
605 double value, ///< Floating point value to convert.
606 unsigned places ///< Number of decimals in real number output.
609 /**Assign the string to the current object. The current instance then
610 becomes another reference to the same string in the #str#
611 parameter.
613 @return
614 reference to the current PString object.
616 PString & operator=(
617 const PString & str ///< New string to assign.
620 /**Assign the C string to the current object. The current instance then
621 becomes a unique reference to a copy of the #cstr# parameter.
622 The #cstr# parameter is typically a literal string, eg:
623 \begin{verbatim}
624 myStr = "fred";
625 \end{verbatim}
626 @return
627 reference to the current PString object.
629 PString & operator=(
630 const char * cstr ///< C string to assign.
633 /**Assign the character to the current object. The current instance then
634 becomes a unique reference to a copy of the character parameter. eg:
635 \begin{verbatim}
636 myStr = 'A';
637 \end{verbatim}
638 @return
639 reference to the current PString object.
641 PString & operator=(
642 char ch ///< Character to assign.
645 /**Assign a string from the integer type.
646 This will create a simple base 10, shortest length conversion of the
647 integer (with sign character if appropriate) into the string.
649 PString & operator=(
650 short n ///< Integer to convert
653 /**Assign a string from the integer type.
654 This will create a simple base 10, shortest length conversion of the
655 integer (with sign character if appropriate) into the string.
657 PString & operator=(
658 unsigned short n ///< Integer to convert
661 /**Assign a string from the integer type.
662 This will create a simple base 10, shortest length conversion of the
663 integer (with sign character if appropriate) into the string.
665 PString & operator=(
666 int n ///< Integer to convert
669 /**Assign a string from the integer type.
670 This will create a simple base 10, shortest length conversion of the
671 integer (with sign character if appropriate) into the string.
673 PString & operator=(
674 unsigned int n ///< Integer to convert
677 /**Assign a string from the integer type.
678 This will create a simple base 10, shortest length conversion of the
679 integer (with sign character if appropriate) into the string.
681 PString & operator=(
682 long n ///< Integer to convert
685 /**Assign a string from the integer type.
686 This will create a simple base 10, shortest length conversion of the
687 integer (with sign character if appropriate) into the string.
689 PString & operator=(
690 unsigned long n ///< Integer to convert
693 /**Assign a string from the integer type.
694 This will create a simple base 10, shortest length conversion of the
695 integer (with sign character if appropriate) into the string.
697 PString & operator=(
698 PInt64 n ///< Integer to convert
701 /**Assign a string from the integer type.
702 This will create a simple base 10, shortest length conversion of the
703 integer (with sign character if appropriate) into the string.
705 PString & operator=(
706 PUInt64 n ///< Integer to convert
709 /**Make the current string empty
711 virtual PString & MakeEmpty();
713 /**Return an empty string.
715 static PString Empty();
716 //@}
718 /**@name Overrides from class PObject */
719 //@{
720 /**Make a complete duplicate of the string. Note that the data in the
721 array of characters is duplicated as well and the new object is a
722 unique reference to that data.
724 virtual PObject * Clone() const;
726 /**Get the relative rank of the two strings. The system standard function,
727 eg strcmp(), is used.
729 @return
730 comparison of the two objects, #EqualTo# for same,
731 #LessThan# for #obj# logically less than the
732 object and #GreaterThan# for #obj# logically
733 greater than the object.
735 virtual Comparison Compare(
736 const PObject & obj ///< Other PString to compare against.
737 ) const;
739 /**Output the string to the specified stream.
741 virtual void PrintOn(
742 ostream & strm ///< I/O stream to output to.
743 ) const;
745 /**Input the string from the specified stream. This will read all
746 characters until a end of line is reached. The end of line itself is
747 {\bf not} placed in the string, however it {\bf is} removed from
748 the stream.
750 virtual void ReadFrom(
751 istream & strm ///< I/O stream to input from.
754 /**Calculate a hash value for use in sets and dictionaries.
756 The hash function for strings will produce a value based on the sum of
757 the first three characters of the string. This is a fairly basic
758 function and make no assumptions about the string contents. A user may
759 descend from PString and override the hash function if they can take
760 advantage of the types of strings being used, eg if all strings start
761 with the letter 'A' followed by 'B or 'C' then the current hash function
762 will not perform very well.
764 @return
765 hash value for string.
767 virtual PINDEX HashFunction() const;
768 //@}
770 /**@name Overrides from class PContainer */
771 //@{
772 /**Set the size of the string. A new string may be allocated to accomodate
773 the new number of characters. If the string increases in size then the
774 new characters are initialised to zero. If the string is made smaller
775 then the data beyond the new size is lost.
777 Note that this function will break the current instance from multiple
778 references to an array. A new array is allocated and the data from the
779 old array copied to it.
781 @return
782 TRUE if the memory for the array was allocated successfully.
784 virtual BOOL SetSize(
785 PINDEX newSize ///< New size of the array in elements.
788 /**Determine if the string is empty. This is semantically slightly
789 different from the usual #PContainer::IsEmpty()# function. It does
790 not test for #PContainer::GetSize()# equal to zero, it tests for
791 #GetLength()# equal to zero.
793 @return
794 TRUE if no non-null characters in string.
796 virtual BOOL IsEmpty() const;
798 /**Make this instance to be the one and only reference to the container
799 contents. This implicitly does a clone of the contents of the container
800 to make a unique reference. If the instance was already unique then
801 the function does nothing.
803 @return
804 TRUE if the instance was already unique.
806 virtual BOOL MakeUnique();
807 //@}
810 /**@name Size/Length functions */
811 //@{
812 /**Set the actual memory block array size to the minimum required to hold
813 the current string contents.
815 Note that this function will break the current instance from multiple
816 references to the string. A new string buffer is allocated and the data
817 from the old string buffer copied to it.
819 @return
820 TRUE if new memory block successfully allocated.
822 BOOL MakeMinimumSize();
824 /**Determine the length of the null terminated string. This is different
825 from #PContainer::GetSize()# which returns the amount of memory
826 allocated to the string. This is often, though no necessarily, one
827 larger than the length of the string.
829 @return
830 length of the null terminated string.
832 PINLINE PINDEX GetLength() const;
834 /**Determine if the string is NOT empty. This is semantically identical
835 to executing !IsEmpty() on the string.
837 @return
838 TRUE if non-null characters in string.
840 bool operator!() const;
841 //@}
843 /**@name Concatenation operators **/
844 //@{
845 /**Concatenate two strings to produce a third. The original strings are
846 not modified, an entirely new unique reference to a string is created.
848 @return
849 new string with concatenation of the object and parameter.
851 PString operator+(
852 const PString & str ///< String to concatenate.
853 ) const;
855 /**Concatenate a C string to a PString to produce a third. The original
856 string is not modified, an entirely new unique reference to a string
857 is created. The #cstr# parameter is typically a literal
858 string, eg:
859 \begin{verbatim}
860 myStr = aStr + "fred";
861 \end{verbatim}
863 @return
864 new string with concatenation of the object and parameter.
866 PString operator+(
867 const char * cstr ///< C string to concatenate.
868 ) const;
870 /**Concatenate a single character to a PString to produce a third. The
871 original string is not modified, an entirely new unique reference to a
872 string is created. The #ch# parameter is typically a
873 literal, eg:
874 \begin{verbatim}
875 myStr = aStr + '!';
876 \end{verbatim}
878 @return
879 new string with concatenation of the object and parameter.
881 PString operator+(
882 char ch ///< Character to concatenate.
883 ) const;
885 /**Concatenate a PString to a C string to produce a third. The original
886 string is not modified, an entirely new unique reference to a string
887 is created. The #cstr# parameter is typically a literal
888 string, eg:
889 \begin{verbatim}
890 myStr = "fred" + aStr;
891 \end{verbatim}
893 @return
894 new string with concatenation of the object and parameter.
896 friend PString operator+(
897 const char * cstr, ///< C string to be concatenated to.
898 const PString & str ///< String to concatenate.
901 /**Concatenate a PString to a single character to produce a third. The
902 original string is not modified, an entirely new unique reference to a
903 string is created. The #c# parameter is typically a literal,
905 \begin{verbatim}
906 myStr = '!' + aStr;
907 \end{verbatim}
909 @return
910 new string with concatenation of the object and parameter.
912 friend PString operator+(
913 char c, ///< Character to be concatenated to.
914 const PString & str ///< String to concatenate.
917 /**Concatenate a string to another string, modifiying that string.
919 @return
920 reference to string that was concatenated to.
922 PString & operator+=(
923 const PString & str ///< String to concatenate.
926 /**Concatenate a C string to a PString, modifiying that string. The
927 #cstr# parameter is typically a literal string, eg:
928 \begin{verbatim}
929 myStr += "fred";
930 \end{verbatim}
932 @return
933 reference to string that was concatenated to.
935 PString & operator+=(
936 const char * cstr ///< C string to concatenate.
939 /**Concatenate a single character to a PString. The #ch#
940 parameter is typically a literal, eg:
941 \begin{verbatim}
942 myStr += '!';
943 \end{verbatim}
945 @return
946 new string with concatenation of the object and parameter.
948 PString & operator+=(
949 char ch ///< Character to concatenate.
953 /**Concatenate two strings to produce a third. The original strings are
954 not modified, an entirely new unique reference to a string is created.
956 @return
957 new string with concatenation of the object and parameter.
959 PString operator&(
960 const PString & str ///< String to concatenate.
961 ) const;
963 /**Concatenate a C string to a PString to produce a third. The original
964 string is not modified, an entirely new unique reference to a string
965 is created. The #cstr# parameter is typically a literal
966 string, eg:
967 \begin{verbatim}
968 myStr = aStr & "fred";
969 \end{verbatim}
971 This function differes from operator+ in that it assures there is at
972 least one space between the strings. Exactly one space is added if
973 there is not a space at the end of the first or beggining of the last
974 string.
976 @return
977 new string with concatenation of the object and parameter.
979 PString operator&(
980 const char * cstr ///< C string to concatenate.
981 ) const;
983 /**Concatenate a single character to a PString to produce a third. The
984 original string is not modified, an entirely new unique reference to a
985 string is created. The #ch# parameter is typically a
986 literal, eg:
987 \begin{verbatim}
988 myStr = aStr & '!';
989 \end{verbatim}
991 This function differes from operator+ in that it assures there is at
992 least one space between the strings. Exactly one space is added if
993 there is not a space at the end of the first or beggining of the last
994 string.
996 @return
997 new string with concatenation of the object and parameter.
999 PString operator&(
1000 char ch ///< Character to concatenate.
1001 ) const;
1003 /**Concatenate a PString to a C string to produce a third. The original
1004 string is not modified, an entirely new unique reference to a string
1005 is created. The #cstr# parameter is typically a literal
1006 string, eg:
1007 \begin{verbatim}
1008 myStr = "fred" & aStr;
1009 \end{verbatim}
1011 This function differes from operator+ in that it assures there is at
1012 least one space between the strings. Exactly one space is added if
1013 there is not a space at the end of the first or beggining of the last
1014 string.
1016 @return
1017 new string with concatenation of the object and parameter.
1019 friend PString operator&(
1020 const char * cstr, ///< C string to be concatenated to.
1021 const PString & str ///< String to concatenate.
1024 /**Concatenate a PString to a single character to produce a third. The
1025 original string is not modified, an entirely new unique reference to a
1026 string is created. The #c# parameter is typically a literal,
1028 \begin{verbatim}
1029 myStr = '!' & aStr;
1030 \end{verbatim}
1032 This function differes from #operator+# in that it assures there is at
1033 least one space between the strings. Exactly one space is added if
1034 there is not a space at the end of the first or beggining of the last
1035 string.
1037 @return
1038 new string with concatenation of the object and parameter.
1040 friend PString operator&(
1041 char ch, ///< Character to be concatenated to.
1042 const PString & str ///< String to concatenate.
1045 /**Concatenate a string to another string, modifiying that string.
1047 @return
1048 reference to string that was concatenated to.
1050 PString & operator&=(
1051 const PString & str ///< String to concatenate.
1054 /**Concatenate a C string to a PString, modifiying that string. The
1055 #cstr# parameter is typically a literal string, eg:
1056 \begin{verbatim}
1057 myStr &= "fred";
1058 \end{verbatim}
1060 This function differes from operator+ in that it assures there is at
1061 least one space between the strings. Exactly one space is added if
1062 there is not a space at the end of the first or beggining of the last
1063 string.
1065 @return
1066 reference to string that was concatenated to.
1068 PString & operator&=(
1069 const char * cstr ///< C string to concatenate.
1073 /**Concatenate a character to a PString, modifiying that string. The
1074 #ch# parameter is typically a literal string, eg:
1075 \begin{verbatim}
1076 myStr &= '!';
1077 \end{verbatim}
1079 This function differes from operator+ in that it assures there is at
1080 least one space between the strings. Exactly one space is added if
1081 there is not a space at the end of the first or beggining of the last
1082 string.
1084 @return
1085 reference to string that was concatenated to.
1087 PString & operator&=(
1088 char ch ///< Character to concatenate.
1090 //@}
1093 /**@name Comparison operators */
1094 //@{
1095 /**Compare two strings using case insensitive comparison.
1097 @return
1098 TRUE if equal.
1100 bool operator*=(
1101 const PString & str ///< PString object to compare against.
1102 ) const;
1104 /**Compare two strings using the #PObject::Compare()# function. This
1105 is identical to the #PObject# class function but is necessary due
1106 to other overloaded versions.
1108 @return
1109 TRUE if equal.
1111 bool operator==(
1112 const PObject & str ///< PString object to compare against.
1113 ) const;
1115 /**Compare two strings using the #PObject::Compare()# function. This
1116 is identical to the #PObject# class function but is necessary due
1117 to other overloaded versions.
1119 @return
1120 TRUE if not equal.
1122 bool operator!=(
1123 const PObject & str ///< PString object to compare against.
1124 ) const;
1126 /**Compare two strings using the #PObject::Compare()# function. This
1127 is identical to the #PObject# class function but is necessary due
1128 to other overloaded versions.
1130 @return
1131 TRUE if less than.
1133 bool operator<(
1134 const PObject & str ///< PString object to compare against.
1135 ) const;
1137 /**Compare two strings using the #PObject::Compare()# function. This
1138 is identical to the #PObject# class function but is necessary due
1139 to other overloaded versions.
1141 @return
1142 TRUE if greater than.
1144 bool operator>(
1145 const PObject & str ///< PString object to compare against.
1146 ) const;
1148 /**Compare two strings using the #PObject::Compare()# function. This
1149 is identical to the #PObject# class function but is necessary due
1150 to other overloaded versions.
1152 @return
1153 TRUE if less than or equal.
1155 bool operator<=(
1156 const PObject & str ///< PString object to compare against.
1157 ) const;
1159 /**Compare two strings using the #PObject::Compare()# function. This
1160 is identical to the #PObject# class function but is necessary due
1161 to other overloaded versions.
1163 @return
1164 TRUE if greater than or equal.
1166 bool operator>=(
1167 const PObject & str ///< PString object to compare against.
1168 ) const;
1171 /**Compare a PString to a C string using a case insensitive compare
1172 function. The #cstr# parameter is typically a literal string,
1174 \begin{verbatim}
1175 if (myStr == "fred")
1176 \end{verbatim}
1178 @return
1179 TRUE if equal.
1181 bool operator*=(
1182 const char * cstr ///< C string to compare against.
1183 ) const;
1185 /**Compare a PString to a C string using the ##Compare()##
1186 function. The #cstr# parameter is typically a literal string,
1188 \begin{verbatim}
1189 if (myStr == "fred")
1190 \end{verbatim}
1192 @return
1193 TRUE if equal.
1195 bool operator==(
1196 const char * cstr ///< C string to compare against.
1197 ) const;
1199 /**Compare a PString to a C string using the #PObject::Compare()#
1200 function. The #cstr# parameter is typically a literal
1201 string, eg:
1202 \begin{verbatim}
1203 if (myStr != "fred")
1204 \end{verbatim}
1206 @return
1207 TRUE if not equal.
1209 bool operator!=(
1210 const char * cstr ///< C string to compare against.
1211 ) const;
1213 /**Compare a PString to a C string using the #PObject::Compare()#
1214 function. The #cstr# parameter is typically a literal
1215 string, eg:
1216 \begin{verbatim}
1217 if (myStr < "fred")
1218 \end{verbatim}
1220 @return
1221 TRUE if less than.
1223 bool operator<(
1224 const char * cstr ///< C string to compare against.
1225 ) const;
1227 /**Compare a PString to a C string using the #PObject::Compare()#
1228 function. The #cstr# parameter is typically a literal
1229 string, eg:
1230 \begin{verbatim}
1231 if (myStr > "fred")
1232 \end{verbatim}
1234 @return
1235 TRUE if greater than.
1237 bool operator>(
1238 const char * cstr ///< C string to compare against.
1239 ) const;
1241 /**Compare a PString to a C string using the #PObject::Compare()#
1242 function. The #cstr# parameter is typically a literal
1243 string, eg:
1244 \begin{verbatim}
1245 if (myStr <= "fred")
1246 \end{verbatim}
1248 @return
1249 TRUE if less than or equal.
1251 bool operator<=(
1252 const char * cstr ///< C string to compare against.
1253 ) const;
1255 /**Compare a PString to a C string using the #PObject::Compare()#
1256 function. The #cstr# parameter is typically a literal
1257 string, eg:
1258 \begin{verbatim}
1259 if (myStr >= "fred")
1260 \end{verbatim}
1262 @return
1263 TRUE if greater than or equal.
1265 bool operator>=(
1266 const char * cstr ///< C string to compare against.
1267 ) const;
1269 /**Compare a string against a substring of the object.
1270 This will compare at most #count# characters of the string, starting at
1271 the specified #offset#, against that many characters of the #str#
1272 parameter. If #count# greater than the length of the #str# parameter
1273 then the actual length of #str# is used. If #count# and the length of
1274 #str# are greater than the length of the string remaining from the
1275 #offset# then FALSE is returned.
1277 @return
1278 TRUE if str is a substring of .
1280 Comparison NumCompare(
1281 const PString & str, ///< PString object to compare against.
1282 PINDEX count = P_MAX_INDEX, ///< Number of chacracters in str to compare
1283 PINDEX offset = 0 ///< Offset into string to compare
1284 ) const;
1286 /**Compare a string against a substring of the object.
1287 This will compare at most #count# characters of the string, starting at
1288 the specified #offset#, against that many characters of the #str#
1289 parameter. If #count# greater than the length of the #str# parameter
1290 then the actual length of #str# is used. If #count# and the length of
1291 #str# are greater than the length of the string remaining from the
1292 #offset# then FALSE is returned.
1294 @return
1295 TRUE if str is a substring of .
1297 Comparison NumCompare(
1298 const char * cstr, ///< C string object to compare against.
1299 PINDEX count = P_MAX_INDEX, ///< Number of chacracters in str to compare
1300 PINDEX offset = 0 ///< Offset into string to compare
1301 ) const;
1302 //@}
1305 /**@name Search & replace functions */
1306 //@{
1307 /** Locate the position within the string of the character. */
1308 PINDEX Find(
1309 char ch, ///< Character to search for in string.
1310 PINDEX offset = 0 ///< Offset into string to begin search.
1311 ) const;
1313 /** Locate the position within the string of the substring. */
1314 PINDEX Find(
1315 const PString & str, ///< String to search for in string.
1316 PINDEX offset = 0 ///< Offset into string to begin search.
1317 ) const;
1319 /* Locate the position within the string of the character or substring. The
1320 search will begin at the character offset provided.
1322 If #offset# is beyond the length of the string, then the
1323 function will always return #P_MAX_INDEX#.
1325 The matching will be for identical character or string. If a search
1326 ignoring case is required then the string should be converted to a
1327 #PCaselessString# before the search is made.
1329 @return
1330 position of character or substring in the string, or P_MAX_INDEX if the
1331 character or substring is not in the string.
1333 PINDEX Find(
1334 const char * cstr, ///< C string to search for in string.
1335 PINDEX offset = 0 ///< Offset into string to begin search.
1336 ) const;
1338 /** Locate the position of the last matching character. */
1339 PINDEX FindLast(
1340 char ch, ///< Character to search for in string.
1341 PINDEX offset = P_MAX_INDEX ///< Offset into string to begin search.
1342 ) const;
1344 /** Locate the position of the last matching substring. */
1345 PINDEX FindLast(
1346 const PString & str, ///< String to search for in string.
1347 PINDEX offset = P_MAX_INDEX ///< Offset into string to begin search.
1348 ) const;
1350 /**Locate the position of the last matching substring.
1351 Locate the position within the string of the last matching character or
1352 substring. The search will begin at the character offset provided,
1353 moving backward through the string.
1355 If #offset# is beyond the length of the string, then the
1356 search begins at the end of the string. If #offset# is zero
1357 then the function always returns #P_MAX_INDEX#.
1359 The matching will be for identical character or string. If a search
1360 ignoring case is required then the string should be converted to a
1361 #PCaselessString# before the search is made.
1363 @return
1364 position of character or substring in the string, or P_MAX_INDEX if the
1365 character or substring is not in the string.
1367 PINDEX FindLast(
1368 const char * cstr, ///< C string to search for in string.
1369 PINDEX offset = P_MAX_INDEX ///< Offset into string to begin search.
1370 ) const;
1372 /** Locate the position of one of the characters in the set. */
1373 PINDEX FindOneOf(
1374 const PString & set, ///< String of characters to search for in string.
1375 PINDEX offset = 0 ///< Offset into string to begin search.
1376 ) const;
1378 /**Locate the position of one of the characters in the set.
1379 The search will begin at the character offset provided.
1381 If #offset# is beyond the length of the string, then the
1382 function will always return #P_MAX_INDEX#.
1384 The matching will be for identical character or string. If a search
1385 ignoring case is required then the string should be converted to a
1386 #PCaselessString# before the search is made.
1388 @return
1389 position of character in the string, or P_MAX_INDEX if no characters
1390 from the set are in the string.
1392 PINDEX FindOneOf(
1393 const char * cset, ///< C string of characters to search for in string.
1394 PINDEX offset = 0 ///< Offset into string to begin search.
1395 ) const;
1397 /** Locate the position of character not in the set. */
1398 PINDEX FindSpan(
1399 const PString & set, ///< String of characters to search for in string.
1400 PINDEX offset = 0 ///< Offset into string to begin search.
1401 ) const;
1403 /**Locate the position of character not in the set.
1404 The search will begin at the character offset provided.
1406 If #offset# is beyond the length of the string, or every character
1407 in the string is a member of the set, then the function will always
1408 return #P_MAX_INDEX#.
1410 The matching will be for identical character or string. If a search
1411 ignoring case is required then the string should be converted to a
1412 #PCaselessString# before the search is made.
1414 @return
1415 position of character not in the set, or P_MAX_INDEX if all characters
1416 from the string are in the set.
1418 PINDEX FindSpan(
1419 const char * cset, ///< C string of characters to search for in string.
1420 PINDEX offset = 0 ///< Offset into string to begin search.
1421 ) const;
1423 /**Locate the position within the string of one of the regular expression.
1424 The search will begin at the character offset provided.
1426 If #offset# is beyond the length of the string, then the
1427 function will always return #P_MAX_INDEX#.
1429 @return
1430 position of regular expression in the string, or P_MAX_INDEX if no
1431 characters from the set are in the string.
1433 PINDEX FindRegEx(
1434 const PRegularExpression & regex, ///< regular expression to find
1435 PINDEX offset = 0 ///< Offset into string to begin search.
1436 ) const;
1438 /**Locate the position within the string of one of the regular expression.
1439 The search will begin at the character offset provided.
1441 If #offset# is beyond the length of the string, then the
1442 function will always return #P_MAX_INDEX#.
1444 @return
1445 position of regular expression in the string, or P_MAX_INDEX if no
1446 characters from the set are in the string.
1448 BOOL FindRegEx(
1449 const PRegularExpression & regex, ///< regular expression to find
1450 PINDEX & pos, ///< Position of matched expression
1451 PINDEX & len, ///< Length of matched expression
1452 PINDEX offset = 0, ///< Offset into string to begin search.
1453 PINDEX maxPos = P_MAX_INDEX ///< Maximum offset into string
1454 ) const;
1457 /**Locate the substring within the string and replace it with the specifed
1458 substring. The search will begin at the character offset provided.
1460 If #offset# is beyond the length of the string, then the
1461 function will do nothing.
1463 The matching will be for identical character or string. If a search
1464 ignoring case is required then the string should be converted to a
1465 #PCaselessString# before the search is made.
1467 void Replace(
1468 const PString & target, ///< Text to be removed.
1469 const PString & subs, ///< String to be inserted into the gaps created
1470 BOOL all = FALSE, ///< Replace all occurrences of target text.
1471 PINDEX offset = 0 ///< Offset into string to begin search.
1474 /**Splice the string into the current string at the specified position. The
1475 specified number of bytes are removed from the string.
1477 Note that this function will break the current instance from multiple
1478 references to the string. A new string buffer is allocated and the data
1479 from the old string buffer copied to it.
1481 void Splice(
1482 const PString & str, ///< Substring to insert.
1483 PINDEX pos, ///< Position in string to insert the substring.
1484 PINDEX len = 0 ///< Length of section to remove.
1487 /**Splice the string into the current string at the specified position. The
1488 specified number of bytes are removed from the string.
1490 Note that this function will break the current instance from multiple
1491 references to the string. A new string buffer is allocated and the data
1492 from the old string buffer copied to it.
1494 void Splice(
1495 const char * cstr, ///< Substring to insert.
1496 PINDEX pos, ///< Position in string to insert the substring.
1497 PINDEX len = 0 ///< Length of section to remove.
1500 /**Remove the substring from the string.
1502 Note that this function will break the current instance from multiple
1503 references to the string. A new string buffer is allocated and the data
1504 from the old string buffer copied to it.
1506 void Delete(
1507 PINDEX start, ///< Position in string to remove.
1508 PINDEX len ///< Number of characters to delete.
1510 //@}
1513 /**@name Sub-string functions */
1514 //@{
1515 /**Extract a portion of the string into a new string. The original string
1516 is not changed and a new unique reference to a string is returned.
1518 The substring is returned inclusive of the characters at the
1519 #start# and #end# positions.
1521 If the #end# position is greater than the length of the
1522 string then all characters from the #start# up to the end of
1523 the string are returned.
1525 If #start# is greater than the length of the string or
1526 #end# is before #start# then an empty string is
1527 returned.
1529 @return
1530 substring of the source string.
1532 PString operator()(
1533 PINDEX start, ///< Starting position of the substring.
1534 PINDEX end ///< Ending position of the substring.
1535 ) const;
1537 /**Extract a portion of the string into a new string. The original string
1538 is not changed and a new unique reference to a string is returned.
1540 A substring from the beginning of the string for the number of
1541 characters specified is extracted.
1543 If #len# is greater than the length of the string then all
1544 characters to the end of the string are returned.
1546 If #len# is zero then an empty string is returned.
1548 @return
1549 substring of the source string.
1551 PString Left(
1552 PINDEX len ///< Number of characters to extract.
1553 ) const;
1555 /**Extract a portion of the string into a new string. The original string
1556 is not changed and a new unique reference to a string is returned.
1558 A substring from the end of the string for the number of characters
1559 specified is extracted.
1561 If #len# is greater than the length of the string then all
1562 characters to the beginning of the string are returned.
1564 If #len# is zero then an empty string is returned.
1566 @return
1567 substring of the source string.
1569 PString Right(
1570 PINDEX len ///< Number of characters to extract.
1571 ) const;
1573 /**Extract a portion of the string into a new string. The original string
1574 is not changed and a new unique reference to a string is returned.
1576 A substring from the #start# position for the number of
1577 characters specified is extracted.
1579 If #len# is greater than the length of the string from the
1580 #start# position then all characters to the end of the
1581 string are returned.
1583 If #start# is greater than the length of the string or
1584 #len# is zero then an empty string is returned.
1586 @return
1587 substring of the source string.
1589 PString Mid(
1590 PINDEX start, ///< Starting position of the substring.
1591 PINDEX len = P_MAX_INDEX ///< Number of characters to extract.
1592 ) const;
1595 /**Create a string consisting of all characters from the source string
1596 except all spaces at the beginning of the string. The original string
1597 is not changed and a new unique reference to a string is returned.
1599 @return
1600 string with leading spaces removed.
1602 PString LeftTrim() const;
1604 /**Create a string consisting of all characters from the source string
1605 except all spaces at the end of the string. The original string is not
1606 changed and a new unique reference to a string is returned.
1608 @return
1609 string with trailing spaces removed.
1611 PString RightTrim() const;
1613 /**Create a string consisting of all characters from the source string
1614 except all spaces at the beginning and end of the string. The original
1615 string is not changed and a new unique reference to a string is
1616 returned.
1618 @return
1619 string with leading and trailing spaces removed.
1621 PString Trim() const;
1624 /**Create a string consisting of all characters from the source string
1625 with all upper case letters converted to lower case. The original
1626 string is not changed and a new unique reference to a string is
1627 returned.
1629 @return
1630 string with upper case converted to lower case.
1632 PString ToLower() const;
1634 /**Create a string consisting of all characters from the source string
1635 with all lower case letters converted to upper case. The original
1636 string is not changed and a new unique reference to a string is
1637 returned.
1639 @return
1640 string with lower case converted to upper case.
1642 PString ToUpper() const;
1645 /** Split the string into an array of substrings. */
1646 PStringArray Tokenise(
1647 const PString & separators,
1648 ///< A string for the set of separator characters that delimit tokens.
1649 BOOL onePerSeparator = TRUE
1650 ///< Flag for if there are empty tokens between consecutive separators.
1651 ) const;
1652 /**Split the string into an array of substrings.
1653 Divide the string into an array of substrings delimited by characters
1654 from the specified set.
1656 There are two options for the tokenisation, the first is where the
1657 #onePerSeparator# is TRUE. This form will produce a token
1658 for each delimiter found in the set. Thus the string ",two,three,,five"
1659 would be split into 5 substrings; "", "two", "three", "" and "five".
1661 The second form where #onePerSeparator# is FALSE is used
1662 where consecutive delimiters do not constitute a empty token. In this
1663 case the string " a list of words " would be split into 5 substrings;
1664 "a", "list", "of", "words" and "".
1666 There is an important distinction when there are delimiters at the
1667 beginning or end of the source string. In the first case there will be
1668 empty strings at the end of the array. In the second case delimeters
1669 at the beginning of the source string are ignored and if there are one
1670 or more trailing delimeters, they will yeild a single empty string at
1671 the end of the array.
1673 @return
1674 an array of substring for each token in the string.
1676 PStringArray Tokenise(
1677 const char * cseparators,
1678 ///< A C string for the set of separator characters that delimit tokens.
1679 BOOL onePerSeparator = TRUE
1680 ///< Flag for if there are empty tokens between consecutive separators.
1681 ) const;
1683 /**Split the string into individual lines. The line delimiters may be a
1684 carriage return ('\r'), a line feed ('\n') or a carriage return and
1685 line feed pair ("\r\n"). A line feed and carriage return pair ("\n\r")
1686 would yield a blank line. between the characters.
1688 The #Tokenise()# function should not be used to split a string
1689 into lines as a #"\r\n"# pair consitutes a single line
1690 ending. The #Tokenise()# function would produce a blank line in
1691 between them.
1693 @return
1694 string array with a substring for each line in the string.
1696 PStringArray Lines() const;
1697 //@}
1699 /**@name Conversion functions */
1700 //@{
1701 /**Concatenate a formatted output to the string. This is identical to the
1702 standard C library #sprintf()# function, but appends its
1703 output to the string.
1705 This function makes the assumption that there is less the 1000
1706 characters of formatted output. The function will assert if this occurs.
1708 Note that this function will break the current instance from multiple
1709 references to the string. A new string buffer is allocated and the data
1710 from the old string buffer copied to it.
1712 @return
1713 reference to the current string object.
1715 PString & sprintf(
1716 const char * cfmt, ///< C string for output format.
1717 ... ///< Extra parameters for #sprintf()# call.
1720 /**Produce formatted output as a string. This is identical to the standard
1721 C library #sprintf()# function, but sends its output to a
1722 #PString#.
1724 This function makes the assumption that there is less the 1000
1725 characters of formatted output. The function will assert if this occurs.
1727 Note that this function will break the current instance from multiple
1728 references to the string. A new string buffer is allocated and the data
1729 from the old string buffer copied to it.
1731 @return
1732 reference to the current string object.
1734 friend PString psprintf(
1735 const char * cfmt, ///< C string for output format.
1736 ... ///< Extra parameters for #sprintf()# call.
1739 /** Concatenate a formatted output to the string. */
1740 PString & vsprintf(
1741 const PString & fmt, ///< String for output format.
1742 va_list args ///< Extra parameters for #sprintf()# call.
1744 /**Concatenate a formatted output to the string. This is identical to the
1745 standard C library #vsprintf()# function, but appends its
1746 output to the string.
1748 This function makes the assumption that there is less the 1000
1749 characters of formatted output. The function will assert if this occurs.
1751 Note that this function will break the current instance from multiple
1752 references to the string. A new string buffer is allocated and the data
1753 from the old string buffer copied to it.
1755 @return
1756 reference to the current string object.
1758 PString & vsprintf(
1759 const char * cfmt, ///< C string for output format.
1760 va_list args ///< Extra parameters for #sprintf()# call.
1763 /** Produce formatted output as a string. */
1764 friend PString pvsprintf(
1765 const char * cfmt, ///< C string for output format.
1766 va_list args ///< Extra parameters for #sprintf()# call.
1768 /**Produce formatted output as a string. This is identical to the standard
1769 C library #vsprintf()# function, but sends its output to a
1770 #PString#.
1772 This function makes the assumption that there is less the 1000
1773 characters of formatted output. The function will assert if this occurs.
1775 Note that this function will break the current instance from multiple
1776 references to the string. A new string buffer is allocated and the data
1777 from the old string buffer copied to it.
1779 @return
1780 reference to the current string object.
1782 friend PString pvsprintf(
1783 const PString & fmt, ///< String for output format.
1784 va_list args ///< Extra parameters for #sprintf()# call.
1788 /**Convert the string to an integer value using the specified number base.
1789 All characters up to the first illegal character for the number base are
1790 converted. Case is not significant for bases greater than 10.
1792 The number base may only be from 2 to 36 and the function will assert
1793 if it is not in this range.
1795 This function uses the standard C library #strtol()# function.
1797 @return
1798 integer value for the string.
1800 long AsInteger(
1801 unsigned base = 10 ///< Number base to convert the string in.
1802 ) const;
1803 /**Convert the string to an integer value using the specified number base.
1804 All characters up to the first illegal character for the number base are
1805 converted. Case is not significant for bases greater than 10.
1807 The number base may only be from 2 to 36 and the function will assert
1808 if it is not in this range.
1810 This function uses the standard C library #strtoul()# function.
1812 @return
1813 integer value for the string.
1815 DWORD AsUnsigned(
1816 unsigned base = 10 ///< Number base to convert the string in.
1817 ) const;
1818 /**Convert the string to an integer value using the specified number base.
1819 All characters up to the first illegal character for the number base are
1820 converted. Case is not significant for bases greater than 10.
1822 The number base may only be from 2 to 36 and the function will assert
1823 if it is not in this range.
1825 This function uses the standard C library #strtoq()#
1826 or #strtoul()# function.
1828 @return
1829 integer value for the string.
1831 PInt64 AsInt64(
1832 unsigned base = 10 ///< Number base to convert the string in.
1833 ) const;
1834 /**Convert the string to an integer value using the specified number base.
1835 All characters up to the first illegal character for the number base are
1836 converted. Case is not significant for bases greater than 10.
1838 The number base may only be from 2 to 36 and the function will assert
1839 if it is not in this range.
1841 This function uses the standard C library #strtouq()#
1842 or #strtoul()# function.
1844 @return
1845 integer value for the string.
1847 PUInt64 AsUnsigned64(
1848 unsigned base = 10 ///< Number base to convert the string in.
1849 ) const;
1851 /**Convert the string to a floating point number. This number may be in
1852 decimal or exponential form. All characters up to the first illegal
1853 character for a floting point number are converted.
1855 This function uses the standard C library #strtod()#
1856 function.
1858 @return
1859 floating point value for the string.
1861 double AsReal() const;
1863 /**Convert UTF-8 string to UCS-2.
1864 Note the resultant PWORDArray will have the trailing null included.
1866 PWORDArray AsUCS2() const;
1868 /**Convert a standard null terminated string to a "pascal" style string.
1869 This consists of a songle byte for the length of the string and then
1870 the string characters following it.
1872 This function will assert if the string is greater than 255 characters
1873 in length.
1875 @return
1876 byte array containing the "pascal" style string.
1878 PBYTEArray ToPascal() const;
1880 /**Convert the string to C literal string format. This will convert non
1881 printable characters to the \nnn form or for standard control characters
1882 such as line feed, to \n form. Any '"' characters are also escaped with
1883 a \ character and the entire string is enclosed in '"' characters.
1885 @return
1886 string converted to a C language literal form.
1888 PString ToLiteral() const;
1890 /**Get the internal buffer as a pointer to unsigned characters. The
1891 standard "operator const char *" function is provided by the
1892 #PCharArray# ancestor class.
1894 @return
1895 pointer to character buffer.
1897 operator const unsigned char *() const;
1899 /** Cast the PString to a std::string
1901 operator std::string () const
1902 { return std::string(theArray); }
1904 /** Cast the PString to a wide char string
1906 #ifdef _WIN32_WCE
1907 operator LPCWSTR() const
1908 { return AsUCS2(); }
1909 #endif
1910 //@}
1913 protected:
1914 void InternalFromUCS2(
1915 const WORD * ptr,
1916 PINDEX len
1918 virtual Comparison InternalCompare(
1919 PINDEX offset, // Offset into string to compare.
1920 char c // Character to compare against.
1921 ) const;
1922 virtual Comparison InternalCompare(
1923 PINDEX offset, // Offset into string to compare.
1924 PINDEX length, // Number of characters to compare.
1925 const char * cstr // C string to compare against.
1926 ) const;
1927 /* Internal function to compare the current string value against the
1928 specified C string.
1930 @return
1931 relative rank of the two strings.
1934 PString(int dummy, const PString * str);
1938 inline ostream & operator<<(ostream & stream, const PString & string)
1940 string.PrintOn(stream);
1941 return stream;
1945 //////////////////////////////////////////////////////////////////////////////
1947 /**This class is a variation of a string that ignores case. Thus in all
1948 standard comparison (#==#, #<# etc) and search
1949 (#Find()# etc) functions the case of the characters and strings is
1950 ignored.
1952 The characters in the string still maintain their case. Only the comparison
1953 operations are affected. So printing etc will still display the string as
1954 entered.
1956 class PCaselessString : public PString
1958 PCLASSINFO(PCaselessString, PString);
1960 public:
1961 /**Create a new, empty, caseless string.
1963 PCaselessString();
1965 /**Create a new caseless string, initialising it to the characters in the
1966 C string provided.
1968 PCaselessString(
1969 const char * cstr ///< C string to initialise the caseless string from.
1972 /**Create a caseless string, with a reference to the characters in the
1973 normal #PString# provided. A PCaselessString may also be provided
1974 to this constructor.
1976 PCaselessString(
1977 const PString & str ///< String to initialise the caseless string from.
1981 /**Create a caseless string from a std::string
1983 PCaselessString(
1984 const std::string & str ///< String to initialise the caseless string from.
1985 ) : PString(str)
1988 /**Assign the string to the current object. The current instance then
1989 becomes another reference to the same string in the #str#
1990 parameter.
1992 @return
1993 reference to the current PString object.
1995 PCaselessString & operator=(
1996 const PString & str ///< New string to assign.
1999 /**Assign the C string to the current object. The current instance then
2000 becomes a unique reference to a copy of the #cstr# parameter.
2001 The #cstr# parameter is typically a literal string, eg:
2002 \begin{verbatim}
2003 myStr = "fred";
2004 \end{verbatim}
2005 @return
2006 reference to the current PString object.
2008 PCaselessString & operator=(
2009 const char * cstr ///< C string to assign.
2012 /**Assign the character to the current object. The current instance then
2013 becomes a unique reference to a copy of the character parameter. eg:
2014 \begin{verbatim}
2015 myStr = 'A';
2016 \end{verbatim}
2017 @return
2018 reference to the current PString object.
2020 PCaselessString & operator=(
2021 char ch ///< Character to assign.
2025 // Overrides from class PObject
2026 /**Make a complete duplicate of the string. Note that the data in the
2027 array of characters is duplicated as well and the new object is a
2028 unique reference to that data.
2030 virtual PObject * Clone() const;
2032 protected:
2033 // Overrides from class PString
2034 virtual Comparison InternalCompare(
2035 PINDEX offset, // Offset into string to compare.
2036 char c // Character to compare against.
2037 ) const;
2038 virtual Comparison InternalCompare(
2039 PINDEX offset, // Offset into string to compare.
2040 PINDEX length, // Number of characters to compare.
2041 const char * cstr // C string to compare against.
2042 ) const;
2043 /* Internal function to compare the current string value against the
2044 specified C string.
2046 @return
2047 relative rank of the two strings or characters.
2050 PCaselessString(int dummy, const PCaselessString * str);
2053 //////////////////////////////////////////////////////////////////////////////
2055 class PStringStream;
2057 /**This class is a standard C++ stream class descendent for reading or writing
2058 streamed data to or from a #PString# class.
2060 All of the standard stream I/O operators, manipulators etc will operate on
2061 the PStringStream class.
2063 class PStringStream : public PString, public iostream
2065 PCLASSINFO(PStringStream, PString);
2067 public:
2068 /**Create a new, empty, string stream. Data may be output to this stream,
2069 but attempts to input from it will return end of file.
2071 The internal string is continually grown as required during output.
2073 PStringStream();
2075 /**Create a new, empty, string stream of a fixed size. Data may be output
2076 to this stream, but attempts to input from it will return end of file.
2077 When the fixed size is reached then no more data may be output to it.
2079 PStringStream(
2080 PINDEX fixedBufferSize
2083 /**Create a new string stream and initialise it to the provided value. The
2084 string stream references the same string buffer as the #str#
2085 parameter until any output to the string stream is attempted. The
2086 reference is then broken and the instance of the string stream becomes
2087 a unique reference to a string buffer.
2089 PStringStream(
2090 const PString & str ///< Initial value for string stream.
2093 /**Create a new string stream and initialise it with the provided value.
2094 The stream may be read or written from. Writes will append to the end of
2095 the string.
2097 PStringStream(
2098 const char * cstr ///< Initial value for the string stream.
2101 /**Make the current string empty
2103 virtual PString & MakeEmpty();
2105 /**Assign the string part of the stream to the current object. The current
2106 instance then becomes another reference to the same string in the #strm#
2107 parameter.
2109 This will reset the read pointer for input to the beginning of the
2110 string. Also, any data output to the string up until the asasignement
2111 will be lost.
2113 @return
2114 reference to the current PStringStream object.
2116 PStringStream & operator=(
2117 const PStringStream & strm
2120 /**Assign the string to the current object. The current instance then
2121 becomes another reference to the same string in the #str#
2122 parameter.
2124 This will reset the read pointer for input to the beginning of the
2125 string. Also, any data output to the string up until the asasignement
2126 will be lost.
2128 @return
2129 reference to the current PStringStream object.
2131 PStringStream & operator=(
2132 const PString & str ///< New string to assign.
2135 /**Assign the C string to the string stream. The current instance then
2136 becomes a unique reference to a copy of the #cstr#
2137 parameter. The #cstr# parameter is typically a literal
2138 string, eg:
2139 \begin{verbatim}
2140 myStr = "fred";
2141 \end{verbatim}
2143 This will reset the read pointer for input to the beginning of the
2144 string. Also, any data output to the string up until the asasignement
2145 will be lost.
2147 @return
2148 reference to the current PStringStream object.
2150 PStringStream & operator=(
2151 const char * cstr ///< C string to assign.
2154 /**Assign the character to the current object. The current instance then
2155 becomes a unique reference to a copy of the character parameter. eg:
2156 \begin{verbatim}
2157 myStr = 'A';
2158 \end{verbatim}
2159 @return
2160 reference to the current PString object.
2162 PStringStream & operator=(
2163 char ch ///< Character to assign.
2167 /// Destroy the string stream, deleting the stream buffer
2168 virtual ~PStringStream();
2171 protected:
2172 virtual void AssignContents(const PContainer & cont);
2174 private:
2175 PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
2177 class Buffer : public streambuf {
2178 public:
2179 Buffer(PStringStream & str, PINDEX size);
2180 Buffer(const Buffer & sbuf);
2181 Buffer & operator=(const Buffer & sbuf);
2182 virtual int overflow(int=EOF);
2183 virtual int underflow();
2184 virtual int sync();
2185 #ifdef __USE_STL__
2186 virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
2187 virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
2188 #else
2189 virtual streampos seekoff(streamoff, ios::seek_dir, int);
2190 #endif
2191 PStringStream & string;
2192 BOOL fixedBufferSize;
2197 class PStringList;
2198 class PSortedStringList;
2200 /**This is an array collection class of #PString# objects. It has all the
2201 usual functions for a collection, with the object types set to
2202 #PString# pointers.
2204 In addition some addition functions are added that take a const
2205 #PString# reference instead of a pointer as most standard collection
2206 functions do. This is more convenient for when string expressions are used
2207 as parameters to function in the collection.
2209 See the #PAbstractArray# and #PArray# classes and
2210 #PDECLARE_ARRAY# macro for more information.
2212 #ifdef DOC_PLUS_PLUS
2213 class PStringArray : public PArray {
2214 #endif
2215 PDECLARE_ARRAY(PStringArray, PString);
2216 public:
2217 /**@name Construction */
2218 //@{
2219 /**Create a PStringArray from the array of C strings. If count is
2220 P_MAX_INDEX then strarr is assumed to point to an array of strings
2221 where the last pointer is NULL.
2223 PStringArray(
2224 PINDEX count, ///< Count of strings in array
2225 char const * const * strarr, ///< Array of C strings
2226 BOOL caseless = FALSE ///< New strings are to be PCaselessStrings
2228 /**Create a PStringArray of length one from the single string.
2230 PStringArray(
2231 const PString & str ///< Single string to convert to an array of one.
2233 /**Create a PStringArray from the list of strings.
2235 PStringArray(
2236 const PStringList & list ///< List of strings to convert to array.
2238 /**Create a PStringArray from the sorted list strings.
2240 PStringArray(
2241 const PSortedStringList & list ///< List of strings to convert to array.
2245 * Create a PStringArray from a vector of PStrings
2247 PStringArray(
2248 const std::vector<PString> & vec
2251 for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
2252 AppendString(*r);
2256 * Create a PStringArray from a vector of std::string
2258 PStringArray(
2259 const std::vector<std::string> & vec
2262 for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
2263 AppendString(PString(*r));
2267 * Create a PStringArray from an STL container
2269 template <typename stlContainer>
2270 static PStringArray container(
2271 const stlContainer & vec
2274 PStringArray list;
2275 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
2276 list.AppendString(PString(*r));
2277 return list;
2280 //@}
2282 /**@name Overrides from class PObject */
2283 //@{
2284 /** Input the contents of the object from the stream. This is
2285 primarily used by the standard #operator>># function.
2287 The default behaviour reads '\n' separated strings until !strm.good().
2289 virtual void ReadFrom(
2290 istream &strm // Stream to read the objects contents from.
2292 //@}
2294 /**@name New functions for class */
2295 //@{
2296 /**As for #GetValuesIndex()# but takes a PString argument so that
2297 literals will be automatically converted.
2299 @return
2300 Index of string in array or P_MAX_INDEX if not found.
2302 PINDEX GetStringsIndex(
2303 const PString & str ///< String to search for index of
2304 ) const;
2306 PString operator[](
2307 PINDEX index ///< Index position in the collection of the object.
2308 ) const;
2310 /**Retrieve a reference to the object in the array. If there was not an
2311 object at that ordinal position or the index was beyond the size of the
2312 array then the function will create a new one.
2314 @return
2315 reference to the object at #index# position.
2317 PString & operator[](
2318 PINDEX index ///< Index position in the collection of the object.
2321 /** Append a string to the array
2323 PINDEX AppendString(
2324 const PString & str ///< String to append.
2327 /**Concatenate a PString or PStringArray to the array
2329 @return
2330 The PStringArray with the new items appended
2332 PStringArray & operator +=(const PStringArray & array);
2333 PStringArray & operator +=(const PString & str);
2336 /**Create a new PStringArray, and add PString or PStringArray to it
2337 a new PStringArray
2339 @return
2340 A new PStringArray with the additional elements(s)
2342 PStringArray operator + (const PStringArray & array);
2343 PStringArray operator + (const PString & str);
2345 /**Create an array of C strings.
2346 If storage is NULL then this returns a single pointer that may be
2347 disposed of using free(). Note that each of the strings are part of the
2348 same memory allocation so only one free() is required.
2350 If storage is not null then that is used to allocate the memory.
2352 char ** ToCharArray(
2353 PCharArray * storage = NULL
2354 ) const;
2355 //@}
2359 /**This is a list collection class of #PString# objects. It has all the
2360 usual functions for a collection, with the object types set to
2361 #PString# pointers.
2363 In addition some addition functions are added that take a const
2364 #PString# reference instead of a pointer as most standard collection
2365 functions do. This is more convenient for when string expressions are used
2366 as parameters to function in the collection.
2368 See the #PAbstractList# and #PList# classes and
2369 #PDECLARE_LIST# macro for more information.
2371 #ifdef DOC_PLUS_PLUS
2372 class PStringList : public PList {
2373 #endif
2374 PDECLARE_LIST(PStringList, PString);
2375 public:
2376 /**@name Construction */
2377 //@{
2378 /**Create a PStringList from the array of C strings.
2380 PStringList(
2381 PINDEX count, ///< Count of strings in array
2382 char const * const * strarr, ///< Array of C strings
2383 BOOL caseless = FALSE ///< New strings are to be PCaselessStrings
2385 /**Create a PStringList of length one from the single string.
2387 PStringList(
2388 const PString & str ///< Single string to convert to a list of one.
2390 /**Create a PStringList from the array of strings.
2392 PStringList(
2393 const PStringArray & array ///< Array of strings to convert to list
2395 /**Create a PStringList from the sorted list of strings.
2397 PStringList(
2398 const PSortedStringList & list ///< List of strings to convert to list.
2400 //@}
2402 /**@name Overrides from class PObject */
2403 //@{
2404 /** Input the contents of the object from the stream. This is
2405 primarily used by the standard #operator>># function.
2407 The default behaviour reads '\n' separated strings until !strm.good().
2409 virtual void ReadFrom(
2410 istream &strm // Stream to read the objects contents from.
2412 //@}
2414 /**@name Operations */
2415 //@{
2416 /** Append a string to the list.
2418 PINDEX AppendString(
2419 const PString & str ///< String to append.
2422 /** Insert a string into the list.
2424 PINDEX InsertString(
2425 const PString & before, ///< String to insert before.
2426 const PString & str ///< String to insert.
2429 /** Get the index of the string with the specified value.
2430 A linear search of list is performed to find the string value.
2432 PINDEX GetStringsIndex(
2433 const PString & str ///< String value to search for.
2434 ) const;
2436 /**Concatenate a PString or PStringArray to the list
2438 @return
2439 The PStringArray with the new items appended
2441 PStringList & operator +=(const PStringList & list);
2442 PStringList & operator +=(const PString & str);
2445 /**Create a new PStringList, and add PString or PStringList to it
2446 a new PStringList
2448 @return
2449 A new PStringList with the additional elements(s)
2451 PStringList operator + (const PStringList & array);
2452 PStringList operator + (const PString & str);
2455 * Create a PStringArray from an STL container
2457 template <typename stlContainer>
2458 static PStringList container(
2459 const stlContainer & vec
2462 PStringList list;
2463 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
2464 list.AppendString(PString(*r));
2465 return list;
2467 //@}
2471 /**This is a sorted list collection class of #PString# objects. It has all
2472 the usual functions for a collection, with the object types set to
2473 #PString# pointers.
2475 In addition some addition functions are added that take a const
2476 #PString# reference instead of a pointer as most standard collection
2477 functions do. This is more convenient for when string expressions are used
2478 as parameters to function in the collection.
2480 See the #PAbstractSortedList# and #PSortedList# classes and
2481 #PDECLARE_SORTEDLIST# macro for more information.
2483 #ifdef DOC_PLUS_PLUS
2484 class PSortedStringList : public PSortedList {
2485 #endif
2486 PDECLARE_SORTED_LIST(PSortedStringList, PString);
2487 public:
2488 /**@name Construction */
2489 //@{
2490 /**Create a PStringArray from the array of C strings.
2492 PSortedStringList(
2493 PINDEX count, ///< Count of strings in array
2494 char const * const * strarr, ///< Array of C strings
2495 BOOL caseless = FALSE ///< New strings are to be PCaselessStrings
2497 /**Create a PSortedStringList of length one from the single string.
2499 PSortedStringList(
2500 const PString & str ///< Single string to convert to a list of one.
2502 /**Create a PSortedStringList from the array of strings.
2504 PSortedStringList(
2505 const PStringArray & array ///< Array of strings to convert to list
2507 /**Create a PSortedStringList from the list of strings.
2509 PSortedStringList(
2510 const PStringList & list ///< List of strings to convert to list.
2512 //@}
2514 /**@name Overrides from class PObject */
2515 //@{
2516 /** Input the contents of the object from the stream. This is
2517 primarily used by the standard #operator>># function.
2519 The default behaviour reads '\n' separated strings until !strm.good().
2521 virtual void ReadFrom(
2522 istream &strm // Stream to read the objects contents from.
2524 //@}
2526 /**@name Operations */
2527 //@{
2528 /** Add a string to the list.
2529 This will place the string in the correct position in the sorted list.
2531 PINDEX AppendString(
2532 const PString & str ///< String to append.
2535 /** Get the index of the string with the specified value.
2536 A binary search of tree is performed to find the string value.
2538 PINDEX GetStringsIndex(
2539 const PString & str ///< String value to search for.
2540 ) const;
2542 /** Get the index of the next string after specified value.
2543 A binary search of tree is performed to find the string greater than
2544 or equal to the specified string value.
2546 PINDEX GetNextStringsIndex(
2547 const PString & str ///< String value to search for.
2548 ) const;
2549 //@}
2551 protected:
2552 PINDEX InternalStringSelect(
2553 const char * str,
2554 PINDEX len,
2555 Element * thisElement
2556 ) const;
2560 /**This is a set collection class of #PString# objects. It has all the
2561 usual functions for a collection, with the object types set to
2562 #PString# pointers.
2564 In addition some addition functions are added that take a const
2565 #PString# reference instead of a pointer as most standard collection
2566 functions do. This is more convenient for when string expressions are used
2567 as parameters to function in the collection.
2569 Unlike the normal sets, this will delete the PStrings removed from it. This
2570 complements the automatic creation of new PString objects when literals or
2571 expressions are used.
2573 See the #PAbstractSet# and #PSet# classes and #PDECLARE_SET#
2574 macro for more information.
2576 #ifdef DOC_PLUS_PLUS
2577 class PStringSet : public PSet {
2578 #endif
2579 PDECLARE_SET(PStringSet, PString, TRUE);
2580 public:
2581 /**@name Construction */
2582 //@{
2583 /**Create a PStringArray from the array of C strings.
2585 PStringSet(
2586 PINDEX count, ///< Count of strings in array
2587 char const * const * strarr, ///< Array of C strings
2588 BOOL caseless = FALSE ///< New strings are to be PCaselessStrings
2590 /**Create a PStringSet containing the single string.
2592 PStringSet(
2593 const PString & str ///< Single string to convert to a list of one.
2595 //@}
2597 /**@name Overrides from class PObject */
2598 //@{
2599 /** Input the contents of the object from the stream. This is
2600 primarily used by the standard #operator>># function.
2602 The default behaviour reads '\n' separated strings until !strm.good().
2604 virtual void ReadFrom(
2605 istream &strm ///< Stream to read the objects contents from.
2607 //@}
2609 /**@name Operations */
2610 //@{
2611 /** Include the spcified string value into the set. */
2612 void Include(
2613 const PString & key ///< String value to add to set.
2615 /** Include the spcified string value into the set. */
2616 PStringSet & operator+=(
2617 const PString & key ///< String value to add to set.
2619 /** Exclude the spcified string value from the set. */
2620 void Exclude(
2621 const PString & key ///< String value to remove from set.
2623 /** Exclude the spcified string value from the set. */
2624 PStringSet & operator-=(
2625 const PString & key ///< String value to remove from set.
2627 //@}
2631 #ifdef PHAS_TEMPLATES
2633 /**This template class maps the PAbstractDictionary to a specific key type and
2634 a #PString# data type. The functions in this class primarily do all the
2635 appropriate casting of types.
2637 Note that if templates are not used the #PDECLARE_STRING_DICTIONARY#
2638 macro will simulate the template instantiation.
2640 template <class K> class PStringDictionary : public PAbstractDictionary
2642 PCLASSINFO(PStringDictionary, PAbstractDictionary);
2644 public:
2645 /**@name Construction */
2646 //@{
2647 /**Create a new, empty, dictionary.
2649 Note that by default, objects placed into the dictionary will be
2650 deleted when removed or when all references to the dictionary are
2651 destroyed.
2653 PStringDictionary()
2654 : PAbstractDictionary() { }
2655 //@}
2657 /**@name Overrides from class PObject */
2658 //@{
2659 /**Make a complete duplicate of the dictionary. Note that all objects in
2660 the array are also cloned, so this will make a complete copy of the
2661 dictionary.
2663 virtual PObject * Clone() const
2664 { return PNEW PStringDictionary(0, this); }
2665 //@}
2667 /**@name New functions for class */
2668 //@{
2669 /**Get the string contained in the dictionary at the #key#
2670 position. The hash table is used to locate the data quickly via the
2671 hash function provided by the key.
2673 The last key/data pair is remembered by the class so that subseqent
2674 access is very fast.
2676 This function asserts if there is no data at the key position.
2678 @return
2679 reference to the object indexed by the key.
2681 const PString & operator[](const K & key) const
2682 { return (const PString &)GetRefAt(key); }
2684 /**Get the string contained in the dictionary at the #key#
2685 position. The hash table is used to locate the data quickly via the
2686 hash function provided by the key.
2688 The last key/data pair is remembered by the class so that subseqent
2689 access is very fast.
2691 This function returns the #dflt# value if there is no data
2692 at the key position.
2694 @return
2695 reference to the object indexed by the key.
2697 PString operator()(const K & key, const char * dflt = "") const
2698 { if (AbstractContains(key)) return (*this)[key]; return dflt; }
2700 /**Determine if the value of the object is contained in the hash table. The
2701 object values are compared, not the pointers. So the objects in the
2702 collection must correctly implement the #PObject::Compare()#
2703 function. The hash table is used to locate the entry.
2705 @return
2706 TRUE if the object value is in the dictionary.
2708 BOOL Contains(
2709 const K & key // Key to look for in the dictionary.
2710 ) const { return AbstractContains(key); }
2712 /**Remove an object at the specified key. The returned pointer is then
2713 removed using the #SetAt()# function to set that key value to
2714 NULL. If the #AllowDeleteObjects# option is set then the
2715 object is also deleted.
2717 @return
2718 pointer to the object being removed, or NULL if the key was not
2719 present in the dictionary. If the dictionary is set to delete objects
2720 upon removal, the value -1 is returned if the key existed prior to removal
2721 rather than returning an illegal pointer
2723 virtual PString * RemoveAt(
2724 const K & key // Key for position in dictionary to get object.
2726 PString * s = GetAt(key); AbstractSetAt(key, NULL);
2727 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s;
2730 /**Get the object at the specified key position. If the key was not in the
2731 collection then NULL is returned.
2733 @return
2734 pointer to object at the specified key.
2736 virtual PString * GetAt(
2737 const K & key // Key for position in dictionary to get object.
2738 ) const { return (PString *)AbstractGetAt(key); }
2740 /**Set the data at the specified ordinal index position in the dictionary.
2742 The ordinal position in the dictionary is determined by the hash values
2743 of the keys and the order of insertion.
2745 @return
2746 TRUE if the new object could be placed into the dictionary.
2748 virtual BOOL SetDataAt(
2749 PINDEX index, // Ordinal index in the dictionary.
2750 const PString & str // New string value to put into the dictionary.
2751 ) { return PAbstractDictionary::SetDataAt(index, PNEW PString(str)); }
2753 /**Add a new object to the collection. If the objects value is already in
2754 the dictionary then the object is overrides the previous value. If the
2755 AllowDeleteObjects option is set then the old object is also deleted.
2757 The object is placed in the an ordinal position dependent on the keys
2758 hash function. Subsequent searches use the has function to speed access
2759 to the data item.
2761 @return
2762 TRUE if the object was successfully added.
2764 virtual BOOL SetAt(
2765 const K & key, // Key for position in dictionary to add object.
2766 const PString & str // New string value to put into the dictionary.
2767 ) { return AbstractSetAt(key, PNEW PString(str)); }
2769 /**Get the key in the dictionary at the ordinal index position.
2771 The ordinal position in the dictionary is determined by the hash values
2772 of the keys and the order of insertion.
2774 The last key/data pair is remembered by the class so that subseqent
2775 access is very fast.
2777 @return
2778 reference to key at the index position.
2780 const K & GetKeyAt(PINDEX index) const
2781 { return (const K &)AbstractGetKeyAt(index); }
2783 /**Get the data in the dictionary at the ordinal index position.
2785 The ordinal position in the dictionary is determined by the hash values
2786 of the keys and the order of insertion.
2788 The last key/data pair is remembered by the class so that subseqent
2789 access is very fast.
2791 @return
2792 reference to data at the index position.
2794 PString & GetDataAt(PINDEX index) const
2795 { return (PString &)AbstractGetDataAt(index); }
2796 //@}
2798 protected:
2799 PStringDictionary(int dummy, const PStringDictionary * c)
2800 : PAbstractDictionary(dummy, c) { }
2804 /**Begin declaration of a dictionary of strings class.
2805 This macro is used to declare a descendent of PAbstractList class,
2806 customised for a particular key type {\bf K} and data object type
2807 #PString#.
2809 If the compilation is using templates then this macro produces a descendent
2810 of the #PStringDictionary# template class. If templates are not being
2811 used then the macro defines a set of inline functions to do all casting of
2812 types. The resultant classes have an identical set of functions in either
2813 case.
2815 See the #PStringDictionary# and #PAbstractDictionary# classes for
2816 more information.
2818 #define PDECLARE_STRING_DICTIONARY(cls, K) \
2819 PDECLARE_CLASS(cls, PStringDictionary<K>) \
2820 protected: \
2821 cls(int dummy, const cls * c) \
2822 : PStringDictionary<K>(dummy, c) { } \
2823 public: \
2824 cls() \
2825 : PStringDictionary<K>() { } \
2826 virtual PObject * Clone() const \
2827 { return PNEW cls(0, this); } \
2830 /**Declare a dictionary of strings class.
2831 This macro is used to declare a descendent of PAbstractDictionary class,
2832 customised for a particular key type {\bf K} and data object type
2833 #PString#. This macro closes the class declaration off so no additional
2834 members can be added.
2836 If the compilation is using templates then this macro produces a typedef
2837 of the #PStringDictionary# template class.
2839 See the #PStringDictionary# class and #PDECLARE_STRING_DICTIONARY#
2840 macro for more information.
2842 #define PSTRING_DICTIONARY(cls, K) typedef PStringDictionary<K> cls
2845 #else // PHAS_TEMPLATES
2848 #define PSTRING_DICTIONARY(cls, K) \
2849 class cls : public PAbstractDictionary { \
2850 PCLASSINFO(cls, PAbstractDictionary) \
2851 protected: \
2852 inline cls(int dummy, const cls * c) \
2853 : PAbstractDictionary(dummy, c) { } \
2854 public: \
2855 inline cls() \
2856 : PAbstractDictionary() { } \
2857 inline PObject * Clone() const \
2858 { return PNEW cls(0, this); } \
2859 inline PString & operator[](const K & key) const \
2860 { return (PString &)GetRefAt(key); } \
2861 inline PString operator()(const K & key, const char * dflt = "") const \
2862 { if (Contains(key)) return (PString &)GetRefAt(key); return dflt; } \
2863 virtual BOOL Contains(const K & key) const \
2864 { return AbstractContains(key); } \
2865 virtual PString * RemoveAt(const K & key) \
2866 { PString * s = GetAt(key); AbstractSetAt(key, NULL); \
2867 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s; } \
2868 virtual PString * GetAt(const K & key) const \
2869 { return (PString *)AbstractGetAt(key); } \
2870 virtual BOOL SetDataAt(PINDEX index, const PString & str) \
2871 { return PAbstractDictionary::SetDataAt(index,PNEW PString(str));} \
2872 virtual BOOL SetAt(const K & key, const PString & str) \
2873 { return AbstractSetAt(key, PNEW PString(str)); } \
2874 inline const K & GetKeyAt(PINDEX index) const \
2875 { return (const K &)AbstractGetKeyAt(index); } \
2876 inline PString & GetDataAt(PINDEX index) const \
2877 { return (PString &)AbstractGetDataAt(index); } \
2880 #define PDECLARE_STRING_DICTIONARY(cls, K) \
2881 PSTRING_DICTIONARY(cls##_PTemplate, K); \
2882 PDECLARE_CLASS(cls, cls##_PTemplate) \
2883 protected: \
2884 cls(int dummy, const cls * c) \
2885 : cls##_PTemplate(dummy, c) { } \
2886 public: \
2887 cls() \
2888 : cls##_PTemplate() { } \
2889 virtual PObject * Clone() const \
2890 { return PNEW cls(0, this); } \
2892 #endif // PHAS_TEMPLATES
2895 /**This is a dictionary collection class of #PString# objects, keyed by an
2896 ordinal value. It has all the usual functions for a collection, with the
2897 object types set to #PString# pointers. The class could be considered
2898 like a sparse array of strings.
2900 In addition some addition functions are added that take a const
2901 #PString# reference instead of a pointer as most standard collection
2902 functions do. This is more convenient for when string expressions are used
2903 as parameters to function in the collection.
2905 See the #PAbstractDictionary# and #PStringDictionary# classes and
2906 #PDECLARE_DICTIONARY# and #PDECLARE_STRING_DICTIONARY# macros for
2907 more information.
2909 #ifdef DOC_PLUS_PLUS
2910 class POrdinalToString : public PStringDictionary {
2911 #endif
2912 PDECLARE_STRING_DICTIONARY(POrdinalToString, POrdinalKey);
2913 public:
2914 /**@name Construction */
2915 //@{
2916 /// Structure for static array initialiser for class.
2917 struct Initialiser {
2918 /// Ordinal key for string.
2919 PINDEX key;
2920 /// String value for ordinal.
2921 const char * value;
2923 /** Initialise the ordinal dictionary of strings from the static array.
2925 POrdinalToString(
2926 PINDEX count, ///< Count of strings in initialiser array
2927 const Initialiser * init ///< Array of Initialiser structures
2929 //@}
2931 /**@name Overrides from class PObject */
2932 //@{
2933 /** Input the contents of the object from the stream. This is
2934 primarily used by the standard #operator>># function.
2936 The default behaviour reads '\n' separated strings until !strm.good().
2938 virtual void ReadFrom(
2939 istream &strm // Stream to read the objects contents from.
2941 //@}
2944 /**This is a dictionary collection class of ordinals keyed by
2945 #PString# objects. It has all the usual functions for a collection,
2946 with the object types set to #POrdinalKey# pointers.
2948 In addition some addition functions are added that take a const
2949 #POrdinalKey# reference or a simple #PINDEX# instead of a pointer
2950 as most standard collection functions do. This is more convenient for when
2951 integer expressions are used as parameters to function in the collection.
2953 See the #PAbstractDicionary# and #POrdinalDictionary# classes and
2954 #PDECLARE_ORDINAL_DICTIONARY# macro for more information.
2956 #ifdef DOC_PLUS_PLUS
2957 class PStringToOrdinal : public POrdinalDictionary {
2958 #endif
2959 PDECLARE_ORDINAL_DICTIONARY(PStringToOrdinal, PString);
2960 public:
2961 /**@name Construction */
2962 //@{
2963 /// Structure for static array initialiser for class.
2964 struct Initialiser {
2965 /// String key for ordinal.
2966 const char * key;
2967 /// Ordinal value for string.
2968 PINDEX value;
2970 /** Initialise the string dictionary of ordinals from the static array.
2972 PStringToOrdinal(
2973 PINDEX count, ///< Count of strings in initialiser array
2974 const Initialiser * init, ///< Array of Initialiser structures
2975 BOOL caseless = FALSE ///< New keys are to be PCaselessStrings
2977 //@}
2979 /**@name Overrides from class PObject */
2980 //@{
2981 /** Input the contents of the object from the stream. This is
2982 primarily used by the standard #operator>># function.
2984 The default behaviour reads '\n' separated strings until !strm.good().
2986 virtual void ReadFrom(
2987 istream &strm // Stream to read the objects contents from.
2989 //@}
2993 /**This is a dictionary collection class of #PString# objects, keyed by
2994 another string. It has all the usual functions for a collection, with the
2995 object types set to #PString# pointers.
2997 In addition some addition functions are added that take a const
2998 #PString# reference instead of a pointer as most standard collection
2999 functions do. This is more convenient for when string expressions are used
3000 as parameters to function in the collection.
3002 See the #PAbstractDictionary# and #PStringDictionary# classes and
3003 #PDECLARE_DICTIONARY# and #PDECLARE_STRING_DICTIONARY# macros for
3004 more information.
3006 #ifdef DOC_PLUS_PLUS
3007 class PStringToString : public PStringDictionary {
3008 #endif
3009 PDECLARE_STRING_DICTIONARY(PStringToString, PString);
3010 public:
3011 /**@name Construction */
3012 //@{
3013 /// Structure for static array initialiser for class.
3014 struct Initialiser {
3015 /// String key for string.
3016 const char * key;
3017 /// String value for string.
3018 const char * value;
3020 /** Initialise the string dictionary of strings from the static array.
3022 PStringToString(
3023 PINDEX count, ///< Count of strings in initialiser array
3024 const Initialiser * init, ///< Array of Initialiser structures
3025 BOOL caselessKeys = FALSE, ///< New keys are to be PCaselessStrings
3026 BOOL caselessValues = FALSE ///< New values are to be PCaselessStrings
3028 //@}
3030 /**@name Overrides from class PObject */
3031 //@{
3032 /** Input the contents of the object from the stream. This is
3033 primarily used by the standard #operator>># function.
3035 The default behaviour reads '\n' separated strings until !strm.good().
3037 virtual void ReadFrom(
3038 istream &strm // Stream to read the objects contents from.
3040 //@}
3044 /**A class representing a regular expression that may be used for locating
3045 patterns in strings. The regular expression string is "compiled" into a
3046 form that is more efficient during the matching. This compiled form
3047 exists for the lifetime of the PRegularExpression instance.
3049 class PRegularExpression : public PObject
3051 PCLASSINFO(PRegularExpression, PObject);
3053 public:
3054 /**@name Constructors & destructors */
3055 //@{
3056 /// Flags for compiler options.
3057 enum {
3058 /// Use extended regular expressions
3059 Extended = 1,
3060 /// Ignore case in search.
3061 IgnoreCase = 2,
3062 /**If this bit is set, then anchors do not match at newline
3063 characters in the string. If not set, then anchors do match
3064 at newlines.
3066 AnchorNewLine = 4
3068 /// Flags for execution options.
3069 enum {
3070 /**If this bit is set, then the beginning-of-line operator doesn't match
3071 the beginning of the string (presumably because it's not the
3072 beginning of a line).
3073 If not set, then the beginning-of-line operator does match the
3074 beginning of the string.
3076 NotBeginningOfLine = 1,
3077 /**Like #NotBeginningOfLine#, except for the end-of-line. */
3078 NotEndofLine = 2
3081 /// Create a new, empty, regular expression
3082 PRegularExpression();
3084 /** Create and compile a new regular expression pattern.
3086 PRegularExpression(
3087 const PString & pattern, ///< Pattern to compile
3088 int flags = IgnoreCase ///< Pattern match options
3091 /** Create and compile a new regular expression pattern.
3093 PRegularExpression(
3094 const char * cpattern, ///< Pattern to compile
3095 int flags = IgnoreCase ///< Pattern match options
3099 * Copy a regular expression
3101 PRegularExpression(
3102 const PRegularExpression &
3106 * Assign a regular expression
3108 PRegularExpression & operator =(
3109 const PRegularExpression &
3112 /// Release storage for the compiled regular expression.
3113 ~PRegularExpression();
3114 //@}
3116 /**@name Status functions */
3117 //@{
3118 /// Error codes.
3119 enum ErrorCodes {
3120 /// Success.
3121 NoError = 0,
3122 /// Didn't find a match (for regexec).
3123 NoMatch,
3125 // POSIX regcomp return error codes. (In the order listed in the standard.)
3126 /// Invalid pattern.
3127 BadPattern,
3128 /// Not implemented.
3129 CollateError,
3130 /// Invalid character class name.
3131 BadClassType,
3132 /// Trailing backslash.
3133 BadEscape,
3134 /// Invalid back reference.
3135 BadSubReg,
3136 /// Unmatched left bracket.
3137 UnmatchedBracket,
3138 /// Parenthesis imbalance.
3139 UnmatchedParen,
3140 /// Unmatched #\{\}#.
3141 UnmatchedBrace,
3142 /// Invalid contents of #\{\}#.
3143 BadBR,
3144 /// Invalid range end.
3145 RangeError,
3146 /// Ran out of memory.
3147 OutOfMemory,
3148 /// No preceding re for repetition op.
3149 BadRepitition,
3151 /* Error codes we've added. */
3152 /// Premature end.
3153 PrematureEnd,
3154 /// Compiled pattern bigger than 2^16 bytes.
3155 TooBig,
3156 /// Unmatched ) or \); not returned from regcomp.
3157 UnmatchedRParen,
3158 /// Miscellaneous error
3159 NotCompiled
3162 /**Get the error code for the last Compile() or Execute() operation.
3164 @return
3165 Error code.
3167 ErrorCodes GetErrorCode() const;
3169 /**Get the text description for the error of the last Compile() or
3170 Execute() operation.
3172 @return
3173 Error text string.
3175 PString GetErrorText() const;
3176 //@}
3178 /**@name Compile & Execute functions */
3179 //@{
3180 /** Compiler pattern. */
3181 BOOL Compile(
3182 const PString & pattern, ///< Pattern to compile
3183 int flags = IgnoreCase ///< Pattern match options
3185 /**Compiler pattern.
3186 The pattern is compiled into an internal format to speed subsequent
3187 execution of the pattern match algorithm.
3189 @return
3190 TRUE if successfully compiled.
3192 BOOL Compile(
3193 const char * cpattern, ///< Pattern to compile
3194 int flags = IgnoreCase ///< Pattern match options
3198 /** Execute regular expression */
3199 BOOL Execute(
3200 const PString & str, ///< Source string to search
3201 PINDEX & start, ///< First match locations
3202 int flags = 0 ///< Pattern match options
3203 ) const;
3204 /** Execute regular expression */
3205 BOOL Execute(
3206 const PString & str, ///< Source string to search
3207 PINDEX & start, ///< First match locations
3208 PINDEX & len, ///< Length of match
3209 int flags = 0 ///< Pattern match options
3210 ) const;
3211 /** Execute regular expression */
3212 BOOL Execute(
3213 const char * cstr, ///< Source string to search
3214 PINDEX & start, ///< First match locations
3215 int flags = 0 ///< Pattern match options
3216 ) const;
3217 /** Execute regular expression */
3218 BOOL Execute(
3219 const char * cstr, ///< Source string to search
3220 PINDEX & start, ///< First match locations
3221 PINDEX & len, ///< Length of match
3222 int flags = 0 ///< Pattern match options
3223 ) const;
3224 /** Execute regular expression */
3225 BOOL Execute(
3226 const PString & str, ///< Source string to search
3227 PIntArray & starts, ///< List of match locations
3228 int flags = 0 ///< Pattern match options
3229 ) const;
3230 /** Execute regular expression */
3231 BOOL Execute(
3232 const PString & str, ///< Source string to search
3233 PIntArray & starts, ///< List of match locations
3234 PIntArray & ends, ///< List of match ends
3235 int flags = 0 ///< Pattern match options
3236 ) const;
3237 /** Execute regular expression */
3238 BOOL Execute(
3239 const char * cstr, ///< Source string to search
3240 PIntArray & starts, ///< List of match locations
3241 int flags = 0 ///< Pattern match options
3242 ) const;
3243 /**Execute regular expression.
3244 Execute the pattern match algorithm using the previously compiled
3245 pattern.
3247 The #starts# array is filled with as many matches as will fit
3248 into the array. If the the array size is zero then it is set to at least
3249 one for the first match found.
3251 The #ends# array is set to teh ending position of each
3252 substring whose start is returned in the #starts# array. This
3253 will always be set to the same size as that array.
3255 @return
3256 TRUE if successfully compiled.
3258 BOOL Execute(
3259 const char * cstr, ///< Source string to search
3260 PIntArray & starts, ///< List of match locations
3261 PIntArray & ends, ///< List of match ends
3262 int flags = 0 ///< Pattern match options
3263 ) const;
3264 //@}
3266 /**@name Miscellaneous functions */
3267 //@{
3268 /**Escape all characters in the #str# parameter that have a
3269 special meaning within a regular expression.
3271 @return
3272 String with additional escape ('\') characters.
3274 static PString EscapeString(
3275 const PString & str ///< String to add esacpes to.
3277 //@}
3279 protected:
3280 PString patternSaved;
3281 int flagsSaved;
3283 void * expression;
3284 int lastError;
3287 PString psprintf(const char * cfmt, ...);
3289 #endif // #ifndef __PSTRING__
3290 // End Of File ///////////////////////////////////////////////////////////////