PTLib  Version 2.10.10
pstring.h
Go to the documentation of this file.
1 /*
2  * pstring.h
3  *
4  * Character string class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
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/
14  *
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.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 27359 $
30  * $Author: rjongbloed $
31  * $Date: 2012-03-28 21:17:54 -0500 (Wed, 28 Mar 2012) $
32  */
33 
34 #ifndef PTLIB_STRING_H
35 #define PTLIB_STRING_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #include <string>
42 #include <vector>
43 #include <ptlib/array.h>
44 
46 // PString class
47 
48 class PStringArray;
49 class PRegularExpression;
50 class PString;
51 
56  const char * fmt,
57  ...
58 );
59 
64  const char * fmt,
65  va_list arg
66 );
67 
68 #if (defined(_WIN32) || defined(_WIN32_WCE)) && (!defined(_NATIVE_WCHAR_T_DEFINED)) && (!defined(__MINGW32__))
69 PBASEARRAY(PWCharArray, unsigned short);
70 #else
71 PBASEARRAY(PWCharArray, wchar_t);
72 #endif
73 
108 class PString : public PCharArray
109 {
110  PCLASSINFO(PString, PCharArray);
111 
112 // using namespace std;
113 
114  public:
115  typedef const char * Initialiser;
116 
122  PINLINE PString();
123 
128  const PString & str
129  );
130 
134  const std::string & str
135  );
136 
145  PString(
146  const char * cstr
147  );
148 
153  PString(
154  const wchar_t * ustr
155  );
156 
170  PString(
171  const char * cstr,
172  PINDEX len
173  );
174 
185  PString(
186  const wchar_t * ustr,
187  PINDEX len
188  );
189 
200  PString(
201  const PWCharArray & ustr
202  );
203 
212  PString(
213  char ch
214  );
215 
220  PString(
221  short n
222  );
223 
228  PString(
229  unsigned short n
230  );
231 
236  PString(
237  int n
238  );
239 
244  PString(
245  unsigned int n
246  );
247 
252  PString(
253  long n
254  );
255 
260  PString(
261  unsigned long n
262  );
263 
268  PString(
269  PInt64 n
270  );
271 
276  PString(
277  PUInt64 n
278  );
279 
280 
282  Pascal, // Data is a length byte followed by characters.
283  Basic, // Data is two length bytes followed by characters.
284  Literal, // Data is C language style string with \\ escape codes.
285  Signed, // Convert a signed integer to a string.
286  Unsigned, // Convert an unsigned integer to a string.
287  Decimal, // Convert a real number to a string in decimal format.
288  Exponent, // Convert a real number to a string in exponent format.
289  Printf, // Formatted output, sprintf() style function.
291  };
292  /* Type of conversion to make in the conversion constructors.
293  */
294 
295  /* Contruct a new string converting from the spcified data source into
296  a string array.
297  */
298  PString(
299  ConversionType type,
300  const char * str,
301  ...
302  );
303  PString(
304  ConversionType type,
305  long value,
306  unsigned base = 10
307  );
308  PString(
309  ConversionType type,
310  double value,
311  unsigned places
312  );
313 
321  PString & operator=(
322  const PString & str
323  );
324 
333  const std::string & str
334  ) { return operator=(str.c_str()); }
335 
345  PString & operator=(
346  const char * cstr
347  );
348 
357  PString & operator=(
358  char ch
359  );
360 
365  PString & operator=(
366  short n
367  );
368 
373  PString & operator=(
374  unsigned short n
375  );
376 
381  PString & operator=(
382  int n
383  );
384 
389  PString & operator=(
390  unsigned int n
391  );
392 
397  PString & operator=(
398  long n
399  );
400 
405  PString & operator=(
406  unsigned long n
407  );
408 
413  PString & operator=(
414  PInt64 n
415  );
416 
421  PString & operator=(
422  PUInt64 n
423  );
424 
427  virtual PString & MakeEmpty();
428 
431  static PString Empty();
433 
440  virtual PObject * Clone() const;
441 
451  virtual Comparison Compare(
452  const PObject & obj
453  ) const;
454 
457  virtual void PrintOn(
458  ostream & strm
459  ) const;
460 
466  virtual void ReadFrom(
467  istream & strm
468  );
469 
483  virtual PINDEX HashFunction() const;
485 
500  virtual PBoolean SetSize(
501  PINDEX newSize
502  );
503 
512  virtual PBoolean IsEmpty() const;
513 
522  virtual PBoolean MakeUnique();
524 
525 
539 
548  PINLINE PINDEX GetLength() const;
549 
556  bool operator!() const;
558 
568  const PString & str
569  ) const;
570 
583  const char * cstr
584  ) const;
585 
598  char ch
599  ) const;
600 
612  friend PString operator+(
613  const char * cstr,
614  const PString & str
615  );
616 
628  friend PString operator+(
629  char ch,
630  const PString & str
631  );
632 
639  const PString & str
640  );
641 
652  const char * cstr
653  );
654 
665  char ch
666  );
667 
668 
676  const PString & str
677  ) const;
678 
696  const char * cstr
697  ) const;
698 
716  char ch
717  ) const;
718 
735  friend PString operator&(
736  const char * cstr,
737  const PString & str
738  );
739 
756  friend PString operator&(
757  char ch,
758  const PString & str
759  );
760 
767  const PString & str
768  );
769 
785  const char * cstr
786  );
787 
788 
804  char ch
805  );
807 
808 
816  bool operator*=(
817  const PString & str
818  ) const;
819 
827  bool operator==(
828  const PObject & str
829  ) const;
830 
838  bool operator!=(
839  const PObject & str
840  ) const;
841 
849  bool operator<(
850  const PObject & str
851  ) const;
852 
860  bool operator>(
861  const PObject & str
862  ) const;
863 
871  bool operator<=(
872  const PObject & str
873  ) const;
874 
882  bool operator>=(
883  const PObject & str
884  ) const;
885 
886 
897  bool operator*=(
898  const char * cstr
899  ) const;
900 
911  bool operator==(
912  const char * cstr
913  ) const;
914 
925  bool operator!=(
926  const char * cstr
927  ) const;
928 
939  bool operator<(
940  const char * cstr
941  ) const;
942 
953  bool operator>(
954  const char * cstr
955  ) const;
956 
967  bool operator<=(
968  const char * cstr
969  ) const;
970 
981  bool operator>=(
982  const char * cstr
983  ) const;
984 
997  const PString & str,
998  PINDEX count = P_MAX_INDEX,
999  PINDEX offset = 0
1000  ) const;
1001 
1014  const char * cstr,
1015  PINDEX count = P_MAX_INDEX,
1016  PINDEX offset = 0
1017  ) const;
1019 
1020 
1024  PINDEX Find(
1025  char ch,
1026  PINDEX offset = 0
1027  ) const;
1028 
1030  PINDEX Find(
1031  const PString & str,
1032  PINDEX offset = 0
1033  ) const;
1034 
1035  /* Locate the position within the string of the character or substring. The
1036  search will begin at the character offset provided.
1037 
1038  If <code>offset</code> is beyond the length of the string, then the
1039  function will always return P_MAX_INDEX.
1040 
1041  The matching will be for identical character or string. If a search
1042  ignoring case is required then the string should be converted to a
1043  PCaselessString before the search is made.
1044 
1045  @return
1046  position of character or substring in the string, or P_MAX_INDEX if the
1047  character or substring is not in the string.
1048  */
1049  PINDEX Find(
1050  const char * cstr,
1051  PINDEX offset = 0
1052  ) const;
1053 
1055  PINDEX FindLast(
1056  char ch,
1057  PINDEX offset = P_MAX_INDEX
1058  ) const;
1059 
1061  PINDEX FindLast(
1062  const PString & str,
1063  PINDEX offset = P_MAX_INDEX
1064  ) const;
1065 
1083  PINDEX FindLast(
1084  const char * cstr,
1085  PINDEX offset = P_MAX_INDEX
1086  ) const;
1087 
1089  PINDEX FindOneOf(
1090  const PString & set,
1091  PINDEX offset = 0
1092  ) const;
1093 
1108  PINDEX FindOneOf(
1109  const char * cset,
1110  PINDEX offset = 0
1111  ) const;
1112 
1114  PINDEX FindSpan(
1115  const PString & set,
1116  PINDEX offset = 0
1117  ) const;
1118 
1134  PINDEX FindSpan(
1135  const char * cset,
1136  PINDEX offset = 0
1137  ) const;
1138 
1149  PINDEX FindRegEx(
1150  const PRegularExpression & regex,
1151  PINDEX offset = 0
1152  ) const;
1153 
1165  const PRegularExpression & regex,
1166  PINDEX & pos,
1167  PINDEX & len,
1168  PINDEX offset = 0,
1169  PINDEX maxPos = P_MAX_INDEX
1170  ) const;
1171 
1172 
1176  const PRegularExpression & regex
1177  ) const;
1178 
1189  void Replace(
1190  const PString & target,
1191  const PString & subs,
1192  PBoolean all = false,
1193  PINDEX offset = 0
1194  );
1195 
1203  void Splice(
1204  const PString & str,
1205  PINDEX pos,
1206  PINDEX len = 0
1207  );
1208 
1216  void Splice(
1217  const char * cstr,
1218  PINDEX pos,
1219  PINDEX len = 0
1220  );
1221 
1228  void Delete(
1229  PINDEX start,
1230  PINDEX len
1231  );
1233 
1234 
1255  PINDEX start,
1256  PINDEX end
1257  ) const;
1258 
1273  PString Left(
1274  PINDEX len
1275  ) const;
1276 
1291  PString Right(
1292  PINDEX len
1293  ) const;
1294 
1311  PString Mid(
1312  PINDEX start,
1313  PINDEX len = P_MAX_INDEX
1314  ) const;
1315 
1316 
1324  PString LeftTrim() const;
1325 
1333  PString RightTrim() const;
1334 
1343  PString Trim() const;
1344 
1345 
1354  PString ToLower() const;
1355 
1364  PString ToUpper() const;
1365 
1366 
1369  const PString & separators,
1371  PBoolean onePerSeparator = true
1373  ) const;
1399  const char * cseparators,
1401  PBoolean onePerSeparator = true
1403  ) const;
1404 
1418  PStringArray Lines() const;
1420 
1437  PString & sprintf(
1438  const char * cfmt,
1439  ...
1440  );
1441 
1456  friend PString psprintf(
1457  const char * cfmt,
1458  ...
1459  );
1460 
1462  PString & vsprintf(
1463  const PString & fmt,
1464  va_list args
1465  );
1480  PString & vsprintf(
1481  const char * cfmt,
1482  va_list args
1483  );
1484 
1486  friend PString pvsprintf(
1487  const char * cfmt,
1488  va_list args
1489  );
1504  friend PString pvsprintf(
1505  const PString & fmt,
1506  va_list args
1507  );
1508 
1509 
1522  long AsInteger(
1523  unsigned base = 10
1524  ) const;
1537  DWORD AsUnsigned(
1538  unsigned base = 10
1539  ) const;
1553  PInt64 AsInt64(
1554  unsigned base = 10
1555  ) const;
1569  PUInt64 AsUnsigned64(
1570  unsigned base = 10
1571  ) const;
1572 
1583  double AsReal() const;
1584 
1588  PWCharArray AsUCS2() const;
1589 
1600  PBYTEArray ToPascal() const;
1601 
1610  PString ToLiteral() const;
1611 
1619  operator const unsigned char *() const;
1620 
1623  operator std::string () const
1624  { return std::string(theArray); }
1626 
1627 
1628  protected:
1629  void InternalFromUCS2(
1630  const wchar_t * ptr,
1631  PINDEX len
1632  );
1633  virtual Comparison InternalCompare(
1634  PINDEX offset, // Offset into string to compare.
1635  char c // Character to compare against.
1636  ) const;
1637  virtual Comparison InternalCompare(
1638  PINDEX offset, // Offset into string to compare.
1639  PINDEX length, // Number of characters to compare.
1640  const char * cstr // C string to compare against.
1641  ) const;
1642 
1643  /* Internal function to compare the current string value against the
1644  specified C string.
1645 
1646  @return
1647  relative rank of the two strings.
1648  */
1649  PString(int dummy, const PString * str);
1650 
1652 };
1653 
1654 
1655 inline ostream & operator<<(ostream & stream, const PString & string)
1656 {
1657  string.PrintOn(stream);
1658  return stream;
1659 }
1660 
1661 
1662 inline wostream & operator<<(wostream & stream, const PString & string)
1663 {
1664  return stream << (const char *)string;
1665 }
1666 
1667 
1668 #ifdef _WIN32
1669  class PWideString : public PWCharArray {
1670  PCLASSINFO(PWideString, PWCharArray);
1671 
1672  public:
1673  typedef const wchar_t * Initialiser;
1674 
1675  PWideString() { }
1676  PWideString(const PWCharArray & arr) : PWCharArray(arr) { }
1677  PWideString(const PString & str) : PWCharArray(str.AsUCS2()) { }
1678  PWideString(const char * str) : PWCharArray(PString(str).AsUCS2()) { }
1679  PWideString & operator=(const PWideString & str) { PWCharArray::operator=(str); return *this; }
1680  PWideString & operator=(const PString & str) { PWCharArray::operator=(str.AsUCS2()); return *this; }
1681  PWideString & operator=(const std::string & str) { PWCharArray::operator=(PString(str.c_str()).AsUCS2()); return *this; }
1682  PWideString & operator=(const char * str) { PWCharArray::operator=(PString(str).AsUCS2()); return *this; }
1683  friend inline ostream & operator<<(ostream & stream, const PWideString & string) { return stream << PString(string); }
1684 
1685  protected:
1686  PWideString(PContainerReference & reference) : PWCharArray(reference) { }
1687  };
1688 
1689  #ifdef UNICODE
1690  typedef PWideString PVarString;
1691  #else
1692  typedef PString PVarString;
1693  #endif
1694 #endif
1695 
1696 
1698 
1708 class PCaselessString : public PString
1709 {
1710  PCLASSINFO(PCaselessString, PString);
1711 
1712  public:
1715  PCaselessString();
1716 
1721  const char * cstr
1722  );
1723 
1729  const PString & str
1730  );
1731 
1732 
1736  const std::string & str
1737  ) : PString(str)
1738  { }
1739 
1748  const PString & str
1749  );
1750 
1759  const std::string & str
1760  ) { return operator=(str.c_str()); }
1761 
1772  const char * cstr
1773  );
1774 
1784  char ch
1785  );
1786 
1787 
1788  // Overrides from class PObject
1793  virtual PObject * Clone() const;
1794 
1795  protected:
1796  // Overrides from class PString
1797  virtual Comparison InternalCompare(
1798  PINDEX offset, // Offset into string to compare.
1799  char c // Character to compare against.
1800  ) const;
1801  virtual Comparison InternalCompare(
1802  PINDEX offset, // Offset into string to compare.
1803  PINDEX length, // Number of characters to compare.
1804  const char * cstr // C string to compare against.
1805  ) const;
1806  /* Internal function to compare the current string value against the
1807  specified C string.
1808 
1809  @return
1810  relative rank of the two strings or characters.
1811  */
1812 
1813  PCaselessString(int dummy, const PCaselessString * str);
1815 };
1816 
1817 
1819 
1833 template <class ParentString>
1834 class PConstantString : public ParentString
1835 {
1836  private:
1837  PContainerReference m_staticReference;
1838  public:
1839  PConstantString(typename ParentString::Initialiser init)
1840  : ParentString(m_staticReference)
1841  , m_staticReference((PINDEX)strlen(init)+1, true)
1842  {
1843  this->theArray = (char *)init;
1844  }
1845  ~PConstantString() { this->Destruct(); }
1846 
1847  virtual PBoolean SetSize(PINDEX) { return false; }
1849  virtual void DestroyReference() { }
1850 
1851  private:
1853  : ParentString(m_staticReference)
1854  , m_staticReference(0, true)
1855  { }
1856  void operator=(const PConstantString &) { }
1857 };
1858 
1859 
1862 
1865 
1866 
1867 
1869 
1870 class PStringStream;
1871 
1878 class PStringStream : public PString, public iostream
1879 {
1880  PCLASSINFO(PStringStream, PString);
1881 
1882  public:
1888  PStringStream();
1889 
1894  PStringStream(
1895  PINDEX fixedBufferSize
1896  );
1897 
1904  PStringStream(
1905  const PString & str
1906  );
1907 
1912  PStringStream(
1913  const char * cstr
1914  );
1915 
1918  virtual PString & MakeEmpty();
1919 
1932  const PStringStream & strm
1933  );
1934 
1947  const PString & str
1948  );
1949 
1966  const char * cstr
1967  );
1968 
1978  char ch
1979  );
1980 
1981 
1983  virtual ~PStringStream();
1984 
1985 
1986  protected:
1987  virtual void AssignContents(const PContainer & cont);
1988 
1989  private:
1990  PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
1991 
1992  class Buffer : public streambuf {
1993  public:
1994  Buffer(PStringStream & str, PINDEX size);
1995  Buffer(const Buffer & sbuf);
1996  Buffer & operator=(const Buffer & sbuf);
1997  virtual int_type overflow(int_type = EOF);
1998  virtual int_type underflow();
1999  virtual int sync();
2000  virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
2001  virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
2002  PStringStream & string;
2003  PBoolean fixedBufferSize;
2004  };
2005 };
2006 
2007 
2008 class PStringList;
2009 class PSortedStringList;
2010 
2023 #ifdef DOC_PLUS_PLUS
2024 class PStringArray : public PArray {
2025 #endif
2026  PDECLARE_ARRAY(PStringArray, PString);
2027  public:
2034  PStringArray(
2035  PINDEX count,
2036  char const * const * strarr,
2037  PBoolean caseless = false
2038  );
2041  PStringArray(
2042  const PString & str
2043  );
2046  PStringArray(
2047  const PStringList & list
2048  );
2051  PStringArray(
2052  const PSortedStringList & list
2053  );
2054 
2059  const std::vector<PString> & vec
2060  )
2061  {
2062  for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
2063  AppendString(*r);
2064  }
2065 
2070  const std::vector<std::string> & vec
2071  )
2072  {
2073  for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
2074  AppendString(PString(*r));
2075  }
2076 
2080  template <typename stlContainer>
2082  const stlContainer & vec
2083  )
2084  {
2085  PStringArray list;
2086  for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
2087  list.AppendString(PString(*r));
2088  return list;
2089  }
2090 
2092 
2101  virtual void ReadFrom(
2102  istream &strm // Stream to read the objects contents from.
2103  );
2105 
2114  PINDEX GetStringsIndex(
2115  const PString & str
2116  ) const;
2117 
2119  PINDEX index
2120  ) const;
2121 
2129  PString & operator[](
2130  PINDEX index
2131  );
2132 
2135  PINDEX AppendString(
2136  const PString & str
2137  );
2138 
2144  PStringArray & operator +=(const PStringArray & array);
2145  PStringArray & operator +=(const PString & str);
2146 
2147 
2154  PStringArray operator + (const PStringArray & array);
2155  PStringArray operator + (const PString & str);
2156 
2164  char ** ToCharArray(
2165  PCharArray * storage = NULL
2166  ) const;
2168 };
2169 
2170 
2183 #ifdef DOC_PLUS_PLUS
2184 class PStringList : public PList {
2185 #endif
2186 PDECLARE_LIST(PStringList, PString);
2187  public:
2192  PStringList(
2193  PINDEX count,
2194  char const * const * strarr,
2195  PBoolean caseless = false
2196  );
2199  PStringList(
2200  const PString & str
2201  );
2204  PStringList(
2205  const PStringArray & array
2206  );
2209  PStringList(
2210  const PSortedStringList & list
2211  );
2213 
2222  virtual void ReadFrom(
2223  istream &strm // Stream to read the objects contents from.
2224  );
2226 
2231  PINDEX AppendString(
2232  const PString & str
2233  );
2234 
2237  PINDEX InsertString(
2238  const PString & before,
2239  const PString & str
2240  );
2241 
2245  PINDEX GetStringsIndex(
2246  const PString & str
2247  ) const;
2248 
2254  PStringList & operator +=(const PStringList & list);
2255  PStringList & operator +=(const PString & str);
2256 
2257 
2264  PStringList operator + (const PStringList & array);
2265  PStringList operator + (const PString & str);
2266 
2270  template <typename stlContainer>
2272  const stlContainer & vec
2273  )
2274  {
2275  PStringList list;
2276  for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
2277  list.AppendString(PString(*r));
2278  return list;
2279  }
2281 };
2282 
2283 
2295 #ifdef DOC_PLUS_PLUS
2297 #endif
2298 PDECLARE_SORTED_LIST(PSortedStringList, PString);
2299  public:
2305  PINDEX count,
2306  char const * const * strarr,
2307  PBoolean caseless = false
2308  );
2312  const PString & str
2313  );
2317  const PStringArray & array
2318  );
2322  const PStringList & list
2323  );
2325 
2334  virtual void ReadFrom(
2335  istream &strm // Stream to read the objects contents from.
2336  );
2338 
2344  PINDEX AppendString(
2345  const PString & str
2346  );
2347 
2351  PINDEX GetStringsIndex(
2352  const PString & str
2353  ) const;
2354 
2359  PINDEX GetNextStringsIndex(
2360  const PString & str
2361  ) const;
2363 
2364  protected:
2365  PINDEX InternalStringSelect(
2366  const char * str,
2367  PINDEX len,
2368  Element * thisElement,
2369  Element * & lastElement
2370  ) const;
2371 };
2372 
2373 
2390 #ifdef DOC_PLUS_PLUS
2391 class PStringSet : public PSet {
2392 #endif
2393 PDECLARE_SET(PStringSet, PString, true);
2394  public:
2399  PStringSet(
2400  PINDEX count,
2401  char const * const * strarr,
2402  PBoolean caseless = false
2403  );
2406  PStringSet(
2407  const PString & str
2408  );
2411  PStringSet(
2412  const PStringArray & strArray
2413  );
2416  PStringSet(
2417  const PStringList & strList
2418  );
2420 
2429  virtual void ReadFrom(
2430  istream &strm
2431  );
2433 
2437  void Include(
2438  const PString & key
2439  );
2442  const PString & key
2443  );
2445  void Exclude(
2446  const PString & key
2447  );
2450  const PString & key
2451  );
2453 };
2454 
2455 
2463 template <class K> class PStringDictionary : public PAbstractDictionary
2464 {
2466 
2467  public:
2477  : PAbstractDictionary() { }
2479 
2486  virtual PObject * Clone() const
2487  { return PNEW PStringDictionary(0, this); }
2489 
2504  const PString & operator[](const K & key) const
2505  { return (const PString &)GetRefAt(key); }
2506 
2520  PString operator()(const K & key, const char * dflt = NULL) const
2521  {
2522  PString * str = this->GetAt(key);
2523  return str != NULL ? *str : PString(dflt);
2524  }
2525 
2535  const K & key // Key to look for in the dictionary.
2536  ) const { return AbstractContains(key); }
2537 
2549  virtual PString * RemoveAt(
2550  const K & key // Key for position in dictionary to get object.
2551  ) {
2552  PString * s = GetAt(key); AbstractSetAt(key, NULL);
2553  return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s;
2554  }
2555 
2562  virtual PString * GetAt(
2563  const K & key // Key for position in dictionary to get object.
2564  ) const { return (PString *)AbstractGetAt(key); }
2565 
2575  PINDEX index, // Ordinal index in the dictionary.
2576  const PString & str // New string value to put into the dictionary.
2577  ) { return PAbstractDictionary::SetDataAt(index, PNEW PString(str)); }
2578 
2590  virtual PBoolean SetAt(
2591  const K & key, // Key for position in dictionary to add object.
2592  const PString & str // New string value to put into the dictionary.
2593  ) { return AbstractSetAt(key, PNEW PString(str)); }
2594 
2606  const K & GetKeyAt(PINDEX index) const
2607  { return (const K &)AbstractGetKeyAt(index); }
2608 
2620  PString & GetDataAt(PINDEX index) const
2621  { return (PString &)AbstractGetDataAt(index); }
2623 
2624  protected:
2625  PStringDictionary(int dummy, const PStringDictionary * c)
2626  : PAbstractDictionary(dummy, c) { }
2627 };
2628 
2629 
2644 #define PDECLARE_STRING_DICTIONARY(cls, K) \
2645  PDECLARE_CLASS(cls, PStringDictionary<K>) \
2646  protected: \
2647  cls(int dummy, const cls * c) \
2648  : PStringDictionary<K>(dummy, c) { } \
2649  public: \
2650  cls() \
2651  : PStringDictionary<K>() { } \
2652  virtual PObject * Clone() const \
2653  { return PNEW cls(0, this); } \
2654 
2655 
2668 #define PSTRING_DICTIONARY(cls, K) typedef PStringDictionary<K> cls
2669 
2670 
2685 #ifdef DOC_PLUS_PLUS
2687 #endif
2688 PDECLARE_STRING_DICTIONARY(POrdinalToString, POrdinalKey);
2689  public:
2692  struct Initialiser {
2695  PINDEX key;
2697  const char * value;
2698  };
2702  PINDEX count,
2703  const Initialiser * init
2704  );
2706 
2715  virtual void ReadFrom(
2716  istream &strm // Stream to read the objects contents from.
2717  );
2719 };
2720 
2732 #ifdef DOC_PLUS_PLUS
2734 #endif
2735 PDECLARE_ORDINAL_DICTIONARY(PStringToOrdinal, PString);
2736  public:
2739  struct Initialiser {
2742  const char * key;
2744  PINDEX value;
2745  };
2749  PINDEX count,
2750  const Initialiser * init,
2751  PBoolean caseless = false
2752  );
2754 
2763  virtual void ReadFrom(
2764  istream &strm // Stream to read the objects contents from.
2765  );
2767 };
2768 
2769 
2783 #ifdef DOC_PLUS_PLUS
2785 #endif
2786 PDECLARE_STRING_DICTIONARY(PStringToString, PString);
2787  public:
2790  struct Initialiser {
2793  const char * key;
2795  const char * value;
2796  };
2800  PINDEX count,
2801  const Initialiser * init,
2802  PBoolean caselessKeys = false,
2803  PBoolean caselessValues = false
2804  );
2806 
2815  virtual void ReadFrom(
2816  istream &strm // Stream to read the objects contents from.
2817  );
2819 
2832  char ** ToCharArray(
2833  bool withEqualSign,
2834  PCharArray * storage = NULL
2835  ) const;
2836 };
2837 
2838 
2846 {
2847  public:
2849  PStringOptions(const PStringToString & other) : PStringToString(other) { }
2850  PStringOptions & operator=(const PStringToString & other) { PStringToString::operator=(other); return *this; }
2851 
2853  bool Contains(const char * key ) const { PConstCaselessString k(key); return PStringToString::Contains(k); }
2854  bool Contains(const PString & key ) const { return PStringToString::Contains(PCaselessString(key)); }
2855  bool Contains(const PCaselessString & key ) const { return PStringToString::Contains(key); }
2856  bool Contains(const PCaselessString & (*key)()) const { return PStringToString::Contains(key()); }
2857 
2858  // Overide default PStringToString::SetAt() to make sure the key is caseless
2859  PString * GetAt(const char * key ) const { PConstCaselessString k(key); return PStringToString::GetAt(k); }
2860  PString * GetAt(const PString & key ) const { return PStringToString::GetAt(PCaselessString(key)); }
2861  PString * GetAt(const PCaselessString & key ) const { return PStringToString::GetAt(key); }
2862  PString * GetAt(const PCaselessString & (*key)()) const { return PStringToString::GetAt(key()); }
2863 
2864  // Overide default PStringToString::SetAt() to make sure the key is caseless
2865  PBoolean SetAt(const char * key, const PString & data) { PConstCaselessString k(key); return SetAt(k, data); }
2866  PBoolean SetAt(const PString & key, const PString & data) { return SetAt(PCaselessString(key), data); }
2867  PBoolean SetAt(const PCaselessString & key, const PString & data) { MakeUnique(); return PStringToString::SetAt(key, data); }
2868  PBoolean SetAt(const PCaselessString & (*key)(), const PString & data) { return SetAt(key(), data); }
2869 
2870  // Overide default PStringToString::RemoveAt() to make sure the key is caseless
2871  PString * RemoveAt(const char * key) { PConstCaselessString k(key); return RemoveAt(k); }
2872  PString * RemoveAt(const PString & key) { return RemoveAt(PCaselessString(key)); }
2874  PString * RemoveAt(const PCaselessString & (*key)()) { return RemoveAt(key()); }
2875 
2877  PString GetString(const char * key, const char * dflt = NULL) const { PConstCaselessString k(key); return GetString(k, dflt); }
2878  PString GetString(const PString & key, const char * dflt = NULL) const { return GetString(PCaselessString(key), dflt); }
2879  PString GetString(const PCaselessString & key, const char * dflt = NULL) const;
2880  PString GetString(const PCaselessString & (*key)(), const char * dflt = NULL) const { return GetString(key(), dflt); }
2881 
2883  bool SetString(const char * key, const PString & value) { return SetAt(key, value); }
2884  bool SetString(const PString & key, const PString & value) { return SetAt(key, value); }
2885  bool SetString(const PCaselessString & key, const PString & value) { return SetAt(key, value); }
2886  bool SetString(const PCaselessString & (*key)(), const PString & value) { return SetAt(key, value); }
2887 
2889  bool GetBoolean(const char * key, bool dflt = false) const { PConstCaselessString k(key); return GetBoolean(k, dflt); }
2890  bool GetBoolean(const PString & key, bool dflt = false) const { return GetBoolean(PCaselessString(key), dflt); }
2891  bool GetBoolean(const PCaselessString & key, bool dflt = false) const;
2892  bool GetBoolean(const PCaselessString & (*key)(), bool dflt = false) const { return GetBoolean(key(), dflt); }
2893 
2895  void SetBoolean(const char * key, bool value) { PConstCaselessString k(key); SetBoolean(k, value); }
2896  void SetBoolean(const PString & key, bool value) { SetBoolean(PCaselessString(key), value); }
2897  void SetBoolean(const PCaselessString & key, bool value) { SetAt(key, value ? "true" : "false"); }
2898  void SetBoolean(const PCaselessString & (*key)(), bool value) { SetBoolean(key(), value); }
2899 
2901  long GetInteger(const char * key, long dflt = 0) const { PConstCaselessString k(key); return GetInteger(k, dflt); }
2902  long GetInteger(const PString & key, long dflt = 0) const { return GetInteger(PCaselessString(key), dflt); }
2903  long GetInteger(const PCaselessString & key, long dflt = 0) const;
2904  long GetInteger(const PCaselessString & (*key)(), long dflt = 0) const { return GetInteger(key(), dflt); }
2905 
2907  void SetInteger(const char * key, long value) { PConstCaselessString k(key); SetInteger(k, value); }
2908  void SetInteger(const PString & key, long value) { SetInteger(PCaselessString(key), value); }
2909  void SetInteger(const PCaselessString & key, long value);
2910  void SetInteger(const PCaselessString & (*key)(), long value) { SetInteger(key(), value); }
2911 
2913  double GetReal(const char * key, double dflt = 0) const { PConstCaselessString k(key); return GetReal(k, dflt); }
2914  double GetReal(const PString & key, double dflt = 0) const { return GetReal(PCaselessString(key), dflt); }
2915  double GetReal(const PCaselessString & key, double dflt = 0) const;
2916  double GetReal(const PCaselessString & (*key)(), double dflt = 0) const { return GetReal(key(), dflt); }
2917 
2919  void SetReal(const char * key, double value, int decimals) { PConstCaselessString k(key); SetReal(k, value, decimals); }
2920  void SetReal(const PString & key, double value, int decimals) { SetReal(PCaselessString(key), value, decimals); }
2921  void SetReal(const PCaselessString & key, double value, int decimals);
2922  void SetReal(const PCaselessString & (*key)(), double value, int decimals) { SetReal(key(), value, decimals); }
2923 
2925  __inline bool Has(const char * key) const { return Contains(key); }
2926  __inline bool Has(const PString & key) const { return Contains(key); }
2927  __inline bool Has(const PCaselessString & key) const { return Contains(key); }
2928  __inline bool Has(const PCaselessString & (*key)()) const { return Contains(key); }
2929 
2931  __inline PString Get(const char * key, const char * dflt = NULL) const { return GetString(key, dflt); }
2932  __inline PString Get(const PString & key, const char * dflt = NULL) const { return GetString(key, dflt); }
2933  __inline PString Get(const PCaselessString & key, const char * dflt = NULL) const { return GetString(key, dflt); }
2934  __inline PString Get(const PCaselessString & (*key)(), const char * dflt = NULL) const { return GetString(key, dflt); }
2935  __inline PString Get(const char * key, const PString & dflt) const { return GetString(key, dflt); }
2936  __inline PString Get(const PString & key, const PString & dflt) const { return GetString(key, dflt); }
2937  __inline PString Get(const PCaselessString & key, const PString & dflt) const { return GetString(key, dflt); }
2938  __inline PString Get(const PCaselessString & (*key)(), const PString & dflt) const { return GetString(key, dflt); }
2939 
2941  __inline bool Set(const char * key, const PString & value) { return SetAt(key, value); }
2942  __inline bool Set(const PString & key, const PString & value) { return SetAt(key, value); }
2943  __inline bool Set(const PCaselessString & key, const PString & value) { return SetAt(key, value); }
2944  __inline bool Set(const PCaselessString & (*key)(), const PString & value) { return SetAt(key, value); }
2945 
2947  __inline void Remove(const char * key) { RemoveAt(key); }
2948  __inline void Remove(const PString & key) { RemoveAt(key); }
2949  __inline void Remove(const PCaselessString & key) { RemoveAt(key); }
2950  __inline void Remove(const PCaselessString & (*key)()) { RemoveAt(key); }
2951 };
2952 
2953 
2960 {
2961  PCLASSINFO(PRegularExpression, PObject);
2962 
2963  public:
2966  enum {
2977  };
2979  enum {
2989  };
2990 
2993 
2997  const PString & pattern,
2998  int flags = IgnoreCase
2999  );
3000 
3004  const char * cpattern,
3005  int flags = IgnoreCase
3006  );
3007 
3012  const PRegularExpression &
3013  );
3014 
3019  const PRegularExpression &
3020  );
3021 
3025 
3026 
3031  virtual void PrintOn(
3032  ostream & strm
3033  ) const;
3035 
3038  enum ErrorCodes {
3041  NoError = 0,
3044 
3045  // POSIX regcomp return error codes. (In the order listed in the standard.)
3070 
3071  /* Error codes we've added. */
3080  };
3081 
3087  ErrorCodes GetErrorCode() const;
3088 
3095  PString GetErrorText() const;
3096 
3098  const PString & GetPattern() const { return patternSaved; }
3100 
3104  PBoolean Compile(
3105  const PString & pattern,
3106  int flags = IgnoreCase
3107  );
3115  PBoolean Compile(
3116  const char * cpattern,
3117  int flags = IgnoreCase
3118  );
3119 
3120 
3122  PBoolean Execute(
3123  const PString & str,
3124  PINDEX & start,
3125  int flags = 0
3126  ) const;
3128  PBoolean Execute(
3129  const PString & str,
3130  PINDEX & start,
3131  PINDEX & len,
3132  int flags = 0
3133  ) const;
3135  PBoolean Execute(
3136  const char * cstr,
3137  PINDEX & start,
3138  int flags = 0
3139  ) const;
3141  PBoolean Execute(
3142  const char * cstr,
3143  PINDEX & start,
3144  PINDEX & len,
3145  int flags = 0
3146  ) const;
3148  PBoolean Execute(
3149  const PString & str,
3150  PIntArray & starts,
3151  int flags = 0
3152  ) const;
3154  PBoolean Execute(
3155  const PString & str,
3156  PIntArray & starts,
3157  PIntArray & ends,
3158  int flags = 0
3159  ) const;
3161  PBoolean Execute(
3162  const char * cstr,
3163  PIntArray & starts,
3164  int flags = 0
3165  ) const;
3182  PBoolean Execute(
3183  const char * cstr,
3184  PIntArray & starts,
3185  PIntArray & ends,
3186  int flags = 0
3187  ) const;
3204  PBoolean Execute(
3205  const char * cstr,
3206  PStringArray & substring,
3207  int flags = 0
3208  ) const;
3210 
3219  static PString EscapeString(
3220  const PString & str
3221  );
3223 
3224  protected:
3227 
3228  void * expression;
3230 };
3231 
3232 
3233 #endif // PTLIB_STRING_H
3234 
3235 
3236 // End Of File ///////////////////////////////////////////////////////////////
PINLINE PBoolean AbstractContains(const PObject &key) const
Determine if the value of the object is contained in the hash table.
const char * value
String value for ordinal.
Definition: pstring.h:2697
long AsInteger(unsigned base=10) const
Convert the string to an integer value using the specified number base.
void SetReal(const PString &key, double value, int decimals)
Definition: pstring.h:2920
PString * GetAt(const PCaselessString &key) const
Definition: pstring.h:2861
PString * RemoveAt(const PString &key)
Definition: pstring.h:2872
char ** ToCharArray(bool withEqualSign, PCharArray *storage=NULL) const
Create an array of C strings.
virtual PBoolean MakeUnique()
Make this instance to be the one and only reference to the container contents.
__inline void Remove(const char *key)
Remove option value.
Definition: pstring.h:2947
virtual ~PStringStream()
Destroy the string stream, deleting the stream buffer.
void SetBoolean(const PCaselessString &(*key)(), bool value)
Definition: pstring.h:2898
PRegularExpression()
Create a new, empty, regular expression.
Trailing backslash.
Definition: pstring.h:3053
Not implemented.
Definition: pstring.h:3049
ErrorCodes GetErrorCode() const
Get the error code for the last Compile() or Execute() operation.
friend PString pvsprintf(const char *cfmt, va_list args)
Produce formatted output as a string.
bool GetBoolean(const char *key, bool dflt=false) const
Get the option value as a boolean.
Definition: pstring.h:2889
PString & operator&=(const PString &str)
Concatenate a string to another string, modifiying that string.
PString & operator=(const PString &str)
Assign the string to the current object.
PRegularExpression & operator=(const PRegularExpression &)
Assign a regular expression.
ostream & operator<<(ostream &stream, const PString &string)
Definition: pstring.h:1655
bool operator*=(const PString &str) const
Compare two strings using case insensitive comparison.
virtual void PrintOn(ostream &strm) const
Output the string to the specified stream.
Definition: lists.h:686
const PString & GetPattern() const
Return the string which represents the pattern matched by the regular expression. ...
Definition: pstring.h:3098
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
Array of characters.
Definition: array.h:551
This template class maps the PAbstractDictionary to a specific key type and a PString data type...
Definition: pstring.h:2463
PINDEX value
Ordinal value for string.
Definition: pstring.h:2744
Invalid character class name.
Definition: pstring.h:3051
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
PINDEX AppendString(const PString &str)
Add a string to the list.
PINDEX InternalStringSelect(const char *str, PINDEX len, Element *thisElement, Element *&lastElement) const
PStringArray & operator+=(const PStringArray &array)
Concatenate a PString or PStringArray to the array.
bool operator<=(const PObject &str) const
Compare two strings using the PObject::Compare() function.
If this bit is set, then anchors do not match at newline characters in the string.
Definition: pstring.h:2976
PBoolean SetAt(const PCaselessString &key, const PString &data)
Definition: pstring.h:2867
PStringOptions()
Definition: pstring.h:2848
PINLINE PINDEX GetLength() const
Determine the length of the null terminated string.
virtual PObject * Clone() const
Make a complete duplicate of the string.
static PStringList container(const stlContainer &vec)
Create a PStringArray from an STL container.
Definition: pstring.h:2271
void * expression
Definition: pstring.h:3228
virtual void AssignContents(const PContainer &cont)
Copy the container contents.
__inline bool Set(const PCaselessString &key, const PString &value)
Definition: pstring.h:2943
#define PAssertAlways(msg)
This macro is used to assert immediately.
Definition: object.h:229
PStringSet(PINDEX count, char const *const *strarr, PBoolean caseless=false)
Create a PStringArray from the array of C strings.
__inline bool Has(const PString &key) const
Definition: pstring.h:2926
long GetInteger(const PCaselessString &(*key)(), long dflt=0) const
Definition: pstring.h:2904
PINDEX key
Ordinal key for string.
Definition: pstring.h:2695
PCaselessString()
Create a new, empty, caseless string.
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
POrdinalToString(PINDEX count, const Initialiser *init)
Initialise the ordinal dictionary of strings from the static array.
PInt64 AsInt64(unsigned base=10) const
Convert the string to an integer value using the specified number base.
virtual PString & MakeEmpty()
Make the current string empty.
PCaselessString & operator=(const PString &str)
Assign the string to the current object.
#define PINLINE
Definition: object.h:127
This class is a standard C++ stream class descendent for reading or writing streamed data to or from ...
Definition: pstring.h:1878
Definition: pstring.h:290
void Replace(const PString &target, const PString &subs, PBoolean all=false, PINDEX offset=0)
Locate the substring within the string and replace it with the specifed substring.
ErrorCodes
Error codes.
Definition: pstring.h:3039
PINDEX GetStringsIndex(const PString &str) const
Get the index of the string with the specified value.
Definition: pstring.h:284
PString & sprintf(const char *cfmt,...)
Concatenate a formatted output to the string.
PINDEX AppendString(const PString &str)
Append a string to the array.
This is a dictionary collection class of PString objects, keyed by another string.
Definition: pstring.h:2784
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
PContainer & operator=(const PContainer &cont)
Assign one container reference to another.
Invalid back reference.
Definition: pstring.h:3055
const char * key
String key for string.
Definition: pstring.h:2793
static PString EscapeString(const PString &str)
Escape all characters in the str parameter that have a special meaning within a regular expression...
virtual Comparison InternalCompare(PINDEX offset, char c) const
Definition: pstring.h:287
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:1184
bool Contains(const PCaselessString &(*key)()) const
Definition: pstring.h:2856
PString(PContainerReference &reference)
Definition: pstring.h:1651
Premature end.
Definition: pstring.h:3073
bool operator!=(const PObject &str) const
Compare two strings using the PObject::Compare() function.
This class is a variation of a string that ignores case.
Definition: pstring.h:1708
An abstract dictionary container.
Definition: dict.h:626
__inline bool Set(const PCaselessString &(*key)(), const PString &value)
Definition: pstring.h:2944
PBYTEArray ToPascal() const
Convert a standard null terminated string to a "pascal" style string.
PString * GetAt(const PCaselessString &(*key)()) const
Definition: pstring.h:2862
void Include(const PString &key)
Include the spcified string value into the set.
PStringOptions & operator=(const PStringToString &other)
Definition: pstring.h:2850
PBoolean SetAt(const PString &key, const PString &data)
Definition: pstring.h:2866
virtual PBoolean SetSize(PINDEX)
Definition: pstring.h:1847
PString RightTrim() const
Create a string consisting of all characters from the source string except all spaces at the end of t...
PBoolean SetAt(const PCaselessString &(*key)(), const PString &data)
Definition: pstring.h:2868
char ** ToCharArray(PCharArray *storage=NULL) const
Create an array of C strings.
double GetReal(const PCaselessString &(*key)(), double dflt=0) const
Definition: pstring.h:2916
PString operator[](PINDEX index) const
PBoolean SetAt(const char *key, const PString &data)
Definition: pstring.h:2865
This is an array collection class of PString objects.
Definition: pstring.h:2024
~PRegularExpression()
Release storage for the compiled regular expression.
__inline void Remove(const PCaselessString &key)
Definition: pstring.h:2949
PConstantString< PString > PConstString
Constant PString type. See PConstantString.
Definition: pstring.h:1861
__inline bool Has(const PCaselessString &(*key)()) const
Definition: pstring.h:2928
virtual Comparison InternalCompare(PINDEX offset, char c) const
Use extended regular expressions.
Definition: pstring.h:2969
PString Right(PINDEX len) const
Extract a portion of the string into a new string.
virtual PINDEX HashFunction() const
Calculate a hash value for use in sets and dictionaries.
int flagsSaved
Definition: pstring.h:3226
PINLINE PString()
Construct an empty string.
PString patternSaved
Definition: pstring.h:3225
PString ToLiteral() const
Convert the string to C literal string format.
PBoolean Compile(const PString &pattern, int flags=IgnoreCase)
Compiler pattern.
PString * RemoveAt(const char *key)
Definition: pstring.h:2871
bool GetBoolean(const PString &key, bool dflt=false) const
Definition: pstring.h:2890
virtual void ReadFrom(istream &strm)
Input the string from the specified stream.
PStringArray operator+(const PStringArray &array)
Create a new PStringArray, and add PString or PStringArray to it a new PStringArray.
bool Contains(const PCaselessString &key) const
Definition: pstring.h:2855
Unmatched ) or \); not returned from regcomp.
Definition: pstring.h:3077
This template class maps the PAbstractList to a specific object type.
Definition: lists.h:321
void InternalFromUCS2(const wchar_t *ptr, PINDEX len)
virtual PBoolean IsEmpty() const
Determine if the string is empty.
virtual PString * RemoveAt(const K &key)
Remove an object at the specified key.
Definition: pstring.h:2549
No preceding re for repetition op.
Definition: pstring.h:3069
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
PStringArray Tokenise(const PString &separators, PBoolean onePerSeparator=true) const
Split the string into an array of substrings.
PINDEX InsertString(const PString &before, const PString &str)
Insert a string into the list.
virtual PString * GetAt(const K &key) const
Get the object at the specified key position.
Definition: pstring.h:2562
PINDEX FindSpan(const PString &set, PINDEX offset=0) const
Locate the position of character not in the set.
PStringOptions(const PStringToString &other)
Definition: pstring.h:2849
BOOL PBoolean
Definition: object.h:102
virtual Comparison Compare(const PObject &obj) const
Get the relative rank of the two strings.
PWCharArray AsUCS2() const
Convert UTF-8 string to UCS-2.
virtual PBoolean AbstractSetAt(const PObject &key, PObject *obj)
Add a new object to the collection.
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
__inline PString Get(const PCaselessString &key, const char *dflt=NULL) const
Definition: pstring.h:2933
PString & operator+=(const PString &str)
Concatenate a string to another string, modifiying that string.
PString operator()(PINDEX start, PINDEX end) const
Extract a portion of the string into a new string.
PINDEX Find(char ch, PINDEX offset=0) const
Locate the position within the string of the character.
bool Contains(const PString &key) const
Definition: pstring.h:2854
PStringList & operator+=(const PStringList &list)
Concatenate a PString or PStringArray to the list.
This is a dictionary collection class of ordinals keyed by PString objects.
Definition: pstring.h:2733
PBoolean MakeMinimumSize()
Set the actual memory block array size to the minimum required to hold the current string contents...
Array of unsigned characters.
Definition: array.h:670
Success.
Definition: pstring.h:3041
PINDEX GetNextStringsIndex(const PString &str) const
Get the index of the next string after specified value.
__inline void Remove(const PString &key)
Definition: pstring.h:2948
ConversionType
Definition: pstring.h:281
virtual PBoolean SetDataAt(PINDEX index, const PString &str)
Set the data at the specified ordinal index position in the dictionary.
Definition: pstring.h:2574
Specialised version of PStringToString to contain a dictionary of options/attributes.
Definition: pstring.h:2845
long GetInteger(const PString &key, long dflt=0) const
Definition: pstring.h:2902
PStringToString(PINDEX count, const Initialiser *init, PBoolean caselessKeys=false, PBoolean caselessValues=false)
Initialise the string dictionary of strings from the static array.
PString & GetDataAt(PINDEX index) const
Get the data in the dictionary at the ordinal index position.
Definition: pstring.h:2620
This is a sorted list collection class of PString objects.
Definition: pstring.h:2296
PStringToOrdinal(PINDEX count, const Initialiser *init, PBoolean caseless=false)
Initialise the string dictionary of ordinals from the static array.
Ignore case in search.
Definition: pstring.h:2971
void SetBoolean(const char *key, bool value)
Set the option value as a boolean.
Definition: pstring.h:2895
const K & GetKeyAt(PINDEX index) const
Get the key in the dictionary at the ordinal index position.
Definition: pstring.h:2606
Create a constant string.
Definition: pstring.h:1834
virtual PObject * AbstractGetAt(const PObject &key) const
Get the object at the specified key position.
Definition: pstring.h:285
PString * GetAt(const char *key) const
Definition: pstring.h:2859
char * theArray
Pointer to the allocated block of memory.
Definition: array.h:245
Definition: pstring.h:289
PStringArray(PINDEX count, char const *const *strarr, PBoolean caseless=false)
Create a PStringArray from the array of C strings.
__inline bool Set(const char *key, const PString &value)
Set the option value.
Definition: pstring.h:2941
const char * value
String value for string.
Definition: pstring.h:2795
const PString & operator[](const K &key) const
Get the string contained in the dictionary at the key position.
Definition: pstring.h:2504
Like NotBeginningOfLine, except for the end-of-line.
Definition: pstring.h:2988
virtual PBoolean MakeUnique()
Make this instance to be the one and only reference to the container contents.
virtual PBoolean SetDataAt(PINDEX index, PObject *obj)
Set the data at the specified ordinal index position in the dictionary.
PCaselessString(PContainerReference &reference)
Definition: pstring.h:1814
PStringArray(const std::vector< PString > &vec)
Create a PStringArray from a vector of PStrings.
Definition: pstring.h:2058
PStringDictionary()
Create a new, empty, dictionary.
Definition: pstring.h:2476
PString Trim() const
Create a string consisting of all characters from the source string except all spaces at the beginnin...
Definition: pstring.h:282
Comparison NumCompare(const PString &str, PINDEX count=P_MAX_INDEX, PINDEX offset=0) const
Compare a string against a substring of the object.
void Splice(const PString &str, PINDEX pos, PINDEX len=0)
Splice the string into the current string at the specified position.
Invalid range end.
Definition: pstring.h:3065
__inline PString Get(const PCaselessString &(*key)(), const char *dflt=NULL) const
Definition: pstring.h:2934
DWORD AsUnsigned(unsigned base=10) const
Convert the string to an integer value using the specified number base.
PString GetString(const PCaselessString &(*key)(), const char *dflt=NULL) const
Definition: pstring.h:2880
bool operator==(const PObject &str) const
Compare two strings using the PObject::Compare() function.
PStringList(PINDEX count, char const *const *strarr, PBoolean caseless=false)
Create a PStringList from the array of C strings.
void Exclude(const PString &key)
Exclude the spcified string value from the set.
void Delete(PINDEX start, PINDEX len)
Remove the substring from the string.
This template class maps the PAbstractSet to a specific object type.
Definition: dict.h:455
virtual PObject * Clone() const
Make a complete duplicate of the string.
PString operator()(const K &key, const char *dflt=NULL) const
Get the string contained in the dictionary at the key position.
Definition: pstring.h:2520
PString & operator=(const std::string &str)
Assign the string to the current object.
Definition: pstring.h:332
PINDEX AppendString(const PString &str)
Append a string to the list.
PINDEX GetStringsIndex(const PString &str) const
Get the index of the string with the specified value.
Definition: contain.h:51
PString * GetAt(const PString &key) const
Definition: pstring.h:2860
__inline bool Set(const PString &key, const PString &value)
Definition: pstring.h:2942
The character string class.
Definition: pstring.h:108
bool SetString(const char *key, const PString &value)
Set the option value.
Definition: pstring.h:2883
This is a set collection class of PString objects.
Definition: pstring.h:2391
PString pvsprintf(const char *fmt, va_list arg)
The same as the standard C vsnprintf(fmt, 1000, va_list arg), but returns a PString instead of a cons...
PString operator&(const PString &str) const
Concatenate two strings to produce a third.
Unmatched left bracket.
Definition: pstring.h:3057
const char * Initialiser
Definition: pstring.h:115
static PString Empty()
Return an empty string.
const char * key
String key for ordinal.
Definition: pstring.h:2742
virtual void DestroyReference()
Definition: pstring.h:1849
bool deleteObjects
Definition: contain.h:72
PString * RemoveAt(const PCaselessString &key)
Definition: pstring.h:2873
virtual PBoolean SetAt(const K &key, const PString &str)
Add a new object to the collection.
Definition: pstring.h:2590
Invalid pattern.
Definition: pstring.h:3047
PCaselessString & operator=(const std::string &str)
Assign the string to the current object.
Definition: pstring.h:1758
PStringDictionary(int dummy, const PStringDictionary *c)
Definition: pstring.h:2625
virtual PString & MakeEmpty()
Make the current string empty.
bool GetBoolean(const PCaselessString &(*key)(), bool dflt=false) const
Definition: pstring.h:2892
__inline PString Get(const PString &key, const char *dflt=NULL) const
Definition: pstring.h:2932
void SetBoolean(const PCaselessString &key, bool value)
Definition: pstring.h:2897
Abstract class to embody the base functionality of a container.
Definition: contain.h:104
This is a list collection class of PString objects.
Definition: pstring.h:2184
Definition: pstring.h:286
PString GetString(const PString &key, const char *dflt=NULL) const
Definition: pstring.h:2878
__inline bool Has(const PCaselessString &key) const
Definition: pstring.h:2927
PINDEX FindOneOf(const PString &set, PINDEX offset=0) const
Locate the position of one of the characters in the set.
bool operator<(const PObject &str) const
Compare two strings using the PObject::Compare() function.
Definition: pstring.h:288
PStringSet & operator-=(const PString &key)
Exclude the spcified string value from the set.
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
void SetReal(const PCaselessString &(*key)(), double value, int decimals)
Definition: pstring.h:2922
PString ToUpper() const
Create a string consisting of all characters from the source string with all lower case letters conve...
__inline PString Get(const char *key, const PString &dflt) const
Definition: pstring.h:2935
PBASEARRAY(PWCharArray, wchar_t)
bool operator>=(const PObject &str) const
Compare two strings using the PObject::Compare() function.
__inline PString Get(const PString &key, const PString &dflt) const
Definition: pstring.h:2936
PString GetErrorText() const
Get the text description for the error of the last Compile() or Execute() operation.
PStringStream & operator=(const PStringStream &strm)
Assign the string part of the stream to the current object.
This template class maps the PAbstractSortedList to a specific object type.
Definition: lists.h:954
void SetBoolean(const PString &key, bool value)
Definition: pstring.h:2896
bool SetString(const PCaselessString &(*key)(), const PString &value)
Definition: pstring.h:2886
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
void SetReal(const char *key, double value, int decimals)
Set a floating point real value for the particular MIME info field.
Definition: pstring.h:2919
Invalid parameter was passed to a function.
Definition: object.h:159
~PConstantString()
Definition: pstring.h:1845
Didn't find a match (for regexec).
Definition: pstring.h:3043
virtual PObject & GetRefAt(const PObject &key) const
Get the object at the specified key position.
PConstantString(typename ParentString::Initialiser init)
Definition: pstring.h:1839
Parenthesis imbalance.
Definition: pstring.h:3059
PString GetString(const char *key, const char *dflt=NULL) const
Get an option value.
Definition: pstring.h:2877
virtual const PObject & AbstractGetKeyAt(PINDEX index) const
Get the key in the hash table at the ordinal index position.
This is a dictionary collection class of PString objects, keyed by an ordinal value.
Definition: pstring.h:2686
PBoolean Contains(const K &key) const
Determine if the value of the object is contained in the hash table.
Definition: pstring.h:2534
static PStringArray container(const stlContainer &vec)
Create a PStringArray from an STL container.
Definition: pstring.h:2081
PString LeftTrim() const
Create a string consisting of all characters from the source string except all spaces at the beginnin...
void SetInteger(const PCaselessString &(*key)(), long value)
Definition: pstring.h:2910
PStringList operator+(const PStringList &array)
Create a new PStringList, and add PString or PStringList to it a new PStringList. ...
This template class maps the PArrayObjects to a specific object type.
Definition: array.h:1024
PStringSet & operator+=(const PString &key)
Include the spcified string value into the set.
PConstantString< PCaselessString > PConstCaselessString
Constant PCaselessString type. See PConstantString.
Definition: pstring.h:1864
A class representing a regular expression that may be used for locating patterns in strings...
Definition: pstring.h:2959
PINDEX FindRegEx(const PRegularExpression &regex, PINDEX offset=0) const
Locate the position within the string of one of the regular expression.
virtual void AssignContents(const PContainer &)
Definition: pstring.h:1848
PStringArray(const std::vector< std::string > &vec)
Create a PStringArray from a vector of std::string.
Definition: pstring.h:2069
bool Contains(const char *key) const
Determine if the specified key is present.
Definition: pstring.h:2853
Definition: pstring.h:283
bool SetString(const PString &key, const PString &value)
Definition: pstring.h:2884
PStringArray Lines() const
Split the string into individual lines.
void SetInteger(const char *key, long value)
Set an integer value for the particular MIME info field.
Definition: pstring.h:2907
__inline PString Get(const PCaselessString &key, const PString &dflt) const
Definition: pstring.h:2937
bool SetString(const PCaselessString &key, const PString &value)
Definition: pstring.h:2885
PUInt64 AsUnsigned64(unsigned base=10) const
Convert the string to an integer value using the specified number base.
double AsReal() const
Convert the string to a floating point number.
PString * RemoveAt(const PCaselessString &(*key)())
Definition: pstring.h:2874
__inline void Remove(const PCaselessString &(*key)())
Definition: pstring.h:2950
__inline PString Get(const char *key, const char *dflt=NULL) const
Get the option value.
Definition: pstring.h:2931
Miscellaneous error.
Definition: pstring.h:3079
PINDEX GetStringsIndex(const PString &str) const
As for GetValuesIndex() but takes a PString argument so that literals will be automatically converted...
PString operator+(const PString &str) const
Concatenate two strings to produce a third.
virtual PObject * Clone() const
Make a complete duplicate of the dictionary.
Definition: pstring.h:2486
bool operator!() const
Determine if the string is NOT empty.
__inline bool Has(const char *key) const
Determine of the option exists.
Definition: pstring.h:2925
virtual PBoolean SetSize(PINDEX newSize)
Set the size of the string.
ErrorCodes lastError
Definition: pstring.h:3229
bool operator>(const PObject &str) const
Compare two strings using the PObject::Compare() function.
PString & vsprintf(const PString &fmt, va_list args)
Concatenate a formatted output to the string.
Unmatched \.
Definition: pstring.h:3061
Invalid contents of \.
Definition: pstring.h:3063
PINDEX FindLast(char ch, PINDEX offset=P_MAX_INDEX) const
Locate the position of the last matching character.
PString Mid(PINDEX start, PINDEX len=P_MAX_INDEX) const
Extract a portion of the string into a new string.
PContainerReference * reference
Definition: contain.h:291
Array of integers.
Definition: array.h:616
__inline PString Get(const PCaselessString &(*key)(), const PString &dflt) const
Definition: pstring.h:2938
virtual PObject & AbstractGetDataAt(PINDEX index) const
Get the data in the hash table at the ordinal index position.
double GetReal(const char *key, double dflt=0) const
Get the option value as a floating point real.
Definition: pstring.h:2913
PString psprintf(const char *fmt,...)
The same as the standard C snprintf(fmt, 1000, ...), but returns a PString instead of a const char *...
This template class maps the PAbstractDictionary to a specific key type and a POrdinalKey data type...
Definition: dict.h:1039
PBoolean Execute(const PString &str, PINDEX &start, int flags=0) const
Execute regular expression.
PBoolean MatchesRegEx(const PRegularExpression &regex) const
Return true if the entire string matches the regular expression.
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PSortedStringList(PINDEX count, char const *const *strarr, PBoolean caseless=false)
Create a PStringArray from the array of C strings.
virtual void PrintOn(ostream &strm) const
Output the regular expression to the specified stream.
PStringStream()
Create a new, empty, string stream.
Compiled pattern bigger than 2^16 bytes.
Definition: pstring.h:3075
void SetInteger(const PString &key, long value)
Definition: pstring.h:2908
PString Left(PINDEX len) const
Extract a portion of the string into a new string.
#define PNEW
Macro for overriding system default new operator.
Definition: object.h:890
friend PString psprintf(const char *cfmt,...)
Produce formatted output as a string.
PCaselessString(const std::string &str)
Create a caseless string from a std::string.
Definition: pstring.h:1735
This class is used when an ordinal index value is the key for PSet and PDictionary classes...
Definition: dict.h:50
Ran out of memory.
Definition: pstring.h:3067
If this bit is set, then the beginning-of-line operator doesn't match the beginning of the string (pr...
Definition: pstring.h:2986
double GetReal(const PString &key, double dflt=0) const
Definition: pstring.h:2914
PString ToLower() const
Create a string consisting of all characters from the source string with all upper case letters conve...
long GetInteger(const char *key, long dflt=0) const
Get the option value as an integer.
Definition: pstring.h:2901