00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __PSTRING__
00034 #define __PSTRING__
00035
00036 #ifdef P_USE_PRAGMA
00037 #pragma interface
00038 #endif
00039
00040 #include <string>
00041 #include <vector>
00042 #include <ptlib/array.h>
00043
00045
00046
00047 class PStringArray;
00048 class PRegularExpression;
00049 PBASEARRAY(PWCharArray, wchar_t);
00050
00051
00086 class PString : public PCharArray {
00087 PCLASSINFO(PString, PCharArray);
00088
00089
00090
00091 public:
00097 PINLINE PString();
00098
00102 PINLINE PString(
00103 const PString & str
00104 );
00105
00108 PINLINE PString(
00109 const std::string & str
00110 );
00111
00120 PString(
00121 const char * cstr
00122 );
00123
00128 PString(
00129 const wchar_t * ustr
00130 );
00131
00145 PString(
00146 const char * cstr,
00147 PINDEX len
00148 );
00149
00160 PString(
00161 const wchar_t * ustr,
00162 PINDEX len
00163 );
00164
00175 PString(
00176 const PWCharArray & ustr
00177 );
00178
00187 PString(
00188 char ch
00189 );
00190
00195 PString(
00196 short n
00197 );
00198
00203 PString(
00204 unsigned short n
00205 );
00206
00211 PString(
00212 int n
00213 );
00214
00219 PString(
00220 unsigned int n
00221 );
00222
00227 PString(
00228 long n
00229 );
00230
00235 PString(
00236 unsigned long n
00237 );
00238
00243 PString(
00244 PInt64 n
00245 );
00246
00251 PString(
00252 PUInt64 n
00253 );
00254
00255
00256 enum ConversionType {
00257 Pascal,
00258 Basic,
00259 Literal,
00260 Signed,
00261 Unsigned,
00262 Decimal,
00263 Exponent,
00264 Printf,
00265 NumConversionTypes
00266 };
00267
00268
00269
00270
00271
00272
00273 PString(
00274 ConversionType type,
00275 const char * str,
00276 ...
00277 );
00278 PString(
00279 ConversionType type,
00280 long value,
00281 unsigned base = 10
00282 );
00283 PString(
00284 ConversionType type,
00285 double value,
00286 unsigned places
00287 );
00288
00296 PString & operator=(
00297 const PString & str
00298 );
00299
00309 PString & operator=(
00310 const char * cstr
00311 );
00312
00321 PString & operator=(
00322 char ch
00323 );
00324
00329 PString & operator=(
00330 short n
00331 );
00332
00337 PString & operator=(
00338 unsigned short n
00339 );
00340
00345 PString & operator=(
00346 int n
00347 );
00348
00353 PString & operator=(
00354 unsigned int n
00355 );
00356
00361 PString & operator=(
00362 long n
00363 );
00364
00369 PString & operator=(
00370 unsigned long n
00371 );
00372
00377 PString & operator=(
00378 PInt64 n
00379 );
00380
00385 PString & operator=(
00386 PUInt64 n
00387 );
00388
00391 virtual PString & MakeEmpty();
00392
00395 static PString Empty();
00397
00404 virtual PObject * Clone() const;
00405
00415 virtual Comparison Compare(
00416 const PObject & obj
00417 ) const;
00418
00421 virtual void PrintOn(
00422 ostream & strm
00423 ) const;
00424
00430 virtual void ReadFrom(
00431 istream & strm
00432 );
00433
00447 virtual PINDEX HashFunction() const;
00449
00464 virtual PBoolean SetSize(
00465 PINDEX newSize
00466 );
00467
00476 virtual PBoolean IsEmpty() const;
00477
00486 virtual PBoolean MakeUnique();
00488
00489
00502 PBoolean MakeMinimumSize();
00503
00512 PINLINE PINDEX GetLength() const;
00513
00520 bool operator!() const;
00522
00531 PString operator+(
00532 const PString & str
00533 ) const;
00534
00546 PString operator+(
00547 const char * cstr
00548 ) const;
00549
00561 PString operator+(
00562 char ch
00563 ) const;
00564
00576 friend PString operator+(
00577 const char * cstr,
00578 const PString & str
00579 );
00580
00592 friend PString operator+(
00593 char c,
00594 const PString & str
00595 );
00596
00602 PString & operator+=(
00603 const PString & str
00604 );
00605
00615 PString & operator+=(
00616 const char * cstr
00617 );
00618
00628 PString & operator+=(
00629 char ch
00630 );
00631
00632
00639 PString operator&(
00640 const PString & str
00641 ) const;
00642
00659 PString operator&(
00660 const char * cstr
00661 ) const;
00662
00679 PString operator&(
00680 char ch
00681 ) const;
00682
00699 friend PString operator&(
00700 const char * cstr,
00701 const PString & str
00702 );
00703
00720 friend PString operator&(
00721 char ch,
00722 const PString & str
00723 );
00724
00730 PString & operator&=(
00731 const PString & str
00732 );
00733
00748 PString & operator&=(
00749 const char * cstr
00750 );
00751
00752
00767 PString & operator&=(
00768 char ch
00769 );
00771
00772
00780 bool operator*=(
00781 const PString & str
00782 ) const;
00783
00791 bool operator==(
00792 const PObject & str
00793 ) const;
00794
00802 bool operator!=(
00803 const PObject & str
00804 ) const;
00805
00813 bool operator<(
00814 const PObject & str
00815 ) const;
00816
00824 bool operator>(
00825 const PObject & str
00826 ) const;
00827
00835 bool operator<=(
00836 const PObject & str
00837 ) const;
00838
00846 bool operator>=(
00847 const PObject & str
00848 ) const;
00849
00850
00861 bool operator*=(
00862 const char * cstr
00863 ) const;
00864
00875 bool operator==(
00876 const char * cstr
00877 ) const;
00878
00889 bool operator!=(
00890 const char * cstr
00891 ) const;
00892
00903 bool operator<(
00904 const char * cstr
00905 ) const;
00906
00917 bool operator>(
00918 const char * cstr
00919 ) const;
00920
00931 bool operator<=(
00932 const char * cstr
00933 ) const;
00934
00945 bool operator>=(
00946 const char * cstr
00947 ) const;
00948
00960 Comparison NumCompare(
00961 const PString & str,
00962 PINDEX count = P_MAX_INDEX,
00963 PINDEX offset = 0
00964 ) const;
00965
00977 Comparison NumCompare(
00978 const char * cstr,
00979 PINDEX count = P_MAX_INDEX,
00980 PINDEX offset = 0
00981 ) const;
00983
00984
00988 PINDEX Find(
00989 char ch,
00990 PINDEX offset = 0
00991 ) const;
00992
00994 PINDEX Find(
00995 const PString & str,
00996 PINDEX offset = 0
00997 ) const;
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013 PINDEX Find(
01014 const char * cstr,
01015 PINDEX offset = 0
01016 ) const;
01017
01019 PINDEX FindLast(
01020 char ch,
01021 PINDEX offset = P_MAX_INDEX
01022 ) const;
01023
01025 PINDEX FindLast(
01026 const PString & str,
01027 PINDEX offset = P_MAX_INDEX
01028 ) const;
01029
01047 PINDEX FindLast(
01048 const char * cstr,
01049 PINDEX offset = P_MAX_INDEX
01050 ) const;
01051
01053 PINDEX FindOneOf(
01054 const PString & set,
01055 PINDEX offset = 0
01056 ) const;
01057
01072 PINDEX FindOneOf(
01073 const char * cset,
01074 PINDEX offset = 0
01075 ) const;
01076
01078 PINDEX FindSpan(
01079 const PString & set,
01080 PINDEX offset = 0
01081 ) const;
01082
01098 PINDEX FindSpan(
01099 const char * cset,
01100 PINDEX offset = 0
01101 ) const;
01102
01113 PINDEX FindRegEx(
01114 const PRegularExpression & regex,
01115 PINDEX offset = 0
01116 ) const;
01117
01128 PBoolean FindRegEx(
01129 const PRegularExpression & regex,
01130 PINDEX & pos,
01131 PINDEX & len,
01132 PINDEX offset = 0,
01133 PINDEX maxPos = P_MAX_INDEX
01134 ) const;
01135
01136
01147 void Replace(
01148 const PString & target,
01149 const PString & subs,
01150 PBoolean all = PFalse,
01151 PINDEX offset = 0
01152 );
01153
01161 void Splice(
01162 const PString & str,
01163 PINDEX pos,
01164 PINDEX len = 0
01165 );
01166
01174 void Splice(
01175 const char * cstr,
01176 PINDEX pos,
01177 PINDEX len = 0
01178 );
01179
01186 void Delete(
01187 PINDEX start,
01188 PINDEX len
01189 );
01191
01192
01212 PString operator()(
01213 PINDEX start,
01214 PINDEX end
01215 ) const;
01216
01231 PString Left(
01232 PINDEX len
01233 ) const;
01234
01249 PString Right(
01250 PINDEX len
01251 ) const;
01252
01269 PString Mid(
01270 PINDEX start,
01271 PINDEX len = P_MAX_INDEX
01272 ) const;
01273
01274
01282 PString LeftTrim() const;
01283
01291 PString RightTrim() const;
01292
01301 PString Trim() const;
01302
01303
01312 PString ToLower() const;
01313
01322 PString ToUpper() const;
01323
01324
01326 PStringArray Tokenise(
01327 const PString & separators,
01329 PBoolean onePerSeparator = PTrue
01331 ) const;
01356 PStringArray Tokenise(
01357 const char * cseparators,
01359 PBoolean onePerSeparator = PTrue
01361 ) const;
01362
01376 PStringArray Lines() const;
01378
01395 PString & sprintf(
01396 const char * cfmt,
01397 ...
01398 );
01399
01414 friend PString psprintf(
01415 const char * cfmt,
01416 ...
01417 );
01418
01420 PString & vsprintf(
01421 const PString & fmt,
01422 va_list args
01423 );
01438 PString & vsprintf(
01439 const char * cfmt,
01440 va_list args
01441 );
01442
01444 friend PString pvsprintf(
01445 const char * cfmt,
01446 va_list args
01447 );
01462 friend PString pvsprintf(
01463 const PString & fmt,
01464 va_list args
01465 );
01466
01467
01480 long AsInteger(
01481 unsigned base = 10
01482 ) const;
01495 DWORD AsUnsigned(
01496 unsigned base = 10
01497 ) const;
01511 PInt64 AsInt64(
01512 unsigned base = 10
01513 ) const;
01527 PUInt64 AsUnsigned64(
01528 unsigned base = 10
01529 ) const;
01530
01541 double AsReal() const;
01542
01546 PWCharArray AsUCS2() const;
01547
01558 PBYTEArray ToPascal() const;
01559
01568 PString ToLiteral() const;
01569
01577 operator const unsigned char *() const;
01578
01581 operator std::string () const
01582 { return std::string(theArray); }
01583
01586 #ifdef _WIN32_WCE
01587 operator LPCWSTR() const
01588 { return AsUCS2(); }
01589 #endif
01590
01591
01592
01593 protected:
01594 void InternalFromUCS2(
01595 const wchar_t * ptr,
01596 PINDEX len
01597 );
01598 virtual Comparison InternalCompare(
01599 PINDEX offset,
01600 char c
01601 ) const;
01602 virtual Comparison InternalCompare(
01603 PINDEX offset,
01604 PINDEX length,
01605 const char * cstr
01606 ) const;
01607
01608
01609
01610
01611
01612
01613
01614 PString(int dummy, const PString * str);
01615 };
01616
01617
01618 inline ostream & operator<<(ostream & stream, const PString & string)
01619 {
01620 string.PrintOn(stream);
01621 return stream;
01622 }
01623
01624
01626
01636 class PCaselessString : public PString
01637 {
01638 PCLASSINFO(PCaselessString, PString);
01639
01640 public:
01643 PCaselessString();
01644
01648 PCaselessString(
01649 const char * cstr
01650 );
01651
01656 PCaselessString(
01657 const PString & str
01658 );
01659
01660
01663 PCaselessString(
01664 const std::string & str
01665 ) : PString(str)
01666 { }
01667
01675 PCaselessString & operator=(
01676 const PString & str
01677 );
01678
01688 PCaselessString & operator=(
01689 const char * cstr
01690 );
01691
01700 PCaselessString & operator=(
01701 char ch
01702 );
01703
01704
01705
01710 virtual PObject * Clone() const;
01711
01712 protected:
01713
01714 virtual Comparison InternalCompare(
01715 PINDEX offset,
01716 char c
01717 ) const;
01718 virtual Comparison InternalCompare(
01719 PINDEX offset,
01720 PINDEX length,
01721 const char * cstr
01722 ) const;
01723
01724
01725
01726
01727
01728
01729
01730 PCaselessString(int dummy, const PCaselessString * str);
01731 };
01732
01734
01735 class PStringStream;
01736
01743 class PStringStream : public PString, public iostream
01744 {
01745 PCLASSINFO(PStringStream, PString);
01746
01747 public:
01753 PStringStream();
01754
01759 PStringStream(
01760 PINDEX fixedBufferSize
01761 );
01762
01769 PStringStream(
01770 const PString & str
01771 );
01772
01777 PStringStream(
01778 const char * cstr
01779 );
01780
01783 virtual PString & MakeEmpty();
01784
01796 PStringStream & operator=(
01797 const PStringStream & strm
01798 );
01799
01811 PStringStream & operator=(
01812 const PString & str
01813 );
01814
01830 PStringStream & operator=(
01831 const char * cstr
01832 );
01833
01842 PStringStream & operator=(
01843 char ch
01844 );
01845
01846
01848 virtual ~PStringStream();
01849
01850
01851 protected:
01852 virtual void AssignContents(const PContainer & cont);
01853
01854 private:
01855 PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
01856
01857 class Buffer : public streambuf {
01858 public:
01859 Buffer(PStringStream & str, PINDEX size);
01860 Buffer(const Buffer & sbuf);
01861 Buffer & operator=(const Buffer & sbuf);
01862 virtual int overflow(int=EOF);
01863 virtual int underflow();
01864 virtual int sync();
01865 #ifdef __USE_STL__
01866 virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
01867 virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
01868 #else
01869 virtual streampos seekoff(streamoff, ios::seek_dir, int);
01870 #endif
01871 PStringStream & string;
01872 PBoolean fixedBufferSize;
01873 };
01874 };
01875
01876
01877 class PStringList;
01878 class PSortedStringList;
01879
01892 #ifdef DOC_PLUS_PLUS
01893 class PStringArray : public PArray {
01894 #endif
01895 PDECLARE_ARRAY(PStringArray, PString);
01896 public:
01903 PStringArray(
01904 PINDEX count,
01905 char const * const * strarr,
01906 PBoolean caseless = PFalse
01907 );
01910 PStringArray(
01911 const PString & str
01912 );
01915 PStringArray(
01916 const PStringList & list
01917 );
01920 PStringArray(
01921 const PSortedStringList & list
01922 );
01923
01927 PStringArray(
01928 const std::vector<PString> & vec
01929 )
01930 {
01931 for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
01932 AppendString(*r);
01933 }
01934
01938 PStringArray(
01939 const std::vector<std::string> & vec
01940 )
01941 {
01942 for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
01943 AppendString(PString(*r));
01944 }
01945
01949 template <typename stlContainer>
01950 static PStringArray container(
01951 const stlContainer & vec
01952 )
01953 {
01954 PStringArray list;
01955 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
01956 list.AppendString(PString(*r));
01957 return list;
01958 }
01959
01961
01969 virtual void ReadFrom(
01970 istream &strm
01971 );
01973
01982 PINDEX GetStringsIndex(
01983 const PString & str
01984 ) const;
01985
01986 PString operator[](
01987 PINDEX index
01988 ) const;
01989
01997 PString & operator[](
01998 PINDEX index
01999 );
02000
02003 PINDEX AppendString(
02004 const PString & str
02005 );
02006
02012 PStringArray & operator +=(const PStringArray & array);
02013 PStringArray & operator +=(const PString & str);
02014
02015
02022 PStringArray operator + (const PStringArray & array);
02023 PStringArray operator + (const PString & str);
02024
02032 char ** ToCharArray(
02033 PCharArray * storage = NULL
02034 ) const;
02036 };
02037
02038
02051 #ifdef DOC_PLUS_PLUS
02052 class PStringList : public PList {
02053 #endif
02054 PDECLARE_LIST(PStringList, PString);
02055 public:
02060 PStringList(
02061 PINDEX count,
02062 char const * const * strarr,
02063 PBoolean caseless = PFalse
02064 );
02067 PStringList(
02068 const PString & str
02069 );
02072 PStringList(
02073 const PStringArray & array
02074 );
02077 PStringList(
02078 const PSortedStringList & list
02079 );
02081
02089 virtual void ReadFrom(
02090 istream &strm
02091 );
02093
02098 PINDEX AppendString(
02099 const PString & str
02100 );
02101
02104 PINDEX InsertString(
02105 const PString & before,
02106 const PString & str
02107 );
02108
02112 PINDEX GetStringsIndex(
02113 const PString & str
02114 ) const;
02115
02121 PStringList & operator +=(const PStringList & list);
02122 PStringList & operator +=(const PString & str);
02123
02124
02131 PStringList operator + (const PStringList & array);
02132 PStringList operator + (const PString & str);
02133
02137 template <typename stlContainer>
02138 static PStringList container(
02139 const stlContainer & vec
02140 )
02141 {
02142 PStringList list;
02143 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02144 list.AppendString(PString(*r));
02145 return list;
02146 }
02148 };
02149
02150
02163 #ifdef DOC_PLUS_PLUS
02164 class PSortedStringList : public PSortedList {
02165 #endif
02166 PDECLARE_SORTED_LIST(PSortedStringList, PString);
02167 public:
02172 PSortedStringList(
02173 PINDEX count,
02174 char const * const * strarr,
02175 PBoolean caseless = PFalse
02176 );
02179 PSortedStringList(
02180 const PString & str
02181 );
02184 PSortedStringList(
02185 const PStringArray & array
02186 );
02189 PSortedStringList(
02190 const PStringList & list
02191 );
02193
02201 virtual void ReadFrom(
02202 istream &strm
02203 );
02205
02211 PINDEX AppendString(
02212 const PString & str
02213 );
02214
02218 PINDEX GetStringsIndex(
02219 const PString & str
02220 ) const;
02221
02226 PINDEX GetNextStringsIndex(
02227 const PString & str
02228 ) const;
02230
02231 protected:
02232 PINDEX InternalStringSelect(
02233 const char * str,
02234 PINDEX len,
02235 Element * thisElement
02236 ) const;
02237 };
02238
02239
02256 #ifdef DOC_PLUS_PLUS
02257 class PStringSet : public PSet {
02258 #endif
02259 PDECLARE_SET(PStringSet, PString, PTrue);
02260 public:
02265 PStringSet(
02266 PINDEX count,
02267 char const * const * strarr,
02268 PBoolean caseless = PFalse
02269 );
02272 PStringSet(
02273 const PString & str
02274 );
02276
02284 virtual void ReadFrom(
02285 istream &strm
02286 );
02288
02292 void Include(
02293 const PString & key
02294 );
02296 PStringSet & operator+=(
02297 const PString & key
02298 );
02300 void Exclude(
02301 const PString & key
02302 );
02304 PStringSet & operator-=(
02305 const PString & key
02306 );
02308 };
02309
02310
02311 #ifdef PHAS_TEMPLATES
02312
02320 template <class K> class PStringDictionary : public PAbstractDictionary
02321 {
02322 PCLASSINFO(PStringDictionary, PAbstractDictionary);
02323
02324 public:
02333 PStringDictionary()
02334 : PAbstractDictionary() { }
02336
02343 virtual PObject * Clone() const
02344 { return PNEW PStringDictionary(0, this); }
02346
02361 const PString & operator[](const K & key) const
02362 { return (const PString &)GetRefAt(key); }
02363
02377 PString operator()(const K & key, const char * dflt = "") const
02378 { if (AbstractContains(key)) return (*this)[key]; return dflt; }
02379
02388 PBoolean Contains(
02389 const K & key
02390 ) const { return AbstractContains(key); }
02391
02403 virtual PString * RemoveAt(
02404 const K & key
02405 ) {
02406 PString * s = GetAt(key); AbstractSetAt(key, NULL);
02407 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s;
02408 }
02409
02416 virtual PString * GetAt(
02417 const K & key
02418 ) const { return (PString *)AbstractGetAt(key); }
02419
02428 virtual PBoolean SetDataAt(
02429 PINDEX index,
02430 const PString & str
02431 ) { return PAbstractDictionary::SetDataAt(index, PNEW PString(str)); }
02432
02444 virtual PBoolean SetAt(
02445 const K & key,
02446 const PString & str
02447 ) { return AbstractSetAt(key, PNEW PString(str)); }
02448
02460 const K & GetKeyAt(PINDEX index) const
02461 { return (const K &)AbstractGetKeyAt(index); }
02462
02474 PString & GetDataAt(PINDEX index) const
02475 { return (PString &)AbstractGetDataAt(index); }
02477
02478 protected:
02479 PStringDictionary(int dummy, const PStringDictionary * c)
02480 : PAbstractDictionary(dummy, c) { }
02481 };
02482
02483
02498 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02499 PDECLARE_CLASS(cls, PStringDictionary<K>) \
02500 protected: \
02501 cls(int dummy, const cls * c) \
02502 : PStringDictionary<K>(dummy, c) { } \
02503 public: \
02504 cls() \
02505 : PStringDictionary<K>() { } \
02506 virtual PObject * Clone() const \
02507 { return PNEW cls(0, this); } \
02508
02509
02522 #define PSTRING_DICTIONARY(cls, K) typedef PStringDictionary<K> cls
02523
02524
02525 #else // PHAS_TEMPLATES
02526
02527
02528 #define PSTRING_DICTIONARY(cls, K) \
02529 class cls : public PAbstractDictionary { \
02530 PCLASSINFO(cls, PAbstractDictionary) \
02531 protected: \
02532 inline cls(int dummy, const cls * c) \
02533 : PAbstractDictionary(dummy, c) { } \
02534 public: \
02535 inline cls() \
02536 : PAbstractDictionary() { } \
02537 inline PObject * Clone() const \
02538 { return PNEW cls(0, this); } \
02539 inline PString & operator[](const K & key) const \
02540 { return (PString &)GetRefAt(key); } \
02541 inline PString operator()(const K & key, const char * dflt = "") const \
02542 { if (Contains(key)) return (PString &)GetRefAt(key); return dflt; } \
02543 virtual PBoolean Contains(const K & key) const \
02544 { return AbstractContains(key); } \
02545 virtual PString * RemoveAt(const K & key) \
02546 { PString * s = GetAt(key); AbstractSetAt(key, NULL); \
02547 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s; } \
02548 virtual PString * GetAt(const K & key) const \
02549 { return (PString *)AbstractGetAt(key); } \
02550 virtual PBoolean SetDataAt(PINDEX index, const PString & str) \
02551 { return PAbstractDictionary::SetDataAt(index,PNEW PString(str));} \
02552 virtual PBoolean SetAt(const K & key, const PString & str) \
02553 { return AbstractSetAt(key, PNEW PString(str)); } \
02554 inline const K & GetKeyAt(PINDEX index) const \
02555 { return (const K &)AbstractGetKeyAt(index); } \
02556 inline PString & GetDataAt(PINDEX index) const \
02557 { return (PString &)AbstractGetDataAt(index); } \
02558 }
02559
02560 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02561 PSTRING_DICTIONARY(cls##_PTemplate, K); \
02562 PDECLARE_CLASS(cls, cls##_PTemplate) \
02563 protected: \
02564 cls(int dummy, const cls * c) \
02565 : cls##_PTemplate(dummy, c) { } \
02566 public: \
02567 cls() \
02568 : cls##_PTemplate() { } \
02569 virtual PObject * Clone() const \
02570 { return PNEW cls(0, this); } \
02571
02572 #endif // PHAS_TEMPLATES
02573
02574
02589 #ifdef DOC_PLUS_PLUS
02590 class POrdinalToString : public PStringDictionary {
02591 #endif
02592 PDECLARE_STRING_DICTIONARY(POrdinalToString, POrdinalKey);
02593 public:
02596
02597 struct Initialiser {
02599 PINDEX key;
02601 const char * value;
02602 };
02605 POrdinalToString(
02606 PINDEX count,
02607 const Initialiser * init
02608 );
02610
02618 virtual void ReadFrom(
02619 istream &strm
02620 );
02622 };
02623
02636 #ifdef DOC_PLUS_PLUS
02637 class PStringToOrdinal : public POrdinalDictionary {
02638 #endif
02639 PDECLARE_ORDINAL_DICTIONARY(PStringToOrdinal, PString);
02640 public:
02643
02644 struct Initialiser {
02646 const char * key;
02648 PINDEX value;
02649 };
02652 PStringToOrdinal(
02653 PINDEX count,
02654 const Initialiser * init,
02655 PBoolean caseless = PFalse
02656 );
02658
02666 virtual void ReadFrom(
02667 istream &strm
02668 );
02670 };
02671
02672
02686 #ifdef DOC_PLUS_PLUS
02687 class PStringToString : public PStringDictionary {
02688 #endif
02689 PDECLARE_STRING_DICTIONARY(PStringToString, PString);
02690 public:
02693
02694 struct Initialiser {
02696 const char * key;
02698 const char * value;
02699 };
02702 PStringToString(
02703 PINDEX count,
02704 const Initialiser * init,
02705 PBoolean caselessKeys = PFalse,
02706 PBoolean caselessValues = PFalse
02707 );
02709
02717 virtual void ReadFrom(
02718 istream &strm
02719 );
02721
02734 char ** ToCharArray(
02735 bool withEqualSign,
02736 PCharArray * storage = NULL
02737 ) const;
02738 };
02739
02740
02746 class PRegularExpression : public PObject
02747 {
02748 PCLASSINFO(PRegularExpression, PObject);
02749
02750 public:
02753
02754 enum {
02756 Extended = 1,
02758 IgnoreCase = 2,
02763 AnchorNewLine = 4
02764 };
02766 enum {
02773 NotBeginningOfLine = 1,
02775 NotEndofLine = 2
02776 };
02777
02779 PRegularExpression();
02780
02783 PRegularExpression(
02784 const PString & pattern,
02785 int flags = IgnoreCase
02786 );
02787
02790 PRegularExpression(
02791 const char * cpattern,
02792 int flags = IgnoreCase
02793 );
02794
02798 PRegularExpression(
02799 const PRegularExpression &
02800 );
02801
02805 PRegularExpression & operator =(
02806 const PRegularExpression &
02807 );
02808
02810 ~PRegularExpression();
02812
02815
02816 enum ErrorCodes {
02818 NoError = 0,
02820 NoMatch,
02821
02822
02824 BadPattern,
02826 CollateError,
02828 BadClassType,
02830 BadEscape,
02832 BadSubReg,
02834 UnmatchedBracket,
02836 UnmatchedParen,
02838 UnmatchedBrace,
02840 BadBR,
02842 RangeError,
02844 OutOfMemory,
02846 BadRepitition,
02847
02848
02850 PrematureEnd,
02852 TooBig,
02854 UnmatchedRParen,
02856 NotCompiled
02857 };
02858
02864 ErrorCodes GetErrorCode() const;
02865
02872 PString GetErrorText() const;
02874
02878 PBoolean Compile(
02879 const PString & pattern,
02880 int flags = IgnoreCase
02881 );
02889 PBoolean Compile(
02890 const char * cpattern,
02891 int flags = IgnoreCase
02892 );
02893
02894
02896 PBoolean Execute(
02897 const PString & str,
02898 PINDEX & start,
02899 int flags = 0
02900 ) const;
02902 PBoolean Execute(
02903 const PString & str,
02904 PINDEX & start,
02905 PINDEX & len,
02906 int flags = 0
02907 ) const;
02909 PBoolean Execute(
02910 const char * cstr,
02911 PINDEX & start,
02912 int flags = 0
02913 ) const;
02915 PBoolean Execute(
02916 const char * cstr,
02917 PINDEX & start,
02918 PINDEX & len,
02919 int flags = 0
02920 ) const;
02922 PBoolean Execute(
02923 const PString & str,
02924 PIntArray & starts,
02925 int flags = 0
02926 ) const;
02928 PBoolean Execute(
02929 const PString & str,
02930 PIntArray & starts,
02931 PIntArray & ends,
02932 int flags = 0
02933 ) const;
02935 PBoolean Execute(
02936 const char * cstr,
02937 PIntArray & starts,
02938 int flags = 0
02939 ) const;
02955 PBoolean Execute(
02956 const char * cstr,
02957 PIntArray & starts,
02958 PIntArray & ends,
02959 int flags = 0
02960 ) const;
02962
02971 static PString EscapeString(
02972 const PString & str
02973 );
02975
02976 protected:
02977 PString patternSaved;
02978 int flagsSaved;
02979
02980 void * expression;
02981 mutable ErrorCodes lastError;
02982 };
02983
02984 PString psprintf(const char * cfmt, ...);
02985
02986 #endif // #ifndef __PSTRING__
02987