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
00050 #if (defined(_WIN32) || defined(_WIN32_WCE)) && (!defined(_NATIVE_WCHAR_T_DEFINED))
00051 PBASEARRAY(PWCharArray, unsigned short);
00052 #else
00053 PBASEARRAY(PWCharArray, wchar_t);
00054 #endif
00055
00090 class PString : public PCharArray {
00091 PCLASSINFO(PString, PCharArray);
00092
00093
00094
00095 public:
00101 PINLINE PString();
00102
00106 PINLINE PString(
00107 const PString & str
00108 );
00109
00112 PINLINE PString(
00113 const std::string & str
00114 );
00115
00124 PString(
00125 const char * cstr
00126 );
00127
00132 PString(
00133 const wchar_t * ustr
00134 );
00135
00149 PString(
00150 const char * cstr,
00151 PINDEX len
00152 );
00153
00164 PString(
00165 const wchar_t * ustr,
00166 PINDEX len
00167 );
00168
00179 PString(
00180 const PWCharArray & ustr
00181 );
00182
00191 PString(
00192 char ch
00193 );
00194
00199 PString(
00200 short n
00201 );
00202
00207 PString(
00208 unsigned short n
00209 );
00210
00215 PString(
00216 int n
00217 );
00218
00223 PString(
00224 unsigned int n
00225 );
00226
00231 PString(
00232 long n
00233 );
00234
00239 PString(
00240 unsigned long n
00241 );
00242
00247 PString(
00248 PInt64 n
00249 );
00250
00255 PString(
00256 PUInt64 n
00257 );
00258
00259
00260 enum ConversionType {
00261 Pascal,
00262 Basic,
00263 Literal,
00264 Signed,
00265 Unsigned,
00266 Decimal,
00267 Exponent,
00268 Printf,
00269 NumConversionTypes
00270 };
00271
00272
00273
00274
00275
00276
00277 PString(
00278 ConversionType type,
00279 const char * str,
00280 ...
00281 );
00282 PString(
00283 ConversionType type,
00284 long value,
00285 unsigned base = 10
00286 );
00287 PString(
00288 ConversionType type,
00289 double value,
00290 unsigned places
00291 );
00292
00300 PString & operator=(
00301 const PString & str
00302 );
00303
00313 PString & operator=(
00314 const char * cstr
00315 );
00316
00325 PString & operator=(
00326 char ch
00327 );
00328
00333 PString & operator=(
00334 short n
00335 );
00336
00341 PString & operator=(
00342 unsigned short n
00343 );
00344
00349 PString & operator=(
00350 int n
00351 );
00352
00357 PString & operator=(
00358 unsigned int n
00359 );
00360
00365 PString & operator=(
00366 long n
00367 );
00368
00373 PString & operator=(
00374 unsigned long n
00375 );
00376
00381 PString & operator=(
00382 PInt64 n
00383 );
00384
00389 PString & operator=(
00390 PUInt64 n
00391 );
00392
00395 virtual PString & MakeEmpty();
00396
00399 static PString Empty();
00401
00408 virtual PObject * Clone() const;
00409
00419 virtual Comparison Compare(
00420 const PObject & obj
00421 ) const;
00422
00425 virtual void PrintOn(
00426 ostream & strm
00427 ) const;
00428
00434 virtual void ReadFrom(
00435 istream & strm
00436 );
00437
00451 virtual PINDEX HashFunction() const;
00453
00468 virtual PBoolean SetSize(
00469 PINDEX newSize
00470 );
00471
00480 virtual PBoolean IsEmpty() const;
00481
00490 virtual PBoolean MakeUnique();
00492
00493
00506 PBoolean MakeMinimumSize();
00507
00516 PINLINE PINDEX GetLength() const;
00517
00524 bool operator!() const;
00526
00535 PString operator+(
00536 const PString & str
00537 ) const;
00538
00550 PString operator+(
00551 const char * cstr
00552 ) const;
00553
00565 PString operator+(
00566 char ch
00567 ) const;
00568
00580 friend PString operator+(
00581 const char * cstr,
00582 const PString & str
00583 );
00584
00596 friend PString operator+(
00597 char c,
00598 const PString & str
00599 );
00600
00606 PString & operator+=(
00607 const PString & str
00608 );
00609
00619 PString & operator+=(
00620 const char * cstr
00621 );
00622
00632 PString & operator+=(
00633 char ch
00634 );
00635
00636
00643 PString operator&(
00644 const PString & str
00645 ) const;
00646
00663 PString operator&(
00664 const char * cstr
00665 ) const;
00666
00683 PString operator&(
00684 char ch
00685 ) const;
00686
00703 friend PString operator&(
00704 const char * cstr,
00705 const PString & str
00706 );
00707
00724 friend PString operator&(
00725 char ch,
00726 const PString & str
00727 );
00728
00734 PString & operator&=(
00735 const PString & str
00736 );
00737
00752 PString & operator&=(
00753 const char * cstr
00754 );
00755
00756
00771 PString & operator&=(
00772 char ch
00773 );
00775
00776
00784 bool operator*=(
00785 const PString & str
00786 ) const;
00787
00795 bool operator==(
00796 const PObject & str
00797 ) const;
00798
00806 bool operator!=(
00807 const PObject & str
00808 ) const;
00809
00817 bool operator<(
00818 const PObject & str
00819 ) const;
00820
00828 bool operator>(
00829 const PObject & str
00830 ) const;
00831
00839 bool operator<=(
00840 const PObject & str
00841 ) const;
00842
00850 bool operator>=(
00851 const PObject & str
00852 ) const;
00853
00854
00865 bool operator*=(
00866 const char * cstr
00867 ) const;
00868
00879 bool operator==(
00880 const char * cstr
00881 ) const;
00882
00893 bool operator!=(
00894 const char * cstr
00895 ) const;
00896
00907 bool operator<(
00908 const char * cstr
00909 ) const;
00910
00921 bool operator>(
00922 const char * cstr
00923 ) const;
00924
00935 bool operator<=(
00936 const char * cstr
00937 ) const;
00938
00949 bool operator>=(
00950 const char * cstr
00951 ) const;
00952
00964 Comparison NumCompare(
00965 const PString & str,
00966 PINDEX count = P_MAX_INDEX,
00967 PINDEX offset = 0
00968 ) const;
00969
00981 Comparison NumCompare(
00982 const char * cstr,
00983 PINDEX count = P_MAX_INDEX,
00984 PINDEX offset = 0
00985 ) const;
00987
00988
00992 PINDEX Find(
00993 char ch,
00994 PINDEX offset = 0
00995 ) const;
00996
00998 PINDEX Find(
00999 const PString & str,
01000 PINDEX offset = 0
01001 ) const;
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017 PINDEX Find(
01018 const char * cstr,
01019 PINDEX offset = 0
01020 ) const;
01021
01023 PINDEX FindLast(
01024 char ch,
01025 PINDEX offset = P_MAX_INDEX
01026 ) const;
01027
01029 PINDEX FindLast(
01030 const PString & str,
01031 PINDEX offset = P_MAX_INDEX
01032 ) const;
01033
01051 PINDEX FindLast(
01052 const char * cstr,
01053 PINDEX offset = P_MAX_INDEX
01054 ) const;
01055
01057 PINDEX FindOneOf(
01058 const PString & set,
01059 PINDEX offset = 0
01060 ) const;
01061
01076 PINDEX FindOneOf(
01077 const char * cset,
01078 PINDEX offset = 0
01079 ) const;
01080
01082 PINDEX FindSpan(
01083 const PString & set,
01084 PINDEX offset = 0
01085 ) const;
01086
01102 PINDEX FindSpan(
01103 const char * cset,
01104 PINDEX offset = 0
01105 ) const;
01106
01117 PINDEX FindRegEx(
01118 const PRegularExpression & regex,
01119 PINDEX offset = 0
01120 ) const;
01121
01132 PBoolean FindRegEx(
01133 const PRegularExpression & regex,
01134 PINDEX & pos,
01135 PINDEX & len,
01136 PINDEX offset = 0,
01137 PINDEX maxPos = P_MAX_INDEX
01138 ) const;
01139
01140
01151 void Replace(
01152 const PString & target,
01153 const PString & subs,
01154 PBoolean all = PFalse,
01155 PINDEX offset = 0
01156 );
01157
01165 void Splice(
01166 const PString & str,
01167 PINDEX pos,
01168 PINDEX len = 0
01169 );
01170
01178 void Splice(
01179 const char * cstr,
01180 PINDEX pos,
01181 PINDEX len = 0
01182 );
01183
01190 void Delete(
01191 PINDEX start,
01192 PINDEX len
01193 );
01195
01196
01216 PString operator()(
01217 PINDEX start,
01218 PINDEX end
01219 ) const;
01220
01235 PString Left(
01236 PINDEX len
01237 ) const;
01238
01253 PString Right(
01254 PINDEX len
01255 ) const;
01256
01273 PString Mid(
01274 PINDEX start,
01275 PINDEX len = P_MAX_INDEX
01276 ) const;
01277
01278
01286 PString LeftTrim() const;
01287
01295 PString RightTrim() const;
01296
01305 PString Trim() const;
01306
01307
01316 PString ToLower() const;
01317
01326 PString ToUpper() const;
01327
01328
01330 PStringArray Tokenise(
01331 const PString & separators,
01333 PBoolean onePerSeparator = PTrue
01335 ) const;
01360 PStringArray Tokenise(
01361 const char * cseparators,
01363 PBoolean onePerSeparator = PTrue
01365 ) const;
01366
01380 PStringArray Lines() const;
01382
01399 PString & sprintf(
01400 const char * cfmt,
01401 ...
01402 );
01403
01418 friend PString psprintf(
01419 const char * cfmt,
01420 ...
01421 );
01422
01424 PString & vsprintf(
01425 const PString & fmt,
01426 va_list args
01427 );
01442 PString & vsprintf(
01443 const char * cfmt,
01444 va_list args
01445 );
01446
01448 friend PString pvsprintf(
01449 const char * cfmt,
01450 va_list args
01451 );
01466 friend PString pvsprintf(
01467 const PString & fmt,
01468 va_list args
01469 );
01470
01471
01484 long AsInteger(
01485 unsigned base = 10
01486 ) const;
01499 DWORD AsUnsigned(
01500 unsigned base = 10
01501 ) const;
01515 PInt64 AsInt64(
01516 unsigned base = 10
01517 ) const;
01531 PUInt64 AsUnsigned64(
01532 unsigned base = 10
01533 ) const;
01534
01545 double AsReal() const;
01546
01550 PWCharArray AsUCS2() const;
01551
01562 PBYTEArray ToPascal() const;
01563
01572 PString ToLiteral() const;
01573
01581 operator const unsigned char *() const;
01582
01585 operator std::string () const
01586 { return std::string(theArray); }
01588
01589
01590 protected:
01591 void InternalFromUCS2(
01592 const wchar_t * ptr,
01593 PINDEX len
01594 );
01595 virtual Comparison InternalCompare(
01596 PINDEX offset,
01597 char c
01598 ) const;
01599 virtual Comparison InternalCompare(
01600 PINDEX offset,
01601 PINDEX length,
01602 const char * cstr
01603 ) const;
01604
01605
01606
01607
01608
01609
01610
01611 PString(int dummy, const PString * str);
01612 };
01613
01614
01615 inline ostream & operator<<(ostream & stream, const PString & string)
01616 {
01617 string.PrintOn(stream);
01618 return stream;
01619 }
01620
01621
01622 #ifdef _WIN32
01623 class PWideString : public PWCharArray {
01624 PCLASSINFO(PWideString, PWCharArray);
01625
01626 public:
01627 PWideString() { }
01628 PWideString(const PWCharArray & arr) : PWCharArray(arr) { }
01629 PWideString(const PString & str) : PWCharArray(str.AsUCS2()) { }
01630 PWideString(const char * str) : PWCharArray(PString(str).AsUCS2()) { }
01631 PWideString & operator=(const PWideString & str) { PWCharArray::operator=(str); return *this; }
01632 PWideString & operator=(const PString & str) { PWCharArray::operator=(str.AsUCS2()); return *this; }
01633 PWideString & operator=(const char * str) { PWCharArray::operator=(PString(str).AsUCS2()); return *this; }
01634 friend inline ostream & operator<<(ostream & stream, const PWideString & string) { return stream << PString(string); }
01635 };
01636
01637 #ifdef UNICODE
01638 typedef PWideString PVarString;
01639 #else
01640 typedef PString PVarString;
01641 #endif
01642 #endif
01643
01644
01646
01656 class PCaselessString : public PString
01657 {
01658 PCLASSINFO(PCaselessString, PString);
01659
01660 public:
01663 PCaselessString();
01664
01668 PCaselessString(
01669 const char * cstr
01670 );
01671
01676 PCaselessString(
01677 const PString & str
01678 );
01679
01680
01683 PCaselessString(
01684 const std::string & str
01685 ) : PString(str)
01686 { }
01687
01695 PCaselessString & operator=(
01696 const PString & str
01697 );
01698
01708 PCaselessString & operator=(
01709 const char * cstr
01710 );
01711
01720 PCaselessString & operator=(
01721 char ch
01722 );
01723
01724
01725
01730 virtual PObject * Clone() const;
01731
01732 protected:
01733
01734 virtual Comparison InternalCompare(
01735 PINDEX offset,
01736 char c
01737 ) const;
01738 virtual Comparison InternalCompare(
01739 PINDEX offset,
01740 PINDEX length,
01741 const char * cstr
01742 ) const;
01743
01744
01745
01746
01747
01748
01749
01750 PCaselessString(int dummy, const PCaselessString * str);
01751 };
01752
01754
01755 class PStringStream;
01756
01763 class PStringStream : public PString, public iostream
01764 {
01765 PCLASSINFO(PStringStream, PString);
01766
01767 public:
01773 PStringStream();
01774
01779 PStringStream(
01780 PINDEX fixedBufferSize
01781 );
01782
01789 PStringStream(
01790 const PString & str
01791 );
01792
01797 PStringStream(
01798 const char * cstr
01799 );
01800
01803 virtual PString & MakeEmpty();
01804
01816 PStringStream & operator=(
01817 const PStringStream & strm
01818 );
01819
01831 PStringStream & operator=(
01832 const PString & str
01833 );
01834
01850 PStringStream & operator=(
01851 const char * cstr
01852 );
01853
01862 PStringStream & operator=(
01863 char ch
01864 );
01865
01866
01868 virtual ~PStringStream();
01869
01870
01871 protected:
01872 virtual void AssignContents(const PContainer & cont);
01873
01874 private:
01875 PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
01876
01877 class Buffer : public streambuf {
01878 public:
01879 Buffer(PStringStream & str, PINDEX size);
01880 Buffer(const Buffer & sbuf);
01881 Buffer & operator=(const Buffer & sbuf);
01882 virtual int overflow(int=EOF);
01883 virtual int underflow();
01884 virtual int sync();
01885 #ifdef __USE_STL__
01886 virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
01887 virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
01888 #else
01889 virtual streampos seekoff(streamoff, ios::seek_dir, int);
01890 #endif
01891 PStringStream & string;
01892 PBoolean fixedBufferSize;
01893 };
01894 };
01895
01896
01897 class PStringList;
01898 class PSortedStringList;
01899
01912 #ifdef DOC_PLUS_PLUS
01913 class PStringArray : public PArray {
01914 #endif
01915 PDECLARE_ARRAY(PStringArray, PString);
01916 public:
01923 PStringArray(
01924 PINDEX count,
01925 char const * const * strarr,
01926 PBoolean caseless = PFalse
01927 );
01930 PStringArray(
01931 const PString & str
01932 );
01935 PStringArray(
01936 const PStringList & list
01937 );
01940 PStringArray(
01941 const PSortedStringList & list
01942 );
01943
01947 PStringArray(
01948 const std::vector<PString> & vec
01949 )
01950 {
01951 for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
01952 AppendString(*r);
01953 }
01954
01958 PStringArray(
01959 const std::vector<std::string> & vec
01960 )
01961 {
01962 for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
01963 AppendString(PString(*r));
01964 }
01965
01969 template <typename stlContainer>
01970 static PStringArray container(
01971 const stlContainer & vec
01972 )
01973 {
01974 PStringArray list;
01975 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
01976 list.AppendString(PString(*r));
01977 return list;
01978 }
01979
01981
01989 virtual void ReadFrom(
01990 istream &strm
01991 );
01993
02002 PINDEX GetStringsIndex(
02003 const PString & str
02004 ) const;
02005
02006 PString operator[](
02007 PINDEX index
02008 ) const;
02009
02017 PString & operator[](
02018 PINDEX index
02019 );
02020
02023 PINDEX AppendString(
02024 const PString & str
02025 );
02026
02032 PStringArray & operator +=(const PStringArray & array);
02033 PStringArray & operator +=(const PString & str);
02034
02035
02042 PStringArray operator + (const PStringArray & array);
02043 PStringArray operator + (const PString & str);
02044
02052 char ** ToCharArray(
02053 PCharArray * storage = NULL
02054 ) const;
02056 };
02057
02058
02071 #ifdef DOC_PLUS_PLUS
02072 class PStringList : public PList {
02073 #endif
02074 PDECLARE_LIST(PStringList, PString);
02075 public:
02080 PStringList(
02081 PINDEX count,
02082 char const * const * strarr,
02083 PBoolean caseless = PFalse
02084 );
02087 PStringList(
02088 const PString & str
02089 );
02092 PStringList(
02093 const PStringArray & array
02094 );
02097 PStringList(
02098 const PSortedStringList & list
02099 );
02101
02109 virtual void ReadFrom(
02110 istream &strm
02111 );
02113
02118 PINDEX AppendString(
02119 const PString & str
02120 );
02121
02124 PINDEX InsertString(
02125 const PString & before,
02126 const PString & str
02127 );
02128
02132 PINDEX GetStringsIndex(
02133 const PString & str
02134 ) const;
02135
02141 PStringList & operator +=(const PStringList & list);
02142 PStringList & operator +=(const PString & str);
02143
02144
02151 PStringList operator + (const PStringList & array);
02152 PStringList operator + (const PString & str);
02153
02157 template <typename stlContainer>
02158 static PStringList container(
02159 const stlContainer & vec
02160 )
02161 {
02162 PStringList list;
02163 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02164 list.AppendString(PString(*r));
02165 return list;
02166 }
02168 };
02169
02170
02183 #ifdef DOC_PLUS_PLUS
02184 class PSortedStringList : public PSortedList {
02185 #endif
02186 PDECLARE_SORTED_LIST(PSortedStringList, PString);
02187 public:
02192 PSortedStringList(
02193 PINDEX count,
02194 char const * const * strarr,
02195 PBoolean caseless = PFalse
02196 );
02199 PSortedStringList(
02200 const PString & str
02201 );
02204 PSortedStringList(
02205 const PStringArray & array
02206 );
02209 PSortedStringList(
02210 const PStringList & list
02211 );
02213
02221 virtual void ReadFrom(
02222 istream &strm
02223 );
02225
02231 PINDEX AppendString(
02232 const PString & str
02233 );
02234
02238 PINDEX GetStringsIndex(
02239 const PString & str
02240 ) const;
02241
02246 PINDEX GetNextStringsIndex(
02247 const PString & str
02248 ) const;
02250
02251 protected:
02252 PINDEX InternalStringSelect(
02253 const char * str,
02254 PINDEX len,
02255 Element * thisElement,
02256 Element * & lastElement
02257 ) const;
02258 };
02259
02260
02277 #ifdef DOC_PLUS_PLUS
02278 class PStringSet : public PSet {
02279 #endif
02280 PDECLARE_SET(PStringSet, PString, PTrue);
02281 public:
02286 PStringSet(
02287 PINDEX count,
02288 char const * const * strarr,
02289 PBoolean caseless = PFalse
02290 );
02293 PStringSet(
02294 const PString & str
02295 );
02297
02305 virtual void ReadFrom(
02306 istream &strm
02307 );
02309
02313 void Include(
02314 const PString & key
02315 );
02317 PStringSet & operator+=(
02318 const PString & key
02319 );
02321 void Exclude(
02322 const PString & key
02323 );
02325 PStringSet & operator-=(
02326 const PString & key
02327 );
02329 };
02330
02331
02339 template <class K> class PStringDictionary : public PAbstractDictionary
02340 {
02341 PCLASSINFO(PStringDictionary, PAbstractDictionary);
02342
02343 public:
02352 PStringDictionary()
02353 : PAbstractDictionary() { }
02355
02362 virtual PObject * Clone() const
02363 { return PNEW PStringDictionary(0, this); }
02365
02380 const PString & operator[](const K & key) const
02381 { return (const PString &)GetRefAt(key); }
02382
02396 PString operator()(const K & key, const char * dflt = "") const
02397 { if (AbstractContains(key)) return (*this)[key]; return dflt; }
02398
02407 PBoolean Contains(
02408 const K & key
02409 ) const { return AbstractContains(key); }
02410
02422 virtual PString * RemoveAt(
02423 const K & key
02424 ) {
02425 PString * s = GetAt(key); AbstractSetAt(key, NULL);
02426 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s;
02427 }
02428
02435 virtual PString * GetAt(
02436 const K & key
02437 ) const { return (PString *)AbstractGetAt(key); }
02438
02447 virtual PBoolean SetDataAt(
02448 PINDEX index,
02449 const PString & str
02450 ) { return PAbstractDictionary::SetDataAt(index, PNEW PString(str)); }
02451
02463 virtual PBoolean SetAt(
02464 const K & key,
02465 const PString & str
02466 ) { return AbstractSetAt(key, PNEW PString(str)); }
02467
02479 const K & GetKeyAt(PINDEX index) const
02480 { return (const K &)AbstractGetKeyAt(index); }
02481
02493 PString & GetDataAt(PINDEX index) const
02494 { return (PString &)AbstractGetDataAt(index); }
02496
02497 protected:
02498 PStringDictionary(int dummy, const PStringDictionary * c)
02499 : PAbstractDictionary(dummy, c) { }
02500 };
02501
02502
02517 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02518 PDECLARE_CLASS(cls, PStringDictionary<K>) \
02519 protected: \
02520 cls(int dummy, const cls * c) \
02521 : PStringDictionary<K>(dummy, c) { } \
02522 public: \
02523 cls() \
02524 : PStringDictionary<K>() { } \
02525 virtual PObject * Clone() const \
02526 { return PNEW cls(0, this); } \
02527
02528
02541 #define PSTRING_DICTIONARY(cls, K) typedef PStringDictionary<K> cls
02542
02543
02558 #ifdef DOC_PLUS_PLUS
02559 class POrdinalToString : public PStringDictionary {
02560 #endif
02561 PDECLARE_STRING_DICTIONARY(POrdinalToString, POrdinalKey);
02562 public:
02565
02566 struct Initialiser {
02568 PINDEX key;
02570 const char * value;
02571 };
02574 POrdinalToString(
02575 PINDEX count,
02576 const Initialiser * init
02577 );
02579
02587 virtual void ReadFrom(
02588 istream &strm
02589 );
02591 };
02592
02605 #ifdef DOC_PLUS_PLUS
02606 class PStringToOrdinal : public POrdinalDictionary {
02607 #endif
02608 PDECLARE_ORDINAL_DICTIONARY(PStringToOrdinal, PString);
02609 public:
02612
02613 struct Initialiser {
02615 const char * key;
02617 PINDEX value;
02618 };
02621 PStringToOrdinal(
02622 PINDEX count,
02623 const Initialiser * init,
02624 PBoolean caseless = PFalse
02625 );
02627
02635 virtual void ReadFrom(
02636 istream &strm
02637 );
02639 };
02640
02641
02655 #ifdef DOC_PLUS_PLUS
02656 class PStringToString : public PStringDictionary {
02657 #endif
02658 PDECLARE_STRING_DICTIONARY(PStringToString, PString);
02659 public:
02662
02663 struct Initialiser {
02665 const char * key;
02667 const char * value;
02668 };
02671 PStringToString(
02672 PINDEX count,
02673 const Initialiser * init,
02674 PBoolean caselessKeys = PFalse,
02675 PBoolean caselessValues = PFalse
02676 );
02678
02686 virtual void ReadFrom(
02687 istream &strm
02688 );
02690
02703 char ** ToCharArray(
02704 bool withEqualSign,
02705 PCharArray * storage = NULL
02706 ) const;
02707 };
02708
02709
02715 class PRegularExpression : public PObject
02716 {
02717 PCLASSINFO(PRegularExpression, PObject);
02718
02719 public:
02722
02723 enum {
02725 Extended = 1,
02727 IgnoreCase = 2,
02732 AnchorNewLine = 4
02733 };
02735 enum {
02742 NotBeginningOfLine = 1,
02744 NotEndofLine = 2
02745 };
02746
02748 PRegularExpression();
02749
02752 PRegularExpression(
02753 const PString & pattern,
02754 int flags = IgnoreCase
02755 );
02756
02759 PRegularExpression(
02760 const char * cpattern,
02761 int flags = IgnoreCase
02762 );
02763
02767 PRegularExpression(
02768 const PRegularExpression &
02769 );
02770
02774 PRegularExpression & operator =(
02775 const PRegularExpression &
02776 );
02777
02779 ~PRegularExpression();
02781
02784
02785 enum ErrorCodes {
02787 NoError = 0,
02789 NoMatch,
02790
02791
02793 BadPattern,
02795 CollateError,
02797 BadClassType,
02799 BadEscape,
02801 BadSubReg,
02803 UnmatchedBracket,
02805 UnmatchedParen,
02807 UnmatchedBrace,
02809 BadBR,
02811 RangeError,
02813 OutOfMemory,
02815 BadRepitition,
02816
02817
02819 PrematureEnd,
02821 TooBig,
02823 UnmatchedRParen,
02825 NotCompiled
02826 };
02827
02833 ErrorCodes GetErrorCode() const;
02834
02841 PString GetErrorText() const;
02843
02847 PBoolean Compile(
02848 const PString & pattern,
02849 int flags = IgnoreCase
02850 );
02858 PBoolean Compile(
02859 const char * cpattern,
02860 int flags = IgnoreCase
02861 );
02862
02863
02865 PBoolean Execute(
02866 const PString & str,
02867 PINDEX & start,
02868 int flags = 0
02869 ) const;
02871 PBoolean Execute(
02872 const PString & str,
02873 PINDEX & start,
02874 PINDEX & len,
02875 int flags = 0
02876 ) const;
02878 PBoolean Execute(
02879 const char * cstr,
02880 PINDEX & start,
02881 int flags = 0
02882 ) const;
02884 PBoolean Execute(
02885 const char * cstr,
02886 PINDEX & start,
02887 PINDEX & len,
02888 int flags = 0
02889 ) const;
02891 PBoolean Execute(
02892 const PString & str,
02893 PIntArray & starts,
02894 int flags = 0
02895 ) const;
02897 PBoolean Execute(
02898 const PString & str,
02899 PIntArray & starts,
02900 PIntArray & ends,
02901 int flags = 0
02902 ) const;
02904 PBoolean Execute(
02905 const char * cstr,
02906 PIntArray & starts,
02907 int flags = 0
02908 ) const;
02924 PBoolean Execute(
02925 const char * cstr,
02926 PIntArray & starts,
02927 PIntArray & ends,
02928 int flags = 0
02929 ) const;
02931
02940 static PString EscapeString(
02941 const PString & str
02942 );
02944
02945 protected:
02946 PString patternSaved;
02947 int flagsSaved;
02948
02949 void * expression;
02950 mutable ErrorCodes lastError;
02951 };
02952
02953 PString psprintf(const char * cfmt, ...);
02954
02955 #endif // #ifndef __PSTRING__
02956