PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
30 
31 #include <ptlib/bitwise_enum.h>
32 
33 #ifndef PTLIB_STRING_H
34 #define PTLIB_STRING_H
35 
36 #ifdef P_USE_PRAGMA
37 #pragma interface
38 #endif
39 
40 
41 #include <string>
42 #include <vector>
43 #include <ptlib/array.h>
44 
45 
47 // PString class
48 
49 class PStringArray;
50 class PRegularExpression;
51 class PString;
52 
57  const char * fmt,
58  ...
59 );
60 
65  const char * fmt,
66  va_list arg
67 );
68 
69 
70 #ifdef P_HAS_WCHAR
71 typedef PBaseArray<wchar_t> PWCharArray;
73 #endif
74 
75 
108 class PString : public PCharArray
109 {
110  PCLASSINFO(PString, PCharArray);
111  public:
112  typedef const char * Initialiser;
113 
119  PString();
120 
124  PString(
125  const PString & str
126  );
127 
131  PString(
132  const PCharArray & buf
133  );
134 
139  PString(
140  const PBYTEArray & buf
141  );
142 
145  PString(
146  const std::string & str
147  );
148 
154  PString(
155  const char * cstr
156  );
157 
162 #ifdef P_HAS_WCHAR
163  PString(
164  const wchar_t * ustr
165  );
166 #endif
167 
178  PString(
179  const char * cstr,
180  PINDEX len
181  );
182 
183 #ifdef P_HAS_WCHAR
184 
194  PString(
195  const wchar_t * ustr,
196  PINDEX len
197  );
198 
209  PString(
210  const PWCharArray & ustr
211  );
212 #endif // P_HAS_WCHAR
213 
219  PString(
220  char ch
221  );
222 
227  PString(
228  short n
229  );
230 
235  PString(
236  unsigned short n
237  );
238 
243  PString(
244  int n
245  );
246 
251  PString(
252  unsigned int n
253  );
254 
259  PString(
260  long n
261  );
262 
267  PString(
268  unsigned long n
269  );
270 
271 #ifdef HAVE_LONG_LONG_INT
272 
276  PString(
277  long long n
278  );
279 #endif
280 
281 #ifdef HAVE_UNSIGNED_LONG_LONG_INT
282 
286  PString(
287  unsigned long long n
288  );
289 #endif
290 
291 
292  /* Type of conversion to make in the conversion constructors.
293  */
305  };
306 
307  /* Contruct a new string converting from the spcified data source into
308  a string array.
309  */
310  PString(
311  ConversionType type,
312  const char * str,
313  ...
314  );
315 
316 #ifdef HAVE_LONG_LONG_INT
317  PString(
318  ConversionType type,
319  long long value,
320  unsigned param = 10
324  );
325 #endif
326 #ifdef HAVE_UNSIGNED_LONG_LONG_INT
327  PString(ConversionType type, unsigned long long value, unsigned param = 10);
328 #endif
329 
330  PString(ConversionType type, unsigned long value, unsigned param = 10);
331  PString(ConversionType type, signed long value, unsigned param = 10);
332  PString(ConversionType type, unsigned int value, unsigned param = 10);
333  PString(ConversionType type, signed int value, unsigned param = 10);
334  PString(ConversionType type, unsigned short value, unsigned param = 10);
335  PString(ConversionType type, signed short value, unsigned param = 10);
336  PString(ConversionType type, unsigned char value, unsigned param = 10);
337  PString(ConversionType type, signed char value, unsigned param = 10);
338 
339  /* Contruct a new string converting from the spcified data source into
340  a string array.
341  */
342  PString(
343  ConversionType type,
344  double value,
345  unsigned places
346  );
347 
355  PString & operator=(
356  const PString & str
357  );
358 
367  const std::string & str
368  ) { return operator=(str.c_str()); }
369 
379  PString & operator=(
380  const char * cstr
381  );
382 
391  PString & operator=(
392  char ch
393  );
394 
399  PString & operator=(
400  short n
401  );
402 
407  PString & operator=(
408  unsigned short n
409  );
410 
415  PString & operator=(
416  int n
417  );
418 
423  PString & operator=(
424  unsigned int n
425  );
426 
431  PString & operator=(
432  long n
433  );
434 
439  PString & operator=(
440  unsigned long n
441  );
442 
443 #ifdef HAVE_LONG_LONG_INT
444 
448  PString & operator=(
449  long long n
450  );
451 #endif
452 
453 #ifdef HAVE_UNSIGNED_LONG_LONG_INT
454 
458  PString & operator=(
459  unsigned long long n
460  );
461 #endif
462 
465  virtual PString & MakeEmpty();
466 
469  static const PString & Empty();
471 
478  virtual PObject * Clone() const;
479 
489  virtual Comparison Compare(
490  const PObject & obj
491  ) const;
492 
495  virtual void PrintOn(
496  ostream & strm
497  ) const;
498 
504  virtual void ReadFrom(
505  istream & strm
506  );
507 
521  virtual PINDEX HashFunction() const;
523 
542  virtual PBoolean SetSize(
543  PINDEX newSize
544  );
545 
554  virtual PBoolean IsEmpty() const;
555 
564  virtual PBoolean MakeUnique();
566 
567 
583  bool MakeMinimumSize(
584  PINDEX newLength = 0
585  );
586 
595  virtual PINDEX GetLength() const { return m_length; }
597 
607  const PString & str
608  ) const;
609 
622  const char * cstr
623  ) const;
624 
637  char ch
638  ) const;
639 
651  friend PString operator+(
652  const char * cstr,
653  const PString & str
654  );
655 
667  friend PString operator+(
668  char ch,
669  const PString & str
670  );
671 
678  const PString & str
679  );
680 
691  const char * cstr
692  );
693 
704  char ch
705  );
706 
707 
721  const PString & str
722  ) const;
723 
741  const char * cstr
742  ) const;
743 
761  char ch
762  ) const;
763 
780  friend PString operator&(
781  const char * cstr,
782  const PString & str
783  );
784 
801  friend PString operator&(
802  char ch,
803  const PString & str
804  );
805 
817  const PString & str
818  );
819 
835  const char * cstr
836  );
837 
838 
854  char ch
855  );
857 
858 
866  bool operator*=(
867  const PString & str
868  ) const;
869 
877  bool operator==(
878  const PString & str
879  ) const;
880 
888  bool operator!=(
889  const PString & str
890  ) const;
891 
899  bool operator<(
900  const PString & str
901  ) const;
902 
910  bool operator>(
911  const PString & str
912  ) const;
913 
921  bool operator<=(
922  const PString & str
923  ) const;
924 
932  bool operator>=(
933  const PString & str
934  ) const;
935 
936 
947  bool operator*=(
948  const char * cstr
949  ) const;
950 
961  bool operator==(
962  const char * cstr
963  ) const;
964 
975  bool operator!=(
976  const char * cstr
977  ) const;
978 
989  bool operator<(
990  const char * cstr
991  ) const;
992 
1003  bool operator>(
1004  const char * cstr
1005  ) const;
1006 
1017  bool operator<=(
1018  const char * cstr
1019  ) const;
1020 
1031  bool operator>=(
1032  const char * cstr
1033  ) const;
1034 
1045  friend bool operator*=(
1046  const char * cstr,
1047  const PString & str
1048  );
1049 
1060  friend bool operator==(
1061  const char * cstr,
1062  const PString & str
1063  );
1064 
1075  friend bool operator!=(
1076  const char * cstr,
1077  const PString & str
1078  );
1079 
1090  friend bool operator<(
1091  const char * cstr,
1092  const PString & str
1093  );
1094 
1105  friend bool operator>(
1106  const char * cstr,
1107  const PString & str
1108  );
1109 
1120  friend bool operator<=(
1121  const char * cstr,
1122  const PString & str
1123  );
1124 
1135  friend bool operator>=(
1136  const char * cstr,
1137  const PString & str
1138  );
1139 
1152  const PString & str,
1153  PINDEX count = P_MAX_INDEX,
1154  PINDEX offset = 0
1155  ) const;
1156 
1169  const char * cstr,
1170  PINDEX count = P_MAX_INDEX,
1171  PINDEX offset = 0
1172  ) const;
1174 
1175 
1179  PINDEX Find(
1180  char ch,
1181  PINDEX offset = 0
1182  ) const;
1183 
1185  PINDEX Find(
1186  const PString & str,
1187  PINDEX offset = 0
1188  ) const;
1189 
1190  /* Locate the position within the string of the character or substring. The
1191  search will begin at the character offset provided.
1192 
1193  If <code>offset</code> is beyond the length of the string, then the
1194  function will always return P_MAX_INDEX.
1195 
1196  The matching will be for identical character or string. If a search
1197  ignoring case is required then the string should be converted to a
1198  PCaselessString before the search is made.
1199 
1200  @return
1201  position of character or substring in the string, or P_MAX_INDEX if the
1202  character or substring is not in the string.
1203  */
1204  PINDEX Find(
1205  const char * cstr,
1206  PINDEX offset = 0
1207  ) const;
1208 
1210  PINDEX FindLast(
1211  char ch,
1212  PINDEX offset = P_MAX_INDEX
1213  ) const;
1214 
1216  PINDEX FindLast(
1217  const PString & str,
1218  PINDEX offset = P_MAX_INDEX
1219  ) const;
1220 
1238  PINDEX FindLast(
1239  const char * cstr,
1240  PINDEX offset = P_MAX_INDEX
1241  ) const;
1242 
1244  PINDEX FindOneOf(
1245  const PString & set,
1246  PINDEX offset = 0
1247  ) const;
1248 
1263  PINDEX FindOneOf(
1264  const char * cset,
1265  PINDEX offset = 0
1266  ) const;
1267 
1269  PINDEX FindSpan(
1270  const PString & set,
1271  PINDEX offset = 0
1272  ) const;
1273 
1289  PINDEX FindSpan(
1290  const char * cset,
1291  PINDEX offset = 0
1292  ) const;
1293 
1304  PINDEX FindRegEx(
1305  const PRegularExpression & regex,
1306  PINDEX offset = 0
1307  ) const;
1308 
1320  const PRegularExpression & regex,
1321  PINDEX & pos,
1322  PINDEX & len,
1323  PINDEX offset = 0,
1324  PINDEX maxPos = P_MAX_INDEX
1325  ) const;
1326 
1327 
1331  const PRegularExpression & regex
1332  ) const;
1333 
1344  PString & Replace(
1345  const PString & target,
1346  const PString & subs,
1347  PBoolean all = false,
1348  PINDEX offset = 0
1349  );
1350 
1358  PString & Splice(
1359  const PString & str,
1360  PINDEX pos,
1361  PINDEX len = 0
1362  );
1363 
1371  PString & Splice(
1372  const char * cstr,
1373  PINDEX pos,
1374  PINDEX len = 0
1375  );
1376 
1383  PString & Delete(
1384  PINDEX start,
1385  PINDEX len
1386  );
1388 
1389 
1410  PINDEX start,
1411  PINDEX end
1412  ) const;
1413 
1428  PString Left(
1429  PINDEX len
1430  ) const;
1431 
1446  PString Right(
1447  PINDEX len
1448  ) const;
1449 
1466  PString Mid(
1467  PINDEX start,
1468  PINDEX len = P_MAX_INDEX
1469  ) const;
1470 
1471 
1479  PString LeftTrim() const;
1480 
1488  PString RightTrim() const;
1489 
1498  PString Trim() const;
1499 
1500 
1509  PString ToLower() const;
1510 
1519  PString ToUpper() const;
1520 
1521 
1524  SplitOptions,6,
1525  (
1526  SplitOnly,
1527  SplitTrimBefore,
1528  SplitTrimAfter,
1529  SplitDefaultToBefore,
1530  SplitDefaultToAfter,
1531  SplitBeforeNonEmpty,
1532  SplitAfterNonEmpty
1533  ),
1534  SplitTrim = SplitTrimBefore|SplitTrimAfter,
1535  SplitNonEmpty = SplitBeforeNonEmpty|SplitAfterNonEmpty
1536  );
1547  __inline bool Split(
1548  const PString & delimiter,
1549  PString & before,
1550  PString & after,
1551  SplitOptions options = SplitTrim
1552  ) const
1553  { return InternalSplit(delimiter, before, after, options); }
1554 
1555  // The insanity below is all to maintain backward compatibility with the previous API
1556  __inline bool Split(char delimiter, PString & before, PString & after, SplitOptions options) const { return InternalSplit(delimiter, before, after, options); }
1557  __inline bool Split(char delimiter, PString & before, PString & after, SplitOptions_Bits options) const { return InternalSplit(delimiter, before, after, options); }
1558  __inline bool Split(const char * delimiter, PString & before, PString & after, SplitOptions options) const { return InternalSplit(delimiter, before, after, options); }
1559  __inline bool Split(const char * delimiter, PString & before, PString & after, SplitOptions_Bits options) const { return InternalSplit(delimiter, before, after, options); }
1560  __inline bool Split(char delimiter, PString & before, PString & after, bool trim) const { return InternalSplit(delimiter, before, after, trim ? SplitTrim : SplitOnly); }
1561 
1562 
1565  const PString & separators,
1567  PBoolean onePerSeparator = true
1569  ) const;
1595  const char * cseparators,
1597  PBoolean onePerSeparator = true
1599  ) const;
1600 
1614  PStringArray Lines() const;
1616 
1633  PString & sprintf(
1634  const char * cfmt,
1635  ...
1636  );
1637 
1652  friend PString psprintf(
1653  const char * cfmt,
1654  ...
1655  );
1656 
1658  PString & vsprintf(
1659  const PString & fmt,
1660  va_list args
1661  );
1676  PString & vsprintf(
1677  const char * cfmt,
1678  va_list args
1679  );
1680 
1682  friend PString pvsprintf(
1683  const char * cfmt,
1684  va_list args
1685  );
1700  friend PString pvsprintf(
1701  const PString & fmt,
1702  va_list args
1703  );
1704 
1705 
1709  template <typename T> __inline T As(T t = T()) const;
1710 
1724  long AsInteger(
1725  unsigned base = 0
1726  ) const;
1740  DWORD AsUnsigned(
1741  unsigned base = 0
1742  ) const;
1756  int64_t AsInteger64(
1757  unsigned base = 0
1758  ) const;
1759 
1760  __inline PInt64 AsInt64(unsigned base = 0) const { return AsInteger(base); } // Backward compatibility
1761 
1775  uint64_t AsUnsigned64(
1776  unsigned base = 0
1777  ) const;
1778 
1789  double AsReal() const;
1790 
1791 #ifdef P_HAS_WCHAR
1792 
1796  PWCharArray AsWide() const;
1797 
1798  P_DEPRECATED PWCharArray AsUCS2() const { return AsWide(); }
1799 #endif
1800 
1811  PBYTEArray ToPascal() const;
1812 
1821  PString ToLiteral() const;
1822 
1831  PINDEX & offset
1832  ) const;
1833 
1841  operator const unsigned char *() const;
1842 
1845  operator std::string () const
1846  { return std::string(theArray); }
1847 
1869  char * GetPointerAndSetLength(
1870  PINDEX len
1871  );
1872 
1877  virtual const char * GetPointer(PINDEX = 0) const { return (const char *)(*this); }
1879 
1882  __inline std::string::size_type size() const { return (std::string::size_type)GetLength(); }
1883  __inline std::string::size_type length() const { return (std::string::size_type)GetLength(); }
1884  __inline std::string::size_type capacity() const { return (std::string::size_type)(GetSize()-1); }
1885  __inline bool empty() const { return IsEmpty(); }
1886  __inline void clear() { MakeEmpty(); }
1887  __inline const char * c_str() const { return GetPointer(); }
1888  __inline char * data() { return PCharArray::GetPointer(); }
1889  __inline void push_back(char ch) { *this += ch; }
1890  __inline PString & append(std::string::size_type count, char ch) { while (--count > 0) *this += ch; return *this; }
1891  __inline PString & append(const char * s) { return *this += s; }
1892  __inline PString & append(const std::string & s) { return *this += s.c_str(); }
1893  __inline PString & insert(std::string::size_type index, std::string::size_type count, char ch) { while (--count > 0) Splice(&ch, index); return *this; }
1894  __inline PString & insert(std::string::size_type index, const char * s) { return Splice(s, index); }
1895  __inline PString & insert(std::string::size_type index, const std::string & s) { return Splice(s.c_str(), index); }
1896  __inline PString & erase(std::string::size_type index = 0, std::string::size_type count = std::string::npos) { return Delete(index, count != std::string::npos ? count : P_MAX_INDEX); }
1897  __inline PString & replace(std::string::size_type pos, std::string::size_type count, const char * s) { return Splice(s, pos, count); }
1898  __inline PString & replace(std::string::size_type pos, std::string::size_type count, const std::string & s) { return Splice(s.c_str(), pos, count); }
1899  __inline std::string substr(std::string::size_type pos = 0, std::string::size_type count = std::string::npos) const { return std::string(Mid(pos, count).GetPointer()); }
1900  __inline std::string::size_type find(char c, std::string::size_type pos = 0) const { return StdStringPos(Find(c, pos)); }
1901  __inline std::string::size_type find(const char * s, std::string::size_type pos = 0) const { return StdStringPos(Find(s, pos)); }
1902  __inline std::string::size_type find(const std::string & s, std::string::size_type pos = 0) const { return StdStringPos(Find(s.c_str(), pos)); }
1903  __inline std::string::size_type rfind(char c, std::string::size_type pos = 0) const { return StdStringPos(FindLast(c, pos)); }
1904  __inline std::string::size_type rfind(const char * s, std::string::size_type pos = 0) const { return StdStringPos(FindLast(s, pos)); }
1905  __inline std::string::size_type rfind(const std::string & s, std::string::size_type pos = 0) const { return StdStringPos(FindLast(s.c_str(), pos)); }
1906  __inline std::string::size_type find_first_of(const char * s, std::string::size_type pos = 0) const { return StdStringPos(FindOneOf(s, pos)); }
1907  __inline std::string::size_type find_first_of(const std::string & s, std::string::size_type pos = 0) const { return StdStringPos(FindOneOf(s.c_str(), pos)); }
1908  __inline std::string::size_type find_first_not_of(const char * s, std::string::size_type pos = 0) const { return StdStringPos(FindSpan(s, pos)); }
1909  __inline std::string::size_type find_first_not_of(const std::string & s, std::string::size_type pos = 0) const { return StdStringPos(FindSpan(s.c_str(), pos)); }
1910  private:
1911  __inline static std::string::size_type StdStringPos(PINDEX p) { return p != P_MAX_INDEX ? (std::string::size_type)p : std::string::npos; }
1912  public:
1914 
1915  protected:
1916 #ifdef P_HAS_WCHAR
1917  void InternalFromWChar(
1918  const wchar_t * ptr,
1919  PINDEX len
1920  );
1921 #endif
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  virtual int internal_strcmp(const char * s1, const char *s2) const;
1928  virtual int internal_strncmp(const char * s1, const char *s2, size_t n) const;
1929 
1930  bool InternalSplit(
1931  const PString & delimiter, // Delimiter around which tom plit the substrings
1932  PString & before, // Substring before delimiter
1933  PString & after, // Substring after delimiter
1934  SplitOptions_Bits options // options
1935  ) const;
1936 
1937  /* Internal function to compare the current string value against the
1938  specified C string.
1939 
1940  @return
1941  relative rank of the two strings.
1942  */
1943  PString(int dummy, const PString * str);
1944 
1945  virtual void AssignContents(const PContainer &);
1946  PString(PContainerReference & reference_, PINDEX len)
1947  : PCharArray(reference_)
1948  , m_length(len)
1949  { }
1950 
1951  protected:
1952  mutable PINDEX m_length; // Length of the string, always at least one less than GetSize()
1953 };
1954 
1955 
1956 inline ostream & operator<<(ostream & stream, const PString & string)
1957 {
1958  string.PrintOn(stream);
1959  return stream;
1960 }
1961 
1962 #ifdef P_HAS_WOSTREAM
1963 inline wostream & operator<<(wostream & stream, const PString & string)
1964 {
1965  return stream << (const char *)string;
1966 }
1967 #endif
1968 
1969 
1970 #ifdef _WIN32
1971  class PWideString : public PWCharArray {
1972  PCLASSINFO(PWideString, PWCharArray);
1973 
1974  public:
1975  typedef const wchar_t * Initialiser;
1976 
1977  PWideString() { }
1978  PWideString(const PWCharArray & arr) : PWCharArray(arr) { }
1979  PWideString(const PString & str) : PWCharArray(str.AsWide()) { }
1980  PWideString(const char * str);
1981  PWideString & operator=(const PWideString & str) { PWCharArray::operator=(str); return *this; }
1982  PWideString & operator=(const PString & str) { PWCharArray::operator=(str.AsWide()); return *this; }
1983  PWideString & operator=(const std::string & str);
1984  PWideString & operator=(const char * str);
1985  friend inline ostream & operator<<(ostream & stream, const PWideString & string) { return stream << PString(string); }
1986 
1987  PINDEX GetLength() const { return GetSize() - 1; }
1988 
1989  protected:
1990  PWideString(PContainerReference & reference_) : PWCharArray(reference_) { }
1991  };
1992 
1993  #ifdef UNICODE
1994  typedef PWideString PVarString;
1995  #else
1996  typedef PString PVarString;
1997  #endif
1998 #endif
1999 
2000 
2002 
2012 class PCaselessString : public PString
2013 {
2014  PCLASSINFO(PCaselessString, PString);
2015 
2016  public:
2019  PCaselessString();
2020 
2025  const char * cstr
2026  );
2027 
2033  const PString & str
2034  );
2035 
2036 
2040  const std::string & str
2041  ) : PString(str)
2042  { }
2043 
2052  const PString & str
2053  );
2054 
2063  const std::string & str
2064  ) { return operator=(str.c_str()); }
2065 
2076  const char * cstr
2077  );
2078 
2088  char ch
2089  );
2090 
2091 
2092  // Overrides from class PObject
2097  virtual PObject * Clone() const;
2098 
2099  protected:
2100  // Overrides from class PString
2101  virtual int internal_strcmp(const char * s1, const char *s2) const;
2102  virtual int internal_strncmp(const char * s1, const char *s2, size_t n) const;
2103 
2104  /* Internal function to compare the current string value against the
2105  specified C string.
2106 
2107  @return
2108  relative rank of the two strings or characters.
2109  */
2110 
2111  PCaselessString(int dummy, const PCaselessString * str);
2112  PCaselessString(PContainerReference & reference_, PINDEX len) : PString(reference_, len) { }
2113 };
2114 
2115 
2117 
2131 template <class ParentString>
2132 class PConstantString : public ParentString
2133 {
2134  private:
2135  PContainerReference m_staticReference;
2136  public:
2137  PConstantString(typename ParentString::Initialiser init)
2138  : ParentString(m_staticReference, init != NULL ? strlen(init) : 0)
2139  , P_DISABLE_MSVC_WARNINGS(4267 4355, m_staticReference(this->m_length+1, true))
2140  {
2141  this->theArray = (char *)(init != NULL ? init : "");
2142  }
2143 
2145  : ParentString(m_staticReference, other.m_length)
2146  , m_staticReference(other.m_length + 1, true)
2147  {
2148  this->theArray = other.theArray;
2149  }
2150 
2152  {
2153  this->Destruct();
2154  }
2155 
2156  virtual PBoolean SetSize(PINDEX s) { return s <= this->m_length+1; }
2158  virtual void DestroyReference() { this->reference = NULL; }
2159 
2160  private:
2161  void operator=(const PConstantString &) { }
2162 };
2163 
2164 
2167 
2170 
2171 
2172 #ifdef _WIN32
2173 // Now have PConstString can have these definitions
2174 __inline PWideString::PWideString(const char * str) : PWCharArray(PConstString(str).AsWide()) { }
2175 __inline PWideString & PWideString::operator=(const std::string & str) { PWCharArray::operator=(PConstString(str.c_str()).AsWide()); return *this; }
2176 __inline PWideString & PWideString::operator=(const char * str) { PWCharArray::operator=(PConstString(str).AsWide()); return *this; }
2177 #endif
2178 
2179 
2181 
2188 class PStringStream : public PString, public std::iostream
2189 {
2190  PCLASSINFO(PStringStream, PString);
2191 
2192  public:
2198  PStringStream();
2199 
2204  PStringStream(
2205  PINDEX fixedBufferSize
2206  );
2207 
2214  PStringStream(
2215  const PString & str
2216  );
2217 
2222  PStringStream(
2223  const char * cstr
2224  );
2225 
2227  virtual ~PStringStream();
2228 
2231  virtual PString & MakeEmpty();
2232 
2245  const PStringStream & strm
2246  );
2247 
2260  const PString & str
2261  );
2262 
2279  const char * cstr
2280  );
2281 
2291  char ch
2292  );
2293 
2294  // Miscellanous fix ups
2295  __inline void clear() { std::iostream::clear(); }
2296  virtual PINDEX GetLength() const;
2297 
2298 
2299  protected:
2300  virtual void AssignContents(const PContainer & cont);
2301 
2302  private:
2303  PStringStream(int, const PStringStream &)
2304  : std::iostream(cout.rdbuf())
2305  {
2306  }
2307 
2308  class Buffer : public streambuf {
2309  public:
2310  Buffer(PStringStream & str, PINDEX size);
2311  Buffer(const Buffer & sbuf);
2312  Buffer & operator=(const Buffer & sbuf);
2313  virtual int_type overflow(int_type = EOF);
2314  virtual int_type underflow();
2315  virtual int sync();
2316  virtual pos_type seekoff(std::streamoff, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
2317  virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
2318  PCharArray & string;
2319  PBoolean fixedBufferSize;
2320  };
2321 };
2322 
2323 
2324 __inline PString PSTRSTRM_support(const ostream & s) { return dynamic_cast<const PString &>(s); }
2325 
2337 #define PSTRSTRM(arg) PSTRSTRM_support(PStringStream() << std::flush << arg << std::flush)
2338 
2339 
2340 // Definition for template PString memeber function, needs to be after PStringStream
2341 template <typename T> __inline T PString::As(T t) const
2342 {
2343  PStringStream strm(*this);
2344  strm >> t;
2345  return t;
2346 }
2347 
2348 
2349 class PStringList;
2350 class PSortedStringList;
2351 class PStringSet;
2352 
2365 class PStringArray : public PArray<PString>
2366 {
2367  typedef PArray<PString> BaseClass;
2368  PCLASSINFO(PStringArray, BaseClass);
2369 
2370  protected:
2371  inline PStringArray(int dummy, const PStringArray * c)
2372  : BaseClass(dummy, c)
2373  {
2374  }
2375 
2376  public:
2379  __inline PStringArray(PINDEX initialSize = 0)
2381  : BaseClass(initialSize) { }
2382 
2383  __inline PStringArray(const BaseClass & other)
2384  : BaseClass(other) { }
2385 
2390  PStringArray(
2391  PINDEX count,
2392  char const * const * strarr,
2393  PBoolean caseless = false
2394  );
2397  PStringArray(
2398  const PString & str
2399  );
2402  PStringArray(
2403  const char * cstr
2404  );
2407  PStringArray(
2408  const PStringList & list
2409  );
2412  PStringArray(
2413  const PSortedStringList & list
2414  );
2417  PStringArray(
2418  const PStringSet & set
2419  );
2420 
2425  const std::vector<PString> & vec
2426  )
2427  {
2428  for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
2429  AppendString(*r);
2430  }
2431 
2436  const std::vector<std::string> & vec
2437  )
2438  {
2439  for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
2440  AppendString(PString(*r));
2441  }
2442 
2446  template <typename stlContainer>
2448  const stlContainer & vec
2449  )
2450  {
2451  PStringArray list;
2452  for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
2453  list.AppendString(PString(*r));
2454  return list;
2455  }
2456 
2458 
2467  virtual void ReadFrom(
2468  istream &strm // Stream to read the objects contents from.
2469  );
2470 
2471  virtual PObject * Clone() const
2472  {
2473  return new PStringArray(0, this);
2474  }
2476 
2485  PINDEX GetStringsIndex(
2486  const PString & str
2487  ) const;
2488 
2490  PINDEX index
2491  ) const;
2492 
2500  PString & operator[](
2501  PINDEX index
2502  );
2503 
2506  PINDEX AppendString(
2507  const PString & str
2508  );
2509  void push_back(const PString & str) { AppendString(str); }
2510 
2516  PStringArray & operator +=(const PStringArray & array);
2517  PStringArray & operator +=(const PString & str) { AppendString(str); return *this; }
2518  PStringArray & operator +=(const char * cstr) { AppendString(cstr); return *this; }
2519 
2520 
2527  PStringArray operator + (const PStringArray & array);
2528  PStringArray operator + (const PString & str);
2529 
2537  char ** ToCharArray(
2538  PCharArray * storage = NULL
2539  ) const;
2540 
2543  PString ToString(
2544  char separator = ' '
2545  ) const;
2547 };
2548 
2549 
2562 class PStringList : public PList<PString>
2563 {
2564  typedef PList<PString> BaseClass;
2565  PCLASSINFO(PStringList, BaseClass);
2566 
2567  protected:
2568  PStringList(int dummy, const PStringList * c)
2569  : BaseClass(dummy, c) { }
2570 
2571  public:
2576  __inline PStringList()
2577  : BaseClass() { }
2578 
2579  __inline PStringList(const BaseClass & other)
2580  : BaseClass(other) { }
2581 
2584  PStringList(
2585  PINDEX count,
2586  char const * const * strarr,
2587  PBoolean caseless = false
2588  );
2591  PStringList(
2592  const PString & str
2593  );
2596  PStringList(
2597  const char * cstr
2598  );
2601  PStringList(
2602  const PStringArray & array
2603  );
2606  PStringList(
2607  const PSortedStringList & list
2608  );
2611  PStringList(
2612  const PStringSet & set
2613  );
2615 
2624  virtual void ReadFrom(
2625  istream &strm // Stream to read the objects contents from.
2626  );
2627 
2628  virtual PObject * Clone() const
2629  {
2630  return new PStringList(0, this);
2631  }
2633 
2638  PINDEX AppendString(
2639  const PString & str
2640  );
2641 
2644  PINDEX InsertString(
2645  const PString & before,
2646  const PString & str
2647  );
2648 
2652  PINDEX GetStringsIndex(
2653  const PString & str
2654  ) const;
2655 
2661  PStringList & operator +=(const PStringList & list);
2662  PStringList & operator +=(const PString & str) { AppendString(str); return *this; }
2663  PStringList & operator +=(const char * cstr) { AppendString(cstr); return *this; }
2664 
2665 
2672  PStringList operator + (const PStringList & array);
2673  PStringList operator + (const PString & str);
2674 
2678  template <typename stlContainer>
2680  const stlContainer & vec
2681  )
2682  {
2683  PStringList list;
2684  for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
2685  list.AppendString(PString(*r));
2686  return list;
2687  }
2689 };
2690 
2691 
2703 class PSortedStringList : public PSortedList<PString>
2704 {
2706  PCLASSINFO(PSortedStringList, BaseClass);
2707 
2708  protected:
2709  PSortedStringList(int dummy, const PSortedStringList * c)
2710  : BaseClass(dummy, c) { }
2711 
2712  public:
2718  : BaseClass() { }
2719 
2720  __inline PSortedStringList(const BaseClass & other)
2721  : BaseClass(other) { }
2722 
2726  PINDEX count,
2727  char const * const * strarr,
2728  PBoolean caseless = false
2729  );
2733  const PString & str
2734  );
2738  const char * cstr
2739  );
2743  const PStringArray & array
2744  );
2748  const PStringList & list
2749  );
2753  const PStringSet & set
2754  );
2756 
2765  virtual void ReadFrom(
2766  istream &strm // Stream to read the objects contents from.
2767  );
2769 
2775  PINDEX AppendString(
2776  const PString & str
2777  );
2778 
2782  PINDEX GetStringsIndex(
2783  const PString & str
2784  ) const;
2785 
2790  PINDEX GetNextStringsIndex(
2791  const PString & str
2792  ) const;
2794 
2795  protected:
2796  PINDEX InternalStringSelect(
2797  const char * str,
2798  PINDEX len,
2799  PSortedListElement * thisElement,
2800  PSortedListElement * & lastElement
2801  ) const;
2802 };
2803 
2804 
2821 class PStringSet : public PSet<PString>
2822 {
2823  typedef PSet<PString> BaseClass;
2824  PCLASSINFO(PStringSet, BaseClass);
2825 
2826  protected:
2827  PStringSet(int dummy, const PStringSet * c)
2828  : BaseClass(dummy, c) { }
2829 
2830  public:
2835  PStringSet(PBoolean initialDeleteObjects = true)
2836  : BaseClass(initialDeleteObjects) { }
2837 
2838  PStringSet(const BaseClass & other)
2839  : BaseClass(other) { }
2840 
2843  PStringSet(
2844  PINDEX count,
2845  char const * const * strarr,
2846  PBoolean caseless = false
2847  );
2848 
2851  PStringSet(
2852  const PString & str
2853  );
2856  PStringSet(
2857  const char * cstr
2858  );
2861  PStringSet(
2862  const PStringArray & strArray
2863  );
2866  PStringSet(
2867  const PStringList & strList
2868  );
2870 
2879  virtual void ReadFrom(
2880  istream &strm
2881  );
2882 
2883  virtual PObject * Clone() const
2884  {
2885  return PNEW PStringSet(0, this);
2886  }
2888 
2892  void Include(
2893  const PString & key
2894  );
2897  const PString & key
2898  );
2900  void Exclude(
2901  const PString & key
2902  );
2905  const PString & key
2906  );
2908 };
2909 
2910 
2918 template <class K> class PStringDictionary : public PDictionary<K, PString>
2919 {
2921  PCLASSINFO(PStringDictionary, BaseClass);
2922 
2923  public:
2933  : BaseClass() { }
2935 
2942  virtual PObject * Clone() const
2943  { return PNEW PStringDictionary(0, this); }
2945 
2961  PString operator()(const K & key, const char * dflt = NULL) const
2962  {
2963  PString * str = this->GetAt(key);
2964  return str != NULL ? *str : PString(dflt);
2965  }
2966 
2978  virtual PBoolean SetAt(
2979  const K & key, // Key for position in dictionary to add object.
2980  const PString & str // New string value to put into the dictionary.
2981  ) { return this->AbstractSetAt(key, PNEW PString(str)) != NULL; }
2983 
2984  protected:
2985  PStringDictionary(int dummy, const PStringDictionary * c)
2986  : BaseClass(dummy, c) { }
2987 };
2988 
2989 
3004 #define PDECLARE_STRING_DICTIONARY(cls, K) \
3005  PDECLARE_CLASS(cls, PStringDictionary<K>) \
3006  protected: \
3007  cls(int dummy, const cls * c) \
3008  : PStringDictionary<K>(dummy, c) { } \
3009  public: \
3010  cls() \
3011  : PStringDictionary<K>() { } \
3012  virtual PObject * Clone() const \
3013  { return PNEW cls(0, this); } \
3014 
3015 
3028 #define PSTRING_DICTIONARY(cls, K) typedef PStringDictionary<K> cls
3029 
3030 
3045 #ifdef DOC_PLUS_PLUS
3047 #endif
3048 PDECLARE_STRING_DICTIONARY(POrdinalToString, POrdinalKey);
3049  public:
3052  struct Initialiser {
3055  PINDEX key;
3057  const char * value;
3058  };
3062  PINDEX count,
3063  const Initialiser * init
3064  );
3066 
3075  virtual void ReadFrom(
3076  istream &strm // Stream to read the objects contents from.
3077  );
3079 };
3080 
3092 #ifdef DOC_PLUS_PLUS
3094 #endif
3095 PDECLARE_ORDINAL_DICTIONARY(PStringToOrdinal, PString);
3096  public:
3099  struct Initialiser {
3102  const char * key;
3104  PINDEX value;
3105  };
3109  PINDEX count,
3110  const Initialiser * init,
3111  PBoolean caseless = false
3112  );
3116  PINDEX count,
3117  const POrdinalToString::Initialiser * init,
3118  PBoolean caseless = false
3119  );
3121 
3130  virtual void ReadFrom(
3131  istream &strm // Stream to read the objects contents from.
3132  );
3134 };
3135 
3136 
3150 #ifdef DOC_PLUS_PLUS
3152 #endif
3153 PDECLARE_STRING_DICTIONARY(PStringToString, PString);
3154  public:
3157  struct Initialiser {
3160  const char * key;
3162  const char * value;
3163  };
3167  PINDEX count,
3168  const Initialiser * init,
3169  PBoolean caselessKeys = false,
3170  PBoolean caselessValues = false
3171  );
3172 
3177  const PString & str
3178  ) { FromString(str); }
3180 
3192  virtual void ReadFrom(
3193  istream &strm // Stream to read the objects contents from.
3194  );
3196 
3199  enum MergeAction
3201  {
3205  };
3209  void Merge(
3210  const PStringToString & merge,
3211  MergeAction action
3212  );
3213 
3226  char ** ToCharArray(
3227  bool withEqualSign,
3228  PCharArray * storage = NULL
3229  ) const;
3230 
3236  void FromString(
3237  const PString & str
3238  );
3240 };
3241 
3242 
3250 {
3251  public:
3253  explicit PStringOptions(const PString & str) : PStringToString(str) { }
3254  PStringOptions(const PStringToString & other) : PStringToString(other) { }
3255  PStringOptions & operator=(const PStringToString & other) { PStringToString::operator=(other); return *this; }
3256 
3258  bool Contains(const char * key ) const { PConstCaselessString k(key); return PStringToString::Contains(k); }
3259  bool Contains(const std::string & key ) const { return PStringToString::Contains(PCaselessString(key)); }
3260  bool Contains(const PString & key ) const { return PStringToString::Contains(PCaselessString(key)); }
3261  bool Contains(const PCaselessString & key ) const { return PStringToString::Contains(key); }
3262  bool Contains(const PCaselessString & (*key)()) const { return PStringToString::Contains(key()); }
3263 
3264  // Overide default PStringToString::SetAt() to make sure the key is caseless
3265  PString * GetAt(const char * key ) const { PConstCaselessString k(key); return PStringToString::GetAt(k); }
3266  PString * GetAt(const std::string & key ) const { return PStringToString::GetAt(PCaselessString(key)); }
3267  PString * GetAt(const PString & key ) const { return PStringToString::GetAt(PCaselessString(key)); }
3268  PString * GetAt(const PCaselessString & key ) const { return PStringToString::GetAt(key); }
3269  PString * GetAt(const PCaselessString & (*key)()) const { return PStringToString::GetAt(key()); }
3270 
3271  // Overide default PStringToString::SetAt() to make sure the key is caseless
3272  PBoolean SetAt(const char * key, const PString & data) { PConstCaselessString k(key); return SetAt(k, data); }
3273  PBoolean SetAt(const std::string & key, const PString & data) { return SetAt(PCaselessString(key), data); }
3274  PBoolean SetAt(const PString & key, const PString & data) { return SetAt(PCaselessString(key), data); }
3275  PBoolean SetAt(const PCaselessString & key, const PString & data) { MakeUnique(); return PStringToString::SetAt(key, data); }
3276  PBoolean SetAt(const PCaselessString & (*key)(), const PString & data) { return SetAt(key(), data); }
3277 
3278  // Overide default PStringToString::RemoveAt() to make sure the key is caseless
3279  PString * RemoveAt(const char * key) { PConstCaselessString k(key); return RemoveAt(k); }
3280  PString * RemoveAt(const std::string & key) { return RemoveAt(PCaselessString(key)); }
3281  PString * RemoveAt(const PString & key) { return RemoveAt(PCaselessString(key)); }
3283  PString * RemoveAt(const PCaselessString & (*key)()) { return RemoveAt(key()); }
3284 
3286  PString GetString(const char * key, const char * dflt = NULL) const { PConstCaselessString k(key); return GetString(k, dflt); }
3287  PString GetString(const std::string & key, const char * dflt = NULL) const { return GetString(PCaselessString(key), dflt); }
3288  PString GetString(const PString & key, const char * dflt = NULL) const { return GetString(PCaselessString(key), dflt); }
3289  PString GetString(const PCaselessString & key, const char * dflt = NULL) const;
3290  PString GetString(const PCaselessString & (*key)(), const char * dflt = NULL) const { return GetString(key(), dflt); }
3291 
3293  bool SetString(const char * key, const PString & value) { return SetAt(key, value); }
3294  bool SetString(const std::string & key, const PString & value) { return SetAt(key, value); }
3295  bool SetString(const PString & key, const PString & value) { return SetAt(key, value); }
3296  bool SetString(const PCaselessString & key, const PString & value) { return SetAt(key, value); }
3297  bool SetString(const PCaselessString & (*key)(), const PString & value) { return SetAt(key, value); }
3298 
3300  bool GetBoolean(const char * key, bool dflt = false) const { PConstCaselessString k(key); return GetBoolean(k, dflt); }
3301  bool GetBoolean(const std::string & key, bool dflt = false) const { return GetBoolean(PCaselessString(key), dflt); }
3302  bool GetBoolean(const PString & key, bool dflt = false) const { return GetBoolean(PCaselessString(key), dflt); }
3303  bool GetBoolean(const PCaselessString & key, bool dflt = false) const;
3304  bool GetBoolean(const PCaselessString & (*key)(), bool dflt = false) const { return GetBoolean(key(), dflt); }
3305 
3307  void SetBoolean(const char * key, bool value) { PConstCaselessString k(key); SetBoolean(k, value); }
3308  void SetBoolean(const std::string & key, bool value) { SetBoolean(PCaselessString(key), value); }
3309  void SetBoolean(const PString & key, bool value) { SetBoolean(PCaselessString(key), value); }
3310  void SetBoolean(const PCaselessString & key, bool value) { SetAt(key, value ? "true" : "false"); }
3311  void SetBoolean(const PCaselessString & (*key)(), bool value) { SetBoolean(key(), value); }
3312 
3314  long GetInteger(const char * key, long dflt = 0) const { PConstCaselessString k(key); return GetInteger(k, dflt); }
3315  long GetInteger(const std::string & key, long dflt = 0) const { return GetInteger(PCaselessString(key), dflt); }
3316  long GetInteger(const PString & key, long dflt = 0) const { return GetInteger(PCaselessString(key), dflt); }
3317  long GetInteger(const PCaselessString & key, long dflt = 0) const;
3318  long GetInteger(const PCaselessString & (*key)(), long dflt = 0) const { return GetInteger(key(), dflt); }
3319 
3321  void SetInteger(const char * key, long value) { PConstCaselessString k(key); SetInteger(k, value); }
3322  void SetInteger(const std::string & key, long value) { SetInteger(PCaselessString(key), value); }
3323  void SetInteger(const PString & key, long value) { SetInteger(PCaselessString(key), value); }
3324  void SetInteger(const PCaselessString & key, long value);
3325  void SetInteger(const PCaselessString & (*key)(), long value) { SetInteger(key(), value); }
3326 
3328  template<typename E> E GetEnum(const char * key, E dflt) const { PConstCaselessString k(key); return GetEnum(k, dflt); }
3329  template<typename E> E GetEnum(const std::string & key, E dflt) const { return GetEnum(PCaselessString(key), dflt); }
3330  template<typename E> E GetEnum(const PString & key, E dflt) const { return GetEnum(PCaselessString(key), dflt); }
3331  template<typename E> E GetEnum(const PCaselessString & key, E dflt) const { return (E)GetInteger(key, dflt); }
3332  template<typename E> E GetEnum(const PCaselessString & (*key)(), E dflt) const { return GetEnum(key(), dflt); }
3333 
3335  template<typename E> void SetEnum(const char * key, E value) { PConstCaselessString k(key); SetInteger(k, value); }
3336  template<typename E> void SetEnum(const std::string & key, E value) { SetInteger(PCaselessString(key), value); }
3337  template<typename E> void SetEnum(const PString & key, E value) { SetInteger(PCaselessString(key), value); }
3338  template<typename E> void SetEnum(const PCaselessString & key, E value) { SetInteger(key, value); }
3339  template<typename E> void SetEnum(const PCaselessString & (*key)(), E value) { SetInteger(key(), value); }
3340 
3342  double GetReal(const char * key, double dflt = 0) const { PConstCaselessString k(key); return GetReal(k, dflt); }
3343  double GetReal(const std::string & key, double dflt = 0) const { return GetReal(PCaselessString(key), dflt); }
3344  double GetReal(const PString & key, double dflt = 0) const { return GetReal(PCaselessString(key), dflt); }
3345  double GetReal(const PCaselessString & key, double dflt = 0) const;
3346  double GetReal(const PCaselessString & (*key)(), double dflt = 0) const { return GetReal(key(), dflt); }
3347 
3349  void SetReal(const char * key, double value, int decimals) { PConstCaselessString k(key); SetReal(k, value, decimals); }
3350  void SetReal(const std::string & key, double value, int decimals) { SetReal(PCaselessString(key), value, decimals); }
3351  void SetReal(const PString & key, double value, int decimals) { SetReal(PCaselessString(key), value, decimals); }
3352  void SetReal(const PCaselessString & key, double value, int decimals);
3353  void SetReal(const PCaselessString & (*key)(), double value, int decimals) { SetReal(key(), value, decimals); }
3354 
3356  template<typename T> T GetVar(const char * key, const T & dflt) const { PConstCaselessString k(key); return GetVar<T>(k, dflt); }
3357  template<typename T> T GetVar(const std::string & key, const T & dflt) const { return GetVar<T>(PCaselessString(key), dflt); }
3358  template<typename T> T GetVar(const PString & key, const T & dflt) const { return GetVar<T>(PCaselessString(key), dflt); }
3359  template<typename T> T GetVar(const PCaselessString & key, const T & dflt) const { PStringStream s(GetString(key)); T v; s>>v; return s.fail() || s.bad() ? dflt : v; }
3360  template<typename T> T GetVar(const PCaselessString & (*key)(), const T & dflt) const { return GetVar<T>(key(), dflt); }
3361 
3362  template<typename T> bool SetVar(const char * key, const T & value) { PConstCaselessString k(key); return SetVar<T>(k, value); }
3363  template<typename T> bool SetVar(const std::string & key, const T & value) { return SetVar<T>(PCaselessString(key), value); }
3364  template<typename T> bool SetVar(const PString & key, const T & value) { return SetVar<T>(PCaselessString(key), value); }
3365  template<typename T> bool SetVar(const PCaselessString & key, const T & value) { return SetString(key, PSTRSTRM(value)); }
3366  template<typename T> bool SetVar(const PCaselessString & (*key)(), const T & value) { return SetVar<T>(key(), value); }
3367 
3369  __inline bool Has(const char * key) const { return Contains(key); }
3370  __inline bool Has(const std::string & key) const { return Contains(key); }
3371  __inline bool Has(const PString & key) const { return Contains(key); }
3372  __inline bool Has(const PCaselessString & key) const { return Contains(key); }
3373  __inline bool Has(const PCaselessString & (*key)()) const { return Contains(key); }
3374 
3376  __inline PString Get(const char * key, const char * dflt = NULL) const { return GetString(key, dflt); }
3377  __inline PString Get(const PString & key, const char * dflt = NULL) const { return GetString(key, dflt); }
3378  __inline PString Get(const std::string & key, const char * dflt = NULL) const { return GetString(key, dflt); }
3379  __inline PString Get(const PCaselessString & key, const char * dflt = NULL) const { return GetString(key, dflt); }
3380  __inline PString Get(const PCaselessString & (*key)(), const char * dflt = NULL) const { return GetString(key, dflt); }
3381  __inline PString Get(const char * key, const std::string & dflt) const { return GetString(key, dflt.c_str()); }
3382  __inline PString Get(const std::string & key, const std::string & dflt) const { return GetString(key, dflt.c_str()); }
3383  __inline PString Get(const PString & key, const std::string & dflt) const { return GetString(key, dflt.c_str()); }
3384  __inline PString Get(const PCaselessString & key, const std::string & dflt) const { return GetString(key, dflt.c_str()); }
3385  __inline PString Get(const PCaselessString & (*key)(), const std::string & dflt) const { return GetString(key, dflt.c_str()); }
3386  __inline PString Get(const char * key, const PString & dflt) const { return GetString(key, dflt); }
3387  __inline PString Get(const std::string & key, const PString & dflt) const { return GetString(key, dflt); }
3388  __inline PString Get(const PString & key, const PString & dflt) const { return GetString(key, dflt); }
3389  __inline PString Get(const PCaselessString & key, const PString & dflt) const { return GetString(key, dflt); }
3390  __inline PString Get(const PCaselessString & (*key)(), const PString & dflt) const { return GetString(key, dflt); }
3391 
3393  __inline bool Set(const char * key, const PString & value) { return SetAt(key, value); }
3394  __inline bool Set(const std::string & key, const PString & value) { return SetAt(key, value); }
3395  __inline bool Set(const PString & key, const PString & value) { return SetAt(key, value); }
3396  __inline bool Set(const PCaselessString & key, const PString & value) { return SetAt(key, value); }
3397  __inline bool Set(const PCaselessString & (*key)(), const PString & value) { return SetAt(key, value); }
3398 
3400  __inline void Remove(const char * key) { RemoveAt(key); }
3401  __inline void Remove(const std::string & key) { RemoveAt(key); }
3402  __inline void Remove(const PString & key) { RemoveAt(key); }
3403  __inline void Remove(const PCaselessString & key) { RemoveAt(key); }
3404  __inline void Remove(const PCaselessString & (*key)()) { RemoveAt(key); }
3405 };
3406 
3407 
3414 {
3415  PCLASSINFO(PRegularExpression, PObject);
3416  public:
3421  CompileOptions, 3,
3422  (
3423  Simple,
3424  Extended,
3425  IgnoreCase,
3426  AnchorNewLine
3429  )
3430  );
3431 
3434  ExecOptions, 2,
3435  (
3436  Normal,
3437  NotBeginningOfLine,
3442  NotEndofLine
3444  )
3445  );
3446 
3449 
3453  const PString & pattern,
3454  CompileOptions options = IgnoreCase
3455  );
3456 
3460  const char * cpattern,
3461  CompileOptions options = IgnoreCase
3462  );
3463 
3468  const PRegularExpression &
3469  );
3470 
3475  const PRegularExpression &
3476  );
3477 
3481 
3482 
3487  virtual void PrintOn(
3488  ostream & strm
3489  ) const;
3491 
3494  enum ErrorCodes {
3497  NoError = 0,
3500 
3501  // POSIX regcomp return error codes. (In the order listed in the standard.)
3526 
3527  /* Error codes we've added. */
3536  };
3537 
3543  ErrorCodes GetErrorCode() const;
3544 
3551  PString GetErrorText() const;
3552 
3554  const PString & GetPattern() const { return m_pattern; }
3556 
3560  bool Compile(
3561  const PString & pattern,
3562  CompileOptions options = IgnoreCase
3563  );
3571  bool Compile(
3572  const char * cpattern,
3573  CompileOptions options = IgnoreCase
3574  );
3575 
3576 
3578  bool Execute(
3579  const PString & str,
3580  PINDEX & start,
3581  ExecOptions options = Normal
3582  ) const;
3584  bool Execute(
3585  const PString & str,
3586  PINDEX & start,
3587  PINDEX & len,
3588  ExecOptions options = Normal
3589  ) const;
3591  bool Execute(
3592  const char * cstr,
3593  PINDEX & start,
3594  ExecOptions options = Normal
3595  ) const;
3597  bool Execute(
3598  const char * cstr,
3599  PINDEX & start,
3600  PINDEX & len,
3601  ExecOptions options = Normal
3602  ) const;
3604  bool Execute(
3605  const PString & str,
3606  PIntArray & starts,
3607  ExecOptions options = Normal
3608  ) const;
3610  bool Execute(
3611  const PString & str,
3612  PIntArray & starts,
3613  PIntArray & ends,
3614  ExecOptions options = Normal
3615  ) const;
3617  bool Execute(
3618  const char * cstr,
3619  PIntArray & starts,
3620  ExecOptions options = Normal
3621  ) const;
3638  bool Execute(
3639  const char * cstr,
3640  PIntArray & starts,
3641  PIntArray & ends,
3642  ExecOptions options = Normal
3643  ) const;
3660  bool Execute(
3661  const char * cstr,
3662  PStringArray & substring,
3663  ExecOptions options = Normal
3664  ) const;
3666 
3675  static PString EscapeString(
3676  const PString & str
3677  );
3679 
3680  protected:
3681  bool InternalCompile(bool assertOnFail);
3682  void InternalClean();
3683 
3685  CompileOptions m_compileOptions;
3687 };
3688 
3689 
3690 #endif // PTLIB_STRING_H
3691 
3692 
3693 // End Of File ///////////////////////////////////////////////////////////////
const char * value
String value for ordinal.
Definition: pstring.h:3057
__inline std::string::size_type find_first_of(const char *s, std::string::size_type pos=0) const
Definition: pstring.h:1906
__inline PString & append(std::string::size_type count, char ch)
Definition: pstring.h:1890
void SetReal(const std::string &key, double value, int decimals)
Definition: pstring.h:3350
__inline std::ostream & operator<<(std::ostream &strm, const PHashTableList &hash)
Definition: dict.h:180
void SetReal(const PString &key, double value, int decimals)
Definition: pstring.h:3351
bool Compile(const PString &pattern, CompileOptions options=IgnoreCase)
Compiler pattern.
T GetVar(const PCaselessString &key, const T &dflt) const
Definition: pstring.h:3359
PString * GetAt(const PCaselessString &key) const
Definition: pstring.h:3268
void SetEnum(const PCaselessString &key, E value)
Definition: pstring.h:3338
PString * RemoveAt(const PString &key)
Definition: pstring.h:3281
char ** ToCharArray(bool withEqualSign, PCharArray *storage=NULL) const
Create an array of C strings.
#define P_DISABLE_MSVC_WARNINGS(warnings, statement)
Definition: object.h:156
__inline std::string::size_type find(char c, std::string::size_type pos=0) const
Definition: pstring.h:1900
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:3400
__inline char * data()
Definition: pstring.h:1888
PString ToString(char separator= ' ') const
Create a PString concatenation of all array memebers.
E GetEnum(const std::string &key, E dflt) const
Definition: pstring.h:3329
virtual ~PStringStream()
Destroy the string stream, deleting the stream buffer.
void SetBoolean(const PCaselessString &(*key)(), bool value)
Definition: pstring.h:3311
bool Contains(const std::string &key) const
Definition: pstring.h:3259
PRegularExpression()
Create a new, empty, regular expression.
Trailing backslash.
Definition: pstring.h:3509
Not implemented.
Definition: pstring.h:3505
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:3300
PString & operator&=(const PString &str)
Concatenate a PString to a PString, modifiying that string.
PBoolean SetAt(const std::string &key, const PString &data)
Definition: pstring.h:3273
PString & operator=(const PString &str)
Assign the string to the current object.
E GetEnum(const PCaselessString &(*key)(), E dflt) const
Definition: pstring.h:3332
bool InternalCompile(bool assertOnFail)
PRegularExpression & operator=(const PRegularExpression &)
Assign a regular expression.
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:701
const PString & GetPattern() const
Return the string which represents the pattern matched by the regular expression. ...
Definition: pstring.h:3554
__inline std::string::size_type find(const std::string &s, std::string::size_type pos=0) const
Definition: pstring.h:1902
__inline std::string::size_type size() const
Definition: pstring.h:1882
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
Array of characters.
Definition: array.h:552
This template class maps the PAbstractDictionary to a specific key type and a PString data type...
Definition: pstring.h:2918
PINDEX value
Ordinal value for string.
Definition: pstring.h:3104
Invalid character class name.
Definition: pstring.h:3507
bool operator!=(const PString &str) const
Compare two strings using the PObject::Compare() function.
PCaselessString(PContainerReference &reference_, PINDEX len)
Definition: pstring.h:2112
__inline const char * c_str() const
Definition: pstring.h:1887
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
PINDEX AppendString(const PString &str)
Add a string to the list.
int64_t AsInteger64(unsigned base=0) const
Convert the string to an integer value using the specified number base.
PStringArray & operator+=(const PStringArray &array)
Concatenate a PString or PStringArray to the array.
PString & Delete(PINDEX start, PINDEX len)
Remove the substring from the string.
PBoolean SetAt(const PCaselessString &key, const PString &data)
Definition: pstring.h:3275
PStringOptions()
Definition: pstring.h:3252
This template class maps the PAbstractArray to a specific element type.
Definition: array.h:276
virtual PINDEX GetLength() const
Determine the length of the null terminated string.
E GetEnum(const char *key, E dflt) const
Get the option value as an enum.
Definition: pstring.h:3328
bool SetString(const std::string &key, const PString &value)
Definition: pstring.h:3294
__inline void Remove(const std::string &key)
Definition: pstring.h:3401
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:2679
Append to existing key value, separated by &#39; &#39;.
Definition: pstring.h:3204
__inline PStringList()
Create an empty PStringList.
Definition: pstring.h:2576
virtual void AssignContents(const PContainer &cont)
Copy the container contents.
__inline bool Set(const PCaselessString &key, const PString &value)
Definition: pstring.h:3396
__inline PString & insert(std::string::size_type index, const char *s)
Definition: pstring.h:1894
#define PAssertAlways(msg)
This macro is used to assert immediately.
Definition: object.h:437
__inline bool Has(const PString &key) const
Definition: pstring.h:3371
long GetInteger(const PCaselessString &(*key)(), long dflt=0) const
Definition: pstring.h:3318
PINDEX key
Ordinal key for string.
Definition: pstring.h:3055
PCaselessString()
Create a new, empty, caseless string.
This template class maps the PAbstractDictionary to a specific key and data types.
Definition: dict.h:978
double GetReal(const std::string &key, double dflt=0) const
Definition: pstring.h:3343
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.
__inline std::string::size_type capacity() const
Definition: pstring.h:1884
virtual PString & MakeEmpty()
Make the current string empty.
Structure for static array initialiser for class.
Definition: pstring.h:3100
PCaselessString & operator=(const PString &str)
Assign the string to the current object.
__inline PSortedStringList(const BaseClass &other)
Definition: pstring.h:2720
This class is a standard C++ stream class descendent for reading or writing streamed data to or from ...
Definition: pstring.h:2188
Definition: pstring.h:304
__inline std::string::size_type length() const
Definition: pstring.h:1883
ErrorCodes
Error codes.
Definition: pstring.h:3495
PINDEX GetStringsIndex(const PString &str) const
Get the index of the string with the specified value.
T GetVar(const PString &key, const T &dflt) const
Definition: pstring.h:3358
Data is C language style string with \ escape codes.
Definition: pstring.h:297
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:3151
virtual Comparison InternalCompare(PINDEX offset, PINDEX length, const char *cstr) const
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:3511
const char * key
String key for string.
Definition: pstring.h:3160
static PString EscapeString(const PString &str)
Escape all characters in the str parameter that have a special meaning within a regular expression...
Convert a real number to a string in decimal format.
Definition: pstring.h:300
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:2251
bool Contains(const PCaselessString &(*key)()) const
Definition: pstring.h:3262
Premature end.
Definition: pstring.h:3529
__inline void push_back(char ch)
Definition: pstring.h:1889
PString()
Construct an empty string.
bool operator<=(const PString &str) const
Compare two strings using the PObject::Compare() function.
virtual PObject * Clone() const
Make a complete duplicate of the array.
Definition: pstring.h:2471
__inline PString Get(const std::string &key, const PString &dflt) const
Definition: pstring.h:3387
__inline std::string::size_type rfind(const std::string &s, std::string::size_type pos=0) const
Definition: pstring.h:1905
This class is a variation of a string that ignores case.
Definition: pstring.h:2012
__inline T As(T t=T()) const
Convert the string to any type that can be converted using a stream.
Definition: pstring.h:2341
__inline bool Set(const PCaselessString &(*key)(), const PString &value)
Definition: pstring.h:3397
PConstantString(const PConstantString &other)
Definition: pstring.h:2144
PBYTEArray ToPascal() const
Convert a standard null terminated string to a &quot;pascal&quot; style string.
PString * GetAt(const PCaselessString &(*key)()) const
Definition: pstring.h:3269
virtual PObject * AbstractSetAt(const PObject &key, PObject *obj)
Add a new object to the collection.
__inline bool Split(char delimiter, PString &before, PString &after, SplitOptions_Bits options) const
Definition: pstring.h:1557
__inline PString & append(const std::string &s)
Definition: pstring.h:1892
void Include(const PString &key)
Include the spcified string value into the set.
E GetEnum(const PCaselessString &key, E dflt) const
Definition: pstring.h:3331
PStringOptions & operator=(const PStringToString &other)
Definition: pstring.h:3255
PBoolean SetAt(const PString &key, const PString &data)
Definition: pstring.h:3274
__inline std::string::size_type find_first_not_of(const char *s, std::string::size_type pos=0) const
Definition: pstring.h:1908
PString FromLiteral(PINDEX &offset) const
Parse a C literal string format as for PString::ToLiteral().
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:3276
void push_back(const PString &str)
Definition: pstring.h:2509
char ** ToCharArray(PCharArray *storage=NULL) const
Create an array of C strings.
double GetReal(const PCaselessString &(*key)(), double dflt=0) const
Definition: pstring.h:3346
PString operator[](PINDEX index) const
virtual void AssignContents(const PContainer &)
Copy the container contents.
PBoolean SetAt(const char *key, const PString &data)
Definition: pstring.h:3272
__inline PSortedStringList()
Create an empty PStringList.
Definition: pstring.h:2717
This is an array collection class of PString objects.
Definition: pstring.h:2365
~PRegularExpression()
Release storage for the compiled regular expression.
__inline void Remove(const PCaselessString &key)
Definition: pstring.h:3403
PConstantString< PString > PConstString
Constant PString type. See PConstantString.
Definition: pstring.h:2166
__inline bool Has(const PCaselessString &(*key)()) const
Definition: pstring.h:3373
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.
PStringSet(int dummy, const PStringSet *c)
Definition: pstring.h:2827
PString ToLiteral() const
Convert the string to C literal string format.
PString * RemoveAt(const char *key)
Definition: pstring.h:3279
bool GetBoolean(const PString &key, bool dflt=false) const
Definition: pstring.h:3302
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.
__inline PString & replace(std::string::size_type pos, std::string::size_type count, const char *s)
Definition: pstring.h:1897
Output scaled to SI units, e.g. k, M, G.
Definition: pstring.h:302
bool Contains(const PCaselessString &key) const
Definition: pstring.h:3261
Unmatched ) or \); not returned from regcomp.
Definition: pstring.h:3533
This template class maps the PAbstractList to a specific object type.
Definition: lists.h:322
__inline std::string::size_type find_first_of(const std::string &s, std::string::size_type pos=0) const
Definition: pstring.h:1907
virtual PBoolean IsEmpty() const
Determine if the string is empty.
__inline PString & append(const char *s)
Definition: pstring.h:1891
No preceding re for repetition op.
Definition: pstring.h:3525
bool SetVar(const PCaselessString &key, const T &value)
Definition: pstring.h:3365
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
__inline bool Split(const char *delimiter, PString &before, PString &after, SplitOptions options) const
Definition: pstring.h:1558
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.
T GetVar(const PCaselessString &(*key)(), const T &dflt) const
Definition: pstring.h:3360
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:3254
PString(PContainerReference &reference_, PINDEX len)
Definition: pstring.h:1946
virtual Comparison Compare(const PObject &obj) const
Get the relative rank of the two strings.
PString & Splice(const PString &str, PINDEX pos, PINDEX len=0)
Splice the string into the current string at the specified position.
virtual int internal_strncmp(const char *s1, const char *s2, size_t n) const
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:3379
#define PSTRSTRM(arg)
Output a stream expression to a string parameter.
Definition: pstring.h:2337
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:3260
PStringList & operator+=(const PStringList &list)
Concatenate a PString or PStringArray to the list.
void * m_compiledRegex
Definition: pstring.h:3686
This is a dictionary collection class of ordinals keyed by PString objects.
Definition: pstring.h:3093
Array of unsigned characters.
Definition: array.h:605
Success.
Definition: pstring.h:3497
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:3402
virtual PObject * Clone() const
Make a complete duplicate of the list.
Definition: pstring.h:2628
ConversionType
Definition: pstring.h:294
Specialised version of PStringToString to contain a dictionary of options/attributes.
Definition: pstring.h:3249
long GetInteger(const PString &key, long dflt=0) const
Definition: pstring.h:3316
char * GetPointerAndSetLength(PINDEX len)
Get a pointer to the buffer and set the length of the string.
bool SetVar(const char *key, const T &value)
Definition: pstring.h:3362
__inline bool empty() const
Definition: pstring.h:1885
__inline PString PSTRSTRM_support(const ostream &s)
Definition: pstring.h:2324
PStringToString(PINDEX count, const Initialiser *init, PBoolean caselessKeys=false, PBoolean caselessValues=false)
Initialise the string dictionary of strings from the static array.
__inline std::string::size_type rfind(char c, std::string::size_type pos=0) const
Definition: pstring.h:1903
This is a sorted list collection class of PString objects.
Definition: pstring.h:2703
PStringToOrdinal(PINDEX count, const Initialiser *init, PBoolean caseless=false)
Initialise the string dictionary of ordinals from the static array.
void SetBoolean(const char *key, bool value)
Set the option value as a boolean.
Definition: pstring.h:3307
Create a constant string.
Definition: pstring.h:2132
Convert a signed integer to a string.
Definition: pstring.h:298
PString * GetAt(const char *key) const
Definition: pstring.h:3265
MergeAction
Actions to take when doing a PStringToString::Merge()
Definition: pstring.h:3200
virtual PObject * Clone() const
Make a complete duplicate of the set.
Definition: pstring.h:2883
char * theArray
Pointer to the allocated block of memory.
Definition: array.h:247
Formatted output, sprintf() style function.
Definition: pstring.h:303
void SetInteger(const std::string &key, long value)
Definition: pstring.h:3322
__inline bool Set(const char *key, const PString &value)
Set the option value.
Definition: pstring.h:3393
const char * value
String value for string.
Definition: pstring.h:3162
__inline PInt64 AsInt64(unsigned base=0) const
Definition: pstring.h:1760
virtual PBoolean MakeUnique()
Make this instance to be the one and only reference to the container contents.
void SetEnum(const PString &key, E value)
Definition: pstring.h:3337
PStringSet(const BaseClass &other)
Definition: pstring.h:2838
This class is used when an ordinal index value is the key for PSet and PDictionary classes...
Definition: dict.h:47
__inline bool Has(const std::string &key) const
Definition: pstring.h:3370
PStringArray(const std::vector< PString > &vec)
Create a PStringArray from a vector of PStrings.
Definition: pstring.h:2424
__inline void clear()
Definition: pstring.h:1886
PStringDictionary()
Create a new, empty, dictionary.
Definition: pstring.h:2932
PString Trim() const
Create a string consisting of all characters from the source string except all spaces at the beginnin...
__inline PStringArray(const BaseClass &other)
Definition: pstring.h:2383
Data is a length byte followed by characters.
Definition: pstring.h:295
Comparison NumCompare(const PString &str, PINDEX count=P_MAX_INDEX, PINDEX offset=0) const
Compare a string against a substring of the object.
Structure for static array initialiser for class.
Definition: pstring.h:3158
bool SetVar(const std::string &key, const T &value)
Definition: pstring.h:3363
virtual PINDEX GetSize() const
Get the current size of the container.
bool SetVar(const PCaselessString &(*key)(), const T &value)
Definition: pstring.h:3366
PBoolean Contains(const K &key) const
Determine if the value of the object is contained in the hash table.
Definition: dict.h:1036
bool PBoolean
Definition: object.h:174
PStringSet(PBoolean initialDeleteObjects=true)
Create a PStringSet.
Definition: pstring.h:2835
Invalid range end.
Definition: pstring.h:3521
__inline PString Get(const PCaselessString &(*key)(), const char *dflt=NULL) const
Definition: pstring.h:3380
PString GetString(const PCaselessString &(*key)(), const char *dflt=NULL) const
Definition: pstring.h:3290
bool operator==(const PString &str) const
Compare two strings using the PObject::Compare() function.
void Exclude(const PString &key)
Exclude the spcified string value from the set.
bool InternalSplit(const PString &delimiter, PString &before, PString &after, SplitOptions_Bits options) const
This template class maps the PAbstractSet to a specific object type.
Definition: dict.h:508
virtual PObject * Clone() const
Make a complete duplicate of the string.
__inline std::string::size_type find(const char *s, std::string::size_type pos=0) const
Definition: pstring.h:1901
PSortedStringList(int dummy, const PSortedStringList *c)
Definition: pstring.h:2709
PString operator()(const K &key, const char *dflt=NULL) const
Get the string contained in the dictionary at the key position.
Definition: pstring.h:2961
#define P_MAX_INDEX
Definition: object.h:80
PString & operator=(const std::string &str)
Assign the string to the current object.
Definition: pstring.h:366
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:46
PString * GetAt(const PString &key) const
Definition: pstring.h:3267
__inline bool Set(const PString &key, const PString &value)
Definition: pstring.h:3395
The character string class.
Definition: pstring.h:108
__inline PString Get(const PCaselessString &(*key)(), const std::string &dflt) const
Definition: pstring.h:3385
PINDEX InternalStringSelect(const char *str, PINDEX len, PSortedListElement *thisElement, PSortedListElement *&lastElement) const
PString GetString(const std::string &key, const char *dflt=NULL) const
Definition: pstring.h:3287
bool SetString(const char *key, const PString &value)
Set the option value.
Definition: pstring.h:3293
This is a set collection class of PString objects.
Definition: pstring.h:2821
const void * GetPointer() const
Definition: array.h:204
Overwrite destination keys value.
Definition: pstring.h:3202
virtual PString * GetAt(const K &key) const
Get the object at the specified key position.
Definition: dict.h:1075
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...
__inline PString Get(const char *key, const std::string &dflt) const
Definition: pstring.h:3381
PString operator&(const PString &str) const
Concatenate a PString to another PString to produce a third.
PStringArray(int dummy, const PStringArray *c)
Definition: pstring.h:2371
Unmatched left bracket.
Definition: pstring.h:3513
const char * Initialiser
Definition: pstring.h:112
const char * key
String key for ordinal.
Definition: pstring.h:3102
virtual void DestroyReference()
Definition: pstring.h:2158
long AsInteger(unsigned base=0) const
Convert the string to an integer value using the specified number base.
PString * RemoveAt(const PCaselessString &key)
Definition: pstring.h:3282
virtual PBoolean SetAt(const K &key, const PString &str)
Add a new object to the collection.
Definition: pstring.h:2978
PINDEX m_length
Definition: pstring.h:1952
Invalid pattern.
Definition: pstring.h:3503
PCaselessString & operator=(const std::string &str)
Assign the string to the current object.
Definition: pstring.h:2062
PStringDictionary(int dummy, const PStringDictionary *c)
Definition: pstring.h:2985
__inline PString Get(const std::string &key, const std::string &dflt) const
Definition: pstring.h:3382
virtual PString & MakeEmpty()
Make the current string empty.
bool GetBoolean(const PCaselessString &(*key)(), bool dflt=false) const
Definition: pstring.h:3304
__inline PString Get(const PString &key, const char *dflt=NULL) const
Definition: pstring.h:3377
__inline PString & insert(std::string::size_type index, const std::string &s)
Definition: pstring.h:1895
void SetBoolean(const PCaselessString &key, bool value)
Definition: pstring.h:3310
Abstract class to embody the base functionality of a container.
Definition: contain.h:99
This is a list collection class of PString objects.
Definition: pstring.h:2562
Convert an unsigned integer to a string.
Definition: pstring.h:299
PString GetString(const PString &key, const char *dflt=NULL) const
Definition: pstring.h:3288
__inline bool Has(const PCaselessString &key) const
Definition: pstring.h:3372
PStringToString(const PString &str)
Initialise the string dictionary from the string.
Definition: pstring.h:3176
PINDEX FindOneOf(const PString &set, PINDEX offset=0) const
Locate the position of one of the characters in the set.
__inline bool Split(char delimiter, PString &before, PString &after, bool trim) const
Definition: pstring.h:1560
static const PString & Empty()
Return an empty string.
Convert a real number to a string in exponent format.
Definition: pstring.h:301
long GetInteger(const std::string &key, long dflt=0) const
Definition: pstring.h:3315
uint64_t AsUnsigned64(unsigned base=0) const
Convert the string to an integer value using the specified number base.
bool SetVar(const PString &key, const T &value)
Definition: pstring.h:3364
PStringSet & operator-=(const PString &key)
Exclude the spcified string value from the set.
__inline std::string::size_type rfind(const char *s, std::string::size_type pos=0) const
Definition: pstring.h:1904
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:3353
PStringOptions(const PString &str)
Definition: pstring.h:3253
PString * GetAt(const std::string &key) const
Definition: pstring.h:3266
PStringList(int dummy, const PStringList *c)
Definition: pstring.h:2568
__inline bool Set(const std::string &key, const PString &value)
Definition: pstring.h:3394
void SetEnum(const std::string &key, E value)
Definition: pstring.h:3336
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:3386
void FromString(const PString &str)
Set dictionary from string.
__inline PString Get(const PString &key, const PString &dflt) const
Definition: pstring.h:3388
PString GetErrorText() const
Get the text description for the error of the last Compile() or Execute() operation.
bool Execute(const PString &str, PINDEX &start, ExecOptions options=Normal) const
Execute regular expression.
PStringStream & operator=(const PStringStream &strm)
Assign the string part of the stream to the current object.
__inline bool Split(const PString &delimiter, PString &before, PString &after, SplitOptions options=SplitTrim) const
Split the string into two substrings around delimiter.
Definition: pstring.h:1547
This template class maps the PAbstractSortedList to a specific object type.
Definition: lists.h:964
void SetBoolean(const PString &key, bool value)
Definition: pstring.h:3309
bool SetString(const PCaselessString &(*key)(), const PString &value)
Definition: pstring.h:3297
void SetBoolean(const std::string &key, bool value)
Definition: pstring.h:3308
P_DECLARE_BITWISE_ENUM_EX(SplitOptions, 6,(SplitOnly, SplitTrimBefore, SplitTrimAfter, SplitDefaultToBefore, SplitDefaultToAfter, SplitBeforeNonEmpty, SplitAfterNonEmpty), SplitTrim=SplitTrimBefore|SplitTrimAfter, SplitNonEmpty=SplitBeforeNonEmpty|SplitAfterNonEmpty)
Options for PString::Split() function.
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:3349
Invalid parameter was passed to a function.
Definition: object.h:378
~PConstantString()
Definition: pstring.h:2151
Didn&#39;t find a match (for regexec).
Definition: pstring.h:3499
void SetEnum(const char *key, E value)
Set an enum value for the particular MIME info field.
Definition: pstring.h:3335
PConstantString(typename ParentString::Initialiser init)
Definition: pstring.h:2137
Parenthesis imbalance.
Definition: pstring.h:3515
PString GetString(const char *key, const char *dflt=NULL) const
Get an option value.
Definition: pstring.h:3286
This is a dictionary collection class of PString objects, keyed by an ordinal value.
Definition: pstring.h:3046
PString & 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.
static PStringArray container(const stlContainer &vec)
Create a PStringArray from an STL container.
Definition: pstring.h:2447
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:3325
PStringList operator+(const PStringList &array)
Create a new PStringList, and add PString or PStringList to it a new PStringList. ...
E GetEnum(const PString &key, E dflt) const
Definition: pstring.h:3330
This template class maps the PArrayObjects to a specific object type.
Definition: array.h:925
PStringSet & operator+=(const PString &key)
Include the spcified string value into the set.
PConstantString< PCaselessString > PConstCaselessString
Constant PCaselessString type. See PConstantString.
Definition: pstring.h:2169
A class representing a regular expression that may be used for locating patterns in strings...
Definition: pstring.h:3413
PINDEX FindRegEx(const PRegularExpression &regex, PINDEX offset=0) const
Locate the position within the string of one of the regular expression.
T GetVar(const std::string &key, const T &dflt) const
Definition: pstring.h:3357
virtual void AssignContents(const PContainer &)
Definition: pstring.h:2157
virtual int internal_strcmp(const char *s1, const char *s2) const
__inline PString & replace(std::string::size_type pos, std::string::size_type count, const std::string &s)
Definition: pstring.h:1898
__inline PString Get(const PCaselessString &key, const std::string &dflt) const
Definition: pstring.h:3384
PStringArray(const std::vector< std::string > &vec)
Create a PStringArray from a vector of std::string.
Definition: pstring.h:2435
bool Contains(const char *key) const
Determine if the specified key is present.
Definition: pstring.h:3258
Data is two length bytes followed by characters.
Definition: pstring.h:296
bool SetString(const PString &key, const PString &value)
Definition: pstring.h:3295
P_DECLARE_BITWISE_ENUM(CompileOptions, 3,(Simple, Extended, IgnoreCase, AnchorNewLine))
Flags for compiler options.
bool operator>(const PString &str) const
Compare two strings using the PObject::Compare() function.
virtual PINDEX GetLength() const
Determine the length of the null terminated string.
Definition: pstring.h:595
bool MakeMinimumSize(PINDEX newLength=0)
Set the actual memory block array size to the minimum required to hold the current string contents...
__inline PString & insert(std::string::size_type index, std::string::size_type count, char ch)
Definition: pstring.h:1893
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:3321
__inline PString Get(const PCaselessString &key, const PString &dflt) const
Definition: pstring.h:3389
bool SetString(const PCaselessString &key, const PString &value)
Definition: pstring.h:3296
double AsReal() const
Convert the string to a floating point number.
PString * RemoveAt(const PCaselessString &(*key)())
Definition: pstring.h:3283
#define P_DEPRECATED
Definition: object.h:141
__inline void Remove(const PCaselessString &(*key)())
Definition: pstring.h:3404
__inline PString Get(const char *key, const char *dflt=NULL) const
Get the option value.
Definition: pstring.h:3376
Miscellaneous error.
Definition: pstring.h:3535
virtual const char * GetPointer(PINDEX=0) const
Get a const pointer to the buffer contents This function overrides the ancestor function that returns...
Definition: pstring.h:1877
__inline bool Split(const char *delimiter, PString &before, PString &after, SplitOptions_Bits options) const
Definition: pstring.h:1559
PINDEX GetStringsIndex(const PString &str) const
As for GetValuesIndex() but takes a PString argument so that literals will be automatically converted...
__inline PString & erase(std::string::size_type index=0, std::string::size_type count=std::string::npos)
Definition: pstring.h:1896
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:2942
__inline bool Has(const char *key) const
Determine of the option exists.
Definition: pstring.h:3369
DWORD AsUnsigned(unsigned base=0) const
Convert the string to an integer value using the specified number base.
virtual PBoolean SetSize(PINDEX newSize)
Set the size of the string.
__inline PStringList(const BaseClass &other)
Definition: pstring.h:2579
bool GetBoolean(const std::string &key, bool dflt=false) const
Definition: pstring.h:3301
virtual PString * RemoveAt(const K &key)
Remove an object at the specified key.
Definition: dict.h:1049
PString & vsprintf(const PString &fmt, va_list args)
Concatenate a formatted output to the string.
Unmatched \.
Definition: pstring.h:3517
bool operator<(const PString &str) const
Compare two strings using the PObject::Compare() function.
Ignore new value, leave desstination as is.
Definition: pstring.h:3203
PString m_pattern
Definition: pstring.h:3684
Invalid contents of \.
Definition: pstring.h:3519
PINDEX FindLast(char ch, PINDEX offset=P_MAX_INDEX) const
Locate the position of the last matching character.
__inline std::string substr(std::string::size_type pos=0, std::string::size_type count=std::string::npos) const
Definition: pstring.h:1899
PString Mid(PINDEX start, PINDEX len=P_MAX_INDEX) const
Extract a portion of the string into a new string.
virtual PBoolean SetSize(PINDEX s)
Definition: pstring.h:2156
__inline PString Get(const PString &key, const std::string &dflt) const
Definition: pstring.h:3383
__inline std::string::size_type find_first_not_of(const std::string &s, std::string::size_type pos=0) const
Definition: pstring.h:1909
__inline PString Get(const PCaselessString &(*key)(), const PString &dflt) const
Definition: pstring.h:3390
double GetReal(const char *key, double dflt=0) const
Get the option value as a floating point real.
Definition: pstring.h:3342
PString psprintf(const char *fmt,...)
The same as the standard C snprintf(fmt, 1000, ...), but returns a PString instead of a const char *...
T GetVar(const char *key, const T &dflt) const
Get the option value as any type.
Definition: pstring.h:3356
void SetEnum(const PCaselessString &(*key)(), E value)
Definition: pstring.h:3339
This template class maps the PAbstractDictionary to a specific key type and a POrdinalKey data type...
Definition: dict.h:1297
__inline bool Split(char delimiter, PString &before, PString &after, SplitOptions options) const
Definition: pstring.h:1556
PBoolean MatchesRegEx(const PRegularExpression &regex) const
Return true if the entire string matches the regular expression.
virtual int internal_strcmp(const char *s1, const char *s2) const
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
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:3531
void SetInteger(const PString &key, long value)
Definition: pstring.h:3323
PString Left(PINDEX len) const
Extract a portion of the string into a new string.
virtual int internal_strncmp(const char *s1, const char *s2, size_t n) const
PString * RemoveAt(const std::string &key)
Definition: pstring.h:3280
#define PNEW
Macro for overriding system default new operator.
Definition: object.h:1896
friend PString psprintf(const char *cfmt,...)
Produce formatted output as a string.
bool operator>=(const PString &str) const
Compare two strings using the PObject::Compare() function.
PCaselessString(const std::string &str)
Create a caseless string from a std::string.
Definition: pstring.h:2039
Structure for static array initialiser for class.
Definition: pstring.h:3053
Ran out of memory.
Definition: pstring.h:3523
void Merge(const PStringToString &merge, MergeAction action)
Merge string dictionary into this dictionary.
__inline PString Get(const std::string &key, const char *dflt=NULL) const
Definition: pstring.h:3378
double GetReal(const PString &key, double dflt=0) const
Definition: pstring.h:3344
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:3314
__inline void clear()
Definition: pstring.h:2295
CompileOptions m_compileOptions
Definition: pstring.h:3685