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
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 #ifndef __PSTRING__
00350 #define __PSTRING__
00351
00352 #ifdef P_USE_PRAGMA
00353 #pragma interface
00354 #endif
00355
00356 #include <string>
00357 #include <vector>
00358 #include <ptlib/array.h>
00359
00361
00362
00363 class PStringArray;
00364 class PRegularExpression;
00365
00400 class PString : public PCharArray {
00401 PCLASSINFO(PString, PCharArray);
00402
00403
00404
00405 public:
00411 PINLINE PString();
00412
00416 PINLINE PString(
00417 const PString & str
00418 );
00419
00422 PINLINE PString(
00423 const std::string & str
00424 );
00425
00434 PString(
00435 const char * cstr
00436 );
00437
00442 PString(
00443 const WORD * ustr
00444 );
00445
00459 PString(
00460 const char * cstr,
00461 PINDEX len
00462 );
00463
00474 PString(
00475 const WORD * ustr,
00476 PINDEX len
00477 );
00478
00489 PString(
00490 const PWORDArray & ustr
00491 );
00492
00501 PString(
00502 char ch
00503 );
00504
00509 PString(
00510 short n
00511 );
00512
00517 PString(
00518 unsigned short n
00519 );
00520
00525 PString(
00526 int n
00527 );
00528
00533 PString(
00534 unsigned int n
00535 );
00536
00541 PString(
00542 long n
00543 );
00544
00549 PString(
00550 unsigned long n
00551 );
00552
00557 PString(
00558 PInt64 n
00559 );
00560
00565 PString(
00566 PUInt64 n
00567 );
00568
00569
00570 enum ConversionType {
00571 Pascal,
00572 Basic,
00573 Literal,
00574 Signed,
00575 Unsigned,
00576 Decimal,
00577 Exponent,
00578 Printf,
00579 NumConversionTypes
00580 };
00581
00582
00583
00584
00585
00586
00587 PString(
00588 ConversionType type,
00589 const char * str,
00590 ...
00591 );
00592 PString(
00593 ConversionType type,
00594 long value,
00595 unsigned base = 10
00596 );
00597 PString(
00598 ConversionType type,
00599 double value,
00600 unsigned places
00601 );
00602
00610 PString & operator=(
00611 const PString & str
00612 );
00613
00623 PString & operator=(
00624 const char * cstr
00625 );
00626
00635 PString & operator=(
00636 char ch
00637 );
00638
00643 PString & operator=(
00644 short n
00645 );
00646
00651 PString & operator=(
00652 unsigned short n
00653 );
00654
00659 PString & operator=(
00660 int n
00661 );
00662
00667 PString & operator=(
00668 unsigned int n
00669 );
00670
00675 PString & operator=(
00676 long n
00677 );
00678
00683 PString & operator=(
00684 unsigned long n
00685 );
00686
00691 PString & operator=(
00692 PInt64 n
00693 );
00694
00699 PString & operator=(
00700 PUInt64 n
00701 );
00702
00705 virtual PString & MakeEmpty();
00706
00709 static PString Empty();
00711
00718 virtual PObject * Clone() const;
00719
00729 virtual Comparison Compare(
00730 const PObject & obj
00731 ) const;
00732
00735 virtual void PrintOn(
00736 ostream & strm
00737 ) const;
00738
00744 virtual void ReadFrom(
00745 istream & strm
00746 );
00747
00761 virtual PINDEX HashFunction() const;
00763
00778 virtual BOOL SetSize(
00779 PINDEX newSize
00780 );
00781
00790 virtual BOOL IsEmpty() const;
00791
00800 virtual BOOL MakeUnique();
00802
00803
00816 BOOL MakeMinimumSize();
00817
00826 PINLINE PINDEX GetLength() const;
00827
00834 bool operator!() const;
00836
00845 PString operator+(
00846 const PString & str
00847 ) const;
00848
00860 PString operator+(
00861 const char * cstr
00862 ) const;
00863
00875 PString operator+(
00876 char ch
00877 ) const;
00878
00890 friend PString operator+(
00891 const char * cstr,
00892 const PString & str
00893 );
00894
00906 friend PString operator+(
00907 char c,
00908 const PString & str
00909 );
00910
00916 PString & operator+=(
00917 const PString & str
00918 );
00919
00929 PString & operator+=(
00930 const char * cstr
00931 );
00932
00942 PString & operator+=(
00943 char ch
00944 );
00945
00946
00953 PString operator&(
00954 const PString & str
00955 ) const;
00956
00973 PString operator&(
00974 const char * cstr
00975 ) const;
00976
00993 PString operator&(
00994 char ch
00995 ) const;
00996
01013 friend PString operator&(
01014 const char * cstr,
01015 const PString & str
01016 );
01017
01034 friend PString operator&(
01035 char ch,
01036 const PString & str
01037 );
01038
01044 PString & operator&=(
01045 const PString & str
01046 );
01047
01062 PString & operator&=(
01063 const char * cstr
01064 );
01065
01066
01081 PString & operator&=(
01082 char ch
01083 );
01085
01086
01094 bool operator*=(
01095 const PString & str
01096 ) const;
01097
01105 bool operator==(
01106 const PObject & str
01107 ) const;
01108
01116 bool operator!=(
01117 const PObject & str
01118 ) const;
01119
01127 bool operator<(
01128 const PObject & str
01129 ) const;
01130
01138 bool operator>(
01139 const PObject & str
01140 ) const;
01141
01149 bool operator<=(
01150 const PObject & str
01151 ) const;
01152
01160 bool operator>=(
01161 const PObject & str
01162 ) const;
01163
01164
01175 bool operator*=(
01176 const char * cstr
01177 ) const;
01178
01189 bool operator==(
01190 const char * cstr
01191 ) const;
01192
01203 bool operator!=(
01204 const char * cstr
01205 ) const;
01206
01217 bool operator<(
01218 const char * cstr
01219 ) const;
01220
01231 bool operator>(
01232 const char * cstr
01233 ) const;
01234
01245 bool operator<=(
01246 const char * cstr
01247 ) const;
01248
01259 bool operator>=(
01260 const char * cstr
01261 ) const;
01262
01274 Comparison NumCompare(
01275 const PString & str,
01276 PINDEX count = P_MAX_INDEX,
01277 PINDEX offset = 0
01278 ) const;
01279
01291 Comparison NumCompare(
01292 const char * cstr,
01293 PINDEX count = P_MAX_INDEX,
01294 PINDEX offset = 0
01295 ) const;
01297
01298
01302 PINDEX Find(
01303 char ch,
01304 PINDEX offset = 0
01305 ) const;
01306
01308 PINDEX Find(
01309 const PString & str,
01310 PINDEX offset = 0
01311 ) const;
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327 PINDEX Find(
01328 const char * cstr,
01329 PINDEX offset = 0
01330 ) const;
01331
01333 PINDEX FindLast(
01334 char ch,
01335 PINDEX offset = P_MAX_INDEX
01336 ) const;
01337
01339 PINDEX FindLast(
01340 const PString & str,
01341 PINDEX offset = P_MAX_INDEX
01342 ) const;
01343
01361 PINDEX FindLast(
01362 const char * cstr,
01363 PINDEX offset = P_MAX_INDEX
01364 ) const;
01365
01367 PINDEX FindOneOf(
01368 const PString & set,
01369 PINDEX offset = 0
01370 ) const;
01371
01386 PINDEX FindOneOf(
01387 const char * cset,
01388 PINDEX offset = 0
01389 ) const;
01390
01401 PINDEX FindRegEx(
01402 const PRegularExpression & regex,
01403 PINDEX offset = 0
01404 ) const;
01405
01416 BOOL FindRegEx(
01417 const PRegularExpression & regex,
01418 PINDEX & pos,
01419 PINDEX & len,
01420 PINDEX offset = 0,
01421 PINDEX maxPos = P_MAX_INDEX
01422 ) const;
01423
01424
01435 void Replace(
01436 const PString & target,
01437 const PString & subs,
01438 BOOL all = FALSE,
01439 PINDEX offset = 0
01440 );
01441
01449 void Splice(
01450 const PString & str,
01451 PINDEX pos,
01452 PINDEX len = 0
01453 );
01454
01462 void Splice(
01463 const char * cstr,
01464 PINDEX pos,
01465 PINDEX len = 0
01466 );
01467
01474 void Delete(
01475 PINDEX start,
01476 PINDEX len
01477 );
01479
01480
01500 PString operator()(
01501 PINDEX start,
01502 PINDEX end
01503 ) const;
01504
01519 PString Left(
01520 PINDEX len
01521 ) const;
01522
01537 PString Right(
01538 PINDEX len
01539 ) const;
01540
01557 PString Mid(
01558 PINDEX start,
01559 PINDEX len = P_MAX_INDEX
01560 ) const;
01561
01562
01570 PString LeftTrim() const;
01571
01579 PString RightTrim() const;
01580
01589 PString Trim() const;
01590
01591
01600 PString ToLower() const;
01601
01610 PString ToUpper() const;
01611
01612
01614 PStringArray Tokenise(
01615 const PString & separators,
01617 BOOL onePerSeparator = TRUE
01619 ) const;
01644 PStringArray Tokenise(
01645 const char * cseparators,
01647 BOOL onePerSeparator = TRUE
01649 ) const;
01650
01664 PStringArray Lines() const;
01666
01683 PString & sprintf(
01684 const char * cfmt,
01685 ...
01686 );
01687
01702 friend PString psprintf(
01703 const char * cfmt,
01704 ...
01705 );
01706
01708 PString & vsprintf(
01709 const PString & fmt,
01710 va_list args
01711 );
01726 PString & vsprintf(
01727 const char * cfmt,
01728 va_list args
01729 );
01730
01732 friend PString pvsprintf(
01733 const char * cfmt,
01734 va_list args
01735 );
01750 friend PString pvsprintf(
01751 const PString & fmt,
01752 va_list args
01753 );
01754
01755
01768 long AsInteger(
01769 unsigned base = 10
01770 ) const;
01783 DWORD AsUnsigned(
01784 unsigned base = 10
01785 ) const;
01799 PInt64 AsInt64(
01800 unsigned base = 10
01801 ) const;
01815 PUInt64 AsUnsigned64(
01816 unsigned base = 10
01817 ) const;
01818
01829 double AsReal() const;
01830
01834 PWORDArray AsUCS2() const;
01835
01846 PBYTEArray ToPascal() const;
01847
01856 PString ToLiteral() const;
01857
01865 operator const unsigned char *() const;
01866
01869 operator std::string () const
01870 { return std::string(theArray); }
01871
01873
01874
01875 protected:
01876 void InternalFromUCS2(
01877 const WORD * ptr,
01878 PINDEX len
01879 );
01880 virtual Comparison InternalCompare(
01881 PINDEX offset,
01882 char c
01883 ) const;
01884 virtual Comparison InternalCompare(
01885 PINDEX offset,
01886 PINDEX length,
01887 const char * cstr
01888 ) const;
01889
01890
01891
01892
01893
01894
01895
01896 PString(int dummy, const PString * str);
01897 };
01898
01899
01900 inline ostream & operator<<(ostream & stream, const PString & string)
01901 {
01902 string.PrintOn(stream);
01903 return stream;
01904 }
01905
01906
01908
01918 class PCaselessString : public PString
01919 {
01920 PCLASSINFO(PCaselessString, PString);
01921
01922 public:
01925 PCaselessString();
01926
01930 PCaselessString(
01931 const char * cstr
01932 );
01933
01938 PCaselessString(
01939 const PString & str
01940 );
01941
01942
01945 PCaselessString(
01946 const std::string & str
01947 ) : PString(str)
01948 { }
01949
01957 PCaselessString & operator=(
01958 const PString & str
01959 );
01960
01970 PCaselessString & operator=(
01971 const char * cstr
01972 );
01973
01982 PCaselessString & operator=(
01983 char ch
01984 );
01985
01986
01987
01992 virtual PObject * Clone() const;
01993
01994 protected:
01995
01996 virtual Comparison InternalCompare(
01997 PINDEX offset,
01998 char c
01999 ) const;
02000 virtual Comparison InternalCompare(
02001 PINDEX offset,
02002 PINDEX length,
02003 const char * cstr
02004 ) const;
02005
02006
02007
02008
02009
02010
02011
02012 PCaselessString(int dummy, const PCaselessString * str);
02013 };
02014
02016
02017 class PStringStream;
02018
02025 class PStringStream : public PString, public iostream
02026 {
02027 PCLASSINFO(PStringStream, PString);
02028
02029 public:
02035 PStringStream();
02036
02041 PStringStream(
02042 PINDEX fixedBufferSize
02043 );
02044
02051 PStringStream(
02052 const PString & str
02053 );
02054
02059 PStringStream(
02060 const char * cstr
02061 );
02062
02065 virtual PString & MakeEmpty();
02066
02078 PStringStream & operator=(
02079 const PStringStream & strm
02080 );
02081
02093 PStringStream & operator=(
02094 const PString & str
02095 );
02096
02112 PStringStream & operator=(
02113 const char * cstr
02114 );
02115
02124 PStringStream & operator=(
02125 char ch
02126 );
02127
02128
02130 virtual ~PStringStream();
02131
02132
02133 protected:
02134 virtual void AssignContents(const PContainer & cont);
02135
02136 private:
02137 PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
02138
02139 class Buffer : public streambuf {
02140 public:
02141 Buffer(PStringStream & str, PINDEX size);
02142 Buffer(const Buffer & sbuf);
02143 Buffer & operator=(const Buffer & sbuf);
02144 virtual int overflow(int=EOF);
02145 virtual int underflow();
02146 virtual int sync();
02147 #ifdef __USE_STL__
02148 virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
02149 virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
02150 #else
02151 virtual streampos seekoff(streamoff, ios::seek_dir, int);
02152 #endif
02153 PStringStream & string;
02154 BOOL fixedBufferSize;
02155 };
02156 };
02157
02158
02159 class PStringList;
02160 class PSortedStringList;
02161
02174 #ifdef DOC_PLUS_PLUS
02175 class PStringArray : public PArray {
02176 #endif
02177 PDECLARE_ARRAY(PStringArray, PString);
02178 public:
02185 PStringArray(
02186 PINDEX count,
02187 char const * const * strarr,
02188 BOOL caseless = FALSE
02189 );
02192 PStringArray(
02193 const PString & str
02194 );
02197 PStringArray(
02198 const PStringList & list
02199 );
02202 PStringArray(
02203 const PSortedStringList & list
02204 );
02205
02209 PStringArray(
02210 const std::vector<PString> & vec
02211 )
02212 {
02213 for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02214 AppendString(*r);
02215 }
02216
02220 PStringArray(
02221 const std::vector<std::string> & vec
02222 )
02223 {
02224 for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02225 AppendString(PString(*r));
02226 }
02227
02231 template <typename stlContainer>
02232 static PStringArray container(
02233 const stlContainer & vec
02234 )
02235 {
02236 PStringArray list;
02237 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02238 list.AppendString(PString(*r));
02239 return list;
02240 }
02241
02243
02251 virtual void ReadFrom(
02252 istream &strm
02253 );
02255
02264 PINDEX GetStringsIndex(
02265 const PString & str
02266 ) const;
02267
02268 PString operator[](
02269 PINDEX index
02270 ) const;
02271
02279 PString & operator[](
02280 PINDEX index
02281 );
02282
02285 PINDEX AppendString(
02286 const PString & str
02287 );
02288
02294 PStringArray & operator +=(const PStringArray & array);
02295 PStringArray & operator +=(const PString & str);
02296
02297
02304 PStringArray operator + (const PStringArray & array);
02305 PStringArray operator + (const PString & str);
02306
02314 char ** ToCharArray(
02315 PCharArray * storage = NULL
02316 ) const;
02318 };
02319
02320
02333 #ifdef DOC_PLUS_PLUS
02334 class PStringList : public PList {
02335 #endif
02336 PDECLARE_LIST(PStringList, PString);
02337 public:
02342 PStringList(
02343 PINDEX count,
02344 char const * const * strarr,
02345 BOOL caseless = FALSE
02346 );
02349 PStringList(
02350 const PString & str
02351 );
02354 PStringList(
02355 const PStringArray & array
02356 );
02359 PStringList(
02360 const PSortedStringList & list
02361 );
02363
02371 virtual void ReadFrom(
02372 istream &strm
02373 );
02375
02380 PINDEX AppendString(
02381 const PString & str
02382 );
02383
02386 PINDEX InsertString(
02387 const PString & before,
02388 const PString & str
02389 );
02390
02394 PINDEX GetStringsIndex(
02395 const PString & str
02396 ) const;
02397
02403 PStringList & operator +=(const PStringList & list);
02404 PStringList & operator +=(const PString & str);
02405
02406
02413 PStringList operator + (const PStringList & array);
02414 PStringList operator + (const PString & str);
02415
02419 template <typename stlContainer>
02420 static PStringList container(
02421 const stlContainer & vec
02422 )
02423 {
02424 PStringList list;
02425 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02426 list.AppendString(PString(*r));
02427 return list;
02428 }
02430 };
02431
02432
02445 #ifdef DOC_PLUS_PLUS
02446 class PSortedStringList : public PSortedList {
02447 #endif
02448 PDECLARE_SORTED_LIST(PSortedStringList, PString);
02449 public:
02454 PSortedStringList(
02455 PINDEX count,
02456 char const * const * strarr,
02457 BOOL caseless = FALSE
02458 );
02461 PSortedStringList(
02462 const PString & str
02463 );
02466 PSortedStringList(
02467 const PStringArray & array
02468 );
02471 PSortedStringList(
02472 const PStringList & list
02473 );
02475
02483 virtual void ReadFrom(
02484 istream &strm
02485 );
02487
02493 PINDEX AppendString(
02494 const PString & str
02495 );
02496
02500 PINDEX GetStringsIndex(
02501 const PString & str
02502 ) const;
02503
02508 PINDEX GetNextStringsIndex(
02509 const PString & str
02510 ) const;
02512
02513 protected:
02514 PINDEX InternalStringSelect(
02515 const char * str,
02516 PINDEX len,
02517 Element * thisElement
02518 ) const;
02519 };
02520
02521
02538 #ifdef DOC_PLUS_PLUS
02539 class PStringSet : public PSet {
02540 #endif
02541 PDECLARE_SET(PStringSet, PString, TRUE);
02542 public:
02547 PStringSet(
02548 PINDEX count,
02549 char const * const * strarr,
02550 BOOL caseless = FALSE
02551 );
02554 PStringSet(
02555 const PString & str
02556 );
02558
02566 virtual void ReadFrom(
02567 istream &strm
02568 );
02570
02574 void Include(
02575 const PString & key
02576 );
02578 PStringSet & operator+=(
02579 const PString & key
02580 );
02582 void Exclude(
02583 const PString & key
02584 );
02586 PStringSet & operator-=(
02587 const PString & key
02588 );
02590 };
02591
02592
02593 #ifdef PHAS_TEMPLATES
02594
02602 template <class K> class PStringDictionary : public PAbstractDictionary
02603 {
02604 PCLASSINFO(PStringDictionary, PAbstractDictionary);
02605
02606 public:
02615 PStringDictionary()
02616 : PAbstractDictionary() { }
02618
02625 virtual PObject * Clone() const
02626 { return PNEW PStringDictionary(0, this); }
02628
02643 const PString & operator[](const K & key) const
02644 { return (const PString &)GetRefAt(key); }
02645
02659 PString operator()(const K & key, const char * dflt = "") const
02660 { if (AbstractContains(key)) return (*this)[key]; return dflt; }
02661
02670 BOOL Contains(
02671 const K & key
02672 ) const { return AbstractContains(key); }
02673
02685 virtual PString * RemoveAt(
02686 const K & key
02687 ) {
02688 PString * s = GetAt(key); AbstractSetAt(key, NULL);
02689 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s;
02690 }
02691
02698 virtual PString * GetAt(
02699 const K & key
02700 ) const { return (PString *)AbstractGetAt(key); }
02701
02710 virtual BOOL SetDataAt(
02711 PINDEX index,
02712 const PString & str
02713 ) { return PAbstractDictionary::SetDataAt(index, PNEW PString(str)); }
02714
02726 virtual BOOL SetAt(
02727 const K & key,
02728 const PString & str
02729 ) { return AbstractSetAt(key, PNEW PString(str)); }
02730
02742 const K & GetKeyAt(PINDEX index) const
02743 { return (const K &)AbstractGetKeyAt(index); }
02744
02756 PString & GetDataAt(PINDEX index) const
02757 { return (PString &)AbstractGetDataAt(index); }
02759
02760 protected:
02761 PStringDictionary(int dummy, const PStringDictionary * c)
02762 : PAbstractDictionary(dummy, c) { }
02763 };
02764
02765
02780 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02781 PDECLARE_CLASS(cls, PStringDictionary<K>) \
02782 protected: \
02783 cls(int dummy, const cls * c) \
02784 : PStringDictionary<K>(dummy, c) { } \
02785 public: \
02786 cls() \
02787 : PStringDictionary<K>() { } \
02788 virtual PObject * Clone() const \
02789 { return PNEW cls(0, this); } \
02790
02791
02804 #define PSTRING_DICTIONARY(cls, K) typedef PStringDictionary<K> cls
02805
02806
02807 #else // PHAS_TEMPLATES
02808
02809
02810 #define PSTRING_DICTIONARY(cls, K) \
02811 class cls : public PAbstractDictionary { \
02812 PCLASSINFO(cls, PAbstractDictionary) \
02813 protected: \
02814 inline cls(int dummy, const cls * c) \
02815 : PAbstractDictionary(dummy, c) { } \
02816 public: \
02817 inline cls() \
02818 : PAbstractDictionary() { } \
02819 inline PObject * Clone() const \
02820 { return PNEW cls(0, this); } \
02821 inline PString & operator[](const K & key) const \
02822 { return (PString &)GetRefAt(key); } \
02823 inline PString operator()(const K & key, const char * dflt = "") const \
02824 { if (Contains(key)) return (PString &)GetRefAt(key); return dflt; } \
02825 virtual BOOL Contains(const K & key) const \
02826 { return AbstractContains(key); } \
02827 virtual PString * RemoveAt(const K & key) \
02828 { PString * s = GetAt(key); AbstractSetAt(key, NULL); \
02829 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s; } \
02830 virtual PString * GetAt(const K & key) const \
02831 { return (PString *)AbstractGetAt(key); } \
02832 virtual BOOL SetDataAt(PINDEX index, const PString & str) \
02833 { return PAbstractDictionary::SetDataAt(index,PNEW PString(str));} \
02834 virtual BOOL SetAt(const K & key, const PString & str) \
02835 { return AbstractSetAt(key, PNEW PString(str)); } \
02836 inline const K & GetKeyAt(PINDEX index) const \
02837 { return (const K &)AbstractGetKeyAt(index); } \
02838 inline PString & GetDataAt(PINDEX index) const \
02839 { return (PString &)AbstractGetDataAt(index); } \
02840 }
02841
02842 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02843 PSTRING_DICTIONARY(cls##_PTemplate, K); \
02844 PDECLARE_CLASS(cls, cls##_PTemplate) \
02845 protected: \
02846 cls(int dummy, const cls * c) \
02847 : cls##_PTemplate(dummy, c) { } \
02848 public: \
02849 cls() \
02850 : cls##_PTemplate() { } \
02851 virtual PObject * Clone() const \
02852 { return PNEW cls(0, this); } \
02853
02854 #endif // PHAS_TEMPLATES
02855
02856
02871 #ifdef DOC_PLUS_PLUS
02872 class POrdinalToString : public PStringDictionary {
02873 #endif
02874 PDECLARE_STRING_DICTIONARY(POrdinalToString, POrdinalKey);
02875 public:
02878
02879 struct Initialiser {
02881 PINDEX key;
02883 const char * value;
02884 };
02887 POrdinalToString(
02888 PINDEX count,
02889 const Initialiser * init
02890 );
02892
02900 virtual void ReadFrom(
02901 istream &strm
02902 );
02904 };
02905
02918 #ifdef DOC_PLUS_PLUS
02919 class PStringToOrdinal : public POrdinalDictionary {
02920 #endif
02921 PDECLARE_ORDINAL_DICTIONARY(PStringToOrdinal, PString);
02922 public:
02925
02926 struct Initialiser {
02928 const char * key;
02930 PINDEX value;
02931 };
02934 PStringToOrdinal(
02935 PINDEX count,
02936 const Initialiser * init,
02937 BOOL caseless = FALSE
02938 );
02940
02948 virtual void ReadFrom(
02949 istream &strm
02950 );
02952 };
02953
02954
02968 #ifdef DOC_PLUS_PLUS
02969 class PStringToString : public PStringDictionary {
02970 #endif
02971 PDECLARE_STRING_DICTIONARY(PStringToString, PString);
02972 public:
02975
02976 struct Initialiser {
02978 const char * key;
02980 const char * value;
02981 };
02984 PStringToString(
02985 PINDEX count,
02986 const Initialiser * init,
02987 BOOL caselessKeys = FALSE,
02988 BOOL caselessValues = FALSE
02989 );
02991
02999 virtual void ReadFrom(
03000 istream &strm
03001 );
03003 };
03004
03005
03011 class PRegularExpression : public PObject
03012 {
03013 PCLASSINFO(PRegularExpression, PObject);
03014
03015 public:
03018
03019 enum {
03021 Extended = 1,
03023 IgnoreCase = 2,
03028 AnchorNewLine = 4
03029 };
03031 enum {
03038 NotBeginningOfLine = 1,
03040 NotEndofLine = 2
03041 };
03042
03044 PRegularExpression();
03045
03048 PRegularExpression(
03049 const PString & pattern,
03050 int flags = IgnoreCase
03051 );
03052
03055 PRegularExpression(
03056 const char * cpattern,
03057 int flags = IgnoreCase
03058 );
03059
03063 PRegularExpression(
03064 const PRegularExpression &
03065 );
03066
03070 PRegularExpression & operator =(
03071 const PRegularExpression &
03072 );
03073
03075 ~PRegularExpression();
03077
03080
03081 enum ErrorCodes {
03083 NoError = 0,
03085 NoMatch,
03086
03087
03089 BadPattern,
03091 CollateError,
03093 BadClassType,
03095 BadEscape,
03097 BadSubReg,
03099 UnmatchedBracket,
03101 UnmatchedParen,
03103 UnmatchedBrace,
03105 BadBR,
03107 RangeError,
03109 OutOfMemory,
03111 BadRepitition,
03112
03113
03115 PrematureEnd,
03117 TooBig,
03119 UnmatchedRParen,
03121 NotCompiled
03122 };
03123
03129 ErrorCodes GetErrorCode() const;
03130
03137 PString GetErrorText() const;
03139
03143 BOOL Compile(
03144 const PString & pattern,
03145 int flags = IgnoreCase
03146 );
03154 BOOL Compile(
03155 const char * cpattern,
03156 int flags = IgnoreCase
03157 );
03158
03159
03161 BOOL Execute(
03162 const PString & str,
03163 PINDEX & start,
03164 int flags = 0
03165 ) const;
03167 BOOL Execute(
03168 const PString & str,
03169 PINDEX & start,
03170 PINDEX & len,
03171 int flags = 0
03172 ) const;
03174 BOOL Execute(
03175 const char * cstr,
03176 PINDEX & start,
03177 int flags = 0
03178 ) const;
03180 BOOL Execute(
03181 const char * cstr,
03182 PINDEX & start,
03183 PINDEX & len,
03184 int flags = 0
03185 ) const;
03187 BOOL Execute(
03188 const PString & str,
03189 PIntArray & starts,
03190 int flags = 0
03191 ) const;
03193 BOOL Execute(
03194 const PString & str,
03195 PIntArray & starts,
03196 PIntArray & ends,
03197 int flags = 0
03198 ) const;
03200 BOOL Execute(
03201 const char * cstr,
03202 PIntArray & starts,
03203 int flags = 0
03204 ) const;
03220 BOOL Execute(
03221 const char * cstr,
03222 PIntArray & starts,
03223 PIntArray & ends,
03224 int flags = 0
03225 ) const;
03227
03236 static PString EscapeString(
03237 const PString & str
03238 );
03240
03241 protected:
03242 PString patternSaved;
03243 int flagsSaved;
03244
03245 void * expression;
03246 int lastError;
03247 };
03248
03249 PString psprintf(const char * cfmt, ...);
03250
03251 #endif // #ifndef __PSTRING__
03252