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 #ifdef P_USE_PRAGMA
00311 #pragma interface
00312 #endif
00313
00314 #include <string>
00315 #include <vector>
00316
00318
00319
00320 class PStringArray;
00321 class PRegularExpression;
00322
00357 class PString : public PCharArray {
00358 PCLASSINFO(PString, PCharArray);
00359
00360
00361
00362 public:
00368 PINLINE PString();
00369
00373 PINLINE PString(
00374 const PString & str
00375 );
00376
00379 PINLINE PString(
00380 const std::string & str
00381 );
00382
00391 PString(
00392 const char * cstr
00393 );
00394
00399 PString(
00400 const WORD * ustr
00401 );
00402
00416 PString(
00417 const char * cstr,
00418 PINDEX len
00419 );
00420
00431 PString(
00432 const WORD * ustr,
00433 PINDEX len
00434 );
00435
00446 PString(
00447 const PWORDArray & ustr
00448 );
00449
00458 PString(
00459 char ch
00460 );
00461
00466 PString(
00467 short n
00468 );
00469
00474 PString(
00475 unsigned short n
00476 );
00477
00482 PString(
00483 int n
00484 );
00485
00490 PString(
00491 unsigned int n
00492 );
00493
00498 PString(
00499 long n
00500 );
00501
00506 PString(
00507 unsigned long n
00508 );
00509
00514 PString(
00515 PInt64 n
00516 );
00517
00522 PString(
00523 PUInt64 n
00524 );
00525
00526
00527 enum ConversionType {
00528 Pascal,
00529 Basic,
00530 Literal,
00531 Signed,
00532 Unsigned,
00533 Decimal,
00534 Exponent,
00535 Printf,
00536 NumConversionTypes
00537 };
00538
00539
00540
00541
00542
00543
00544 PString(
00545 ConversionType type,
00546 const char * str,
00547 ...
00548 );
00549 PString(
00550 ConversionType type,
00551 long value,
00552 unsigned base = 10
00553 );
00554 PString(
00555 ConversionType type,
00556 double value,
00557 unsigned places
00558 );
00559
00567 PString & operator=(
00568 const PString & str
00569 );
00570
00580 PString & operator=(
00581 const char * cstr
00582 );
00583
00592 PString & operator=(
00593 char ch
00594 );
00595
00600 PString & operator=(
00601 short n
00602 );
00603
00608 PString & operator=(
00609 unsigned short n
00610 );
00611
00616 PString & operator=(
00617 int n
00618 );
00619
00624 PString & operator=(
00625 unsigned int n
00626 );
00627
00632 PString & operator=(
00633 long n
00634 );
00635
00640 PString & operator=(
00641 unsigned long n
00642 );
00643
00648 PString & operator=(
00649 PInt64 n
00650 );
00651
00656 PString & operator=(
00657 PUInt64 n
00658 );
00659
00662 virtual PString & MakeEmpty();
00663
00666 static PString Empty();
00668
00675 virtual PObject * Clone() const;
00676
00686 virtual Comparison Compare(
00687 const PObject & obj
00688 ) const;
00689
00692 virtual void PrintOn(
00693 ostream & strm
00694 ) const;
00695
00701 virtual void ReadFrom(
00702 istream & strm
00703 );
00704
00718 virtual PINDEX HashFunction() const;
00720
00735 virtual BOOL SetSize(
00736 PINDEX newSize
00737 );
00738
00747 virtual BOOL IsEmpty() const;
00748
00757 virtual BOOL MakeUnique();
00759
00760
00773 BOOL MakeMinimumSize();
00774
00783 PINLINE PINDEX GetLength() const;
00784
00791 bool operator!() const;
00793
00802 PString operator+(
00803 const PString & str
00804 ) const;
00805
00817 PString operator+(
00818 const char * cstr
00819 ) const;
00820
00832 PString operator+(
00833 char ch
00834 ) const;
00835
00847 friend PString operator+(
00848 const char * cstr,
00849 const PString & str
00850 );
00851
00863 friend PString operator+(
00864 char c,
00865 const PString & str
00866 );
00867
00873 PString & operator+=(
00874 const PString & str
00875 );
00876
00886 PString & operator+=(
00887 const char * cstr
00888 );
00889
00899 PString & operator+=(
00900 char ch
00901 );
00902
00903
00910 PString operator&(
00911 const PString & str
00912 ) const;
00913
00930 PString operator&(
00931 const char * cstr
00932 ) const;
00933
00950 PString operator&(
00951 char ch
00952 ) const;
00953
00970 friend PString operator&(
00971 const char * cstr,
00972 const PString & str
00973 );
00974
00991 friend PString operator&(
00992 char ch,
00993 const PString & str
00994 );
00995
01001 PString & operator&=(
01002 const PString & str
01003 );
01004
01019 PString & operator&=(
01020 const char * cstr
01021 );
01022
01023
01038 PString & operator&=(
01039 char ch
01040 );
01042
01043
01051 bool operator*=(
01052 const PString & str
01053 ) const;
01054
01062 bool operator==(
01063 const PObject & str
01064 ) const;
01065
01073 bool operator!=(
01074 const PObject & str
01075 ) const;
01076
01084 bool operator<(
01085 const PObject & str
01086 ) const;
01087
01095 bool operator>(
01096 const PObject & str
01097 ) const;
01098
01106 bool operator<=(
01107 const PObject & str
01108 ) const;
01109
01117 bool operator>=(
01118 const PObject & str
01119 ) const;
01120
01121
01132 bool operator*=(
01133 const char * cstr
01134 ) const;
01135
01146 bool operator==(
01147 const char * cstr
01148 ) const;
01149
01160 bool operator!=(
01161 const char * cstr
01162 ) const;
01163
01174 bool operator<(
01175 const char * cstr
01176 ) const;
01177
01188 bool operator>(
01189 const char * cstr
01190 ) const;
01191
01202 bool operator<=(
01203 const char * cstr
01204 ) const;
01205
01216 bool operator>=(
01217 const char * cstr
01218 ) const;
01219
01231 Comparison NumCompare(
01232 const PString & str,
01233 PINDEX count = P_MAX_INDEX,
01234 PINDEX offset = 0
01235 ) const;
01236
01248 Comparison NumCompare(
01249 const char * cstr,
01250 PINDEX count = P_MAX_INDEX,
01251 PINDEX offset = 0
01252 ) const;
01254
01255
01259 PINDEX Find(
01260 char ch,
01261 PINDEX offset = 0
01262 ) const;
01263
01265 PINDEX Find(
01266 const PString & str,
01267 PINDEX offset = 0
01268 ) const;
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284 PINDEX Find(
01285 const char * cstr,
01286 PINDEX offset = 0
01287 ) const;
01288
01290 PINDEX FindLast(
01291 char ch,
01292 PINDEX offset = P_MAX_INDEX
01293 ) const;
01294
01296 PINDEX FindLast(
01297 const PString & str,
01298 PINDEX offset = P_MAX_INDEX
01299 ) const;
01300
01318 PINDEX FindLast(
01319 const char * cstr,
01320 PINDEX offset = P_MAX_INDEX
01321 ) const;
01322
01324 PINDEX FindOneOf(
01325 const PString & set,
01326 PINDEX offset = 0
01327 ) const;
01328
01343 PINDEX FindOneOf(
01344 const char * cset,
01345 PINDEX offset = 0
01346 ) const;
01347
01358 PINDEX FindRegEx(
01359 const PRegularExpression & regex,
01360 PINDEX offset = 0
01361 ) const;
01362
01373 BOOL FindRegEx(
01374 const PRegularExpression & regex,
01375 PINDEX & pos,
01376 PINDEX & len,
01377 PINDEX offset = 0,
01378 PINDEX maxPos = P_MAX_INDEX
01379 ) const;
01380
01381
01392 void Replace(
01393 const PString & target,
01394 const PString & subs,
01395 BOOL all = FALSE,
01396 PINDEX offset = 0
01397 );
01398
01406 void Splice(
01407 const PString & str,
01408 PINDEX pos,
01409 PINDEX len = 0
01410 );
01411
01419 void Splice(
01420 const char * cstr,
01421 PINDEX pos,
01422 PINDEX len = 0
01423 );
01424
01431 void Delete(
01432 PINDEX start,
01433 PINDEX len
01434 );
01436
01437
01457 PString operator()(
01458 PINDEX start,
01459 PINDEX end
01460 ) const;
01461
01476 PString Left(
01477 PINDEX len
01478 ) const;
01479
01494 PString Right(
01495 PINDEX len
01496 ) const;
01497
01514 PString Mid(
01515 PINDEX start,
01516 PINDEX len = P_MAX_INDEX
01517 ) const;
01518
01519
01527 PString LeftTrim() const;
01528
01536 PString RightTrim() const;
01537
01546 PString Trim() const;
01547
01548
01557 PString ToLower() const;
01558
01567 PString ToUpper() const;
01568
01569
01571 PStringArray Tokenise(
01572 const PString & separators,
01574 BOOL onePerSeparator = TRUE
01576 ) const;
01599 PStringArray Tokenise(
01600 const char * cseparators,
01602 BOOL onePerSeparator = TRUE
01604 ) const;
01605
01619 PStringArray Lines() const;
01621
01638 PString & sprintf(
01639 const char * cfmt,
01640 ...
01641 );
01642
01657 friend PString psprintf(
01658 const char * cfmt,
01659 ...
01660 );
01661
01663 PString & vsprintf(
01664 const PString & fmt,
01665 va_list args
01666 );
01681 PString & vsprintf(
01682 const char * cfmt,
01683 va_list args
01684 );
01685
01687 friend PString pvsprintf(
01688 const char * cfmt,
01689 va_list args
01690 );
01705 friend PString pvsprintf(
01706 const PString & fmt,
01707 va_list args
01708 );
01709
01710
01723 long AsInteger(
01724 unsigned base = 10
01725 ) const;
01738 DWORD AsUnsigned(
01739 unsigned base = 10
01740 ) const;
01754 PInt64 AsInt64(
01755 unsigned base = 10
01756 ) const;
01770 PUInt64 AsUnsigned64(
01771 unsigned base = 10
01772 ) const;
01773
01784 double AsReal() const;
01785
01789 PWORDArray AsUCS2() const;
01790
01801 PBYTEArray ToPascal() const;
01802
01811 PString ToLiteral() const;
01812
01820 operator const unsigned char *() const;
01821
01823
01824
01825 protected:
01826 void InternalFromUCS2(
01827 const WORD * ptr,
01828 PINDEX len
01829 );
01830 virtual Comparison InternalCompare(
01831 PINDEX offset,
01832 char c
01833 ) const;
01834 virtual Comparison InternalCompare(
01835 PINDEX offset,
01836 PINDEX length,
01837 const char * cstr
01838 ) const;
01839
01840
01841
01842
01843
01844
01845
01846 PString(int dummy, const PString * str);
01847 };
01848
01849
01851
01861 class PCaselessString : public PString
01862 {
01863 PCLASSINFO(PCaselessString, PString);
01864
01865 public:
01868 PCaselessString();
01869
01873 PCaselessString(
01874 const char * cstr
01875 );
01876
01881 PCaselessString(
01882 const PString & str
01883 );
01884
01885
01893 PCaselessString & operator=(
01894 const PString & str
01895 );
01896
01906 PCaselessString & operator=(
01907 const char * cstr
01908 );
01909
01918 PCaselessString & operator=(
01919 char ch
01920 );
01921
01922
01923
01928 virtual PObject * Clone() const;
01929
01930 protected:
01931
01932 virtual Comparison InternalCompare(
01933 PINDEX offset,
01934 char c
01935 ) const;
01936 virtual Comparison InternalCompare(
01937 PINDEX offset,
01938 PINDEX length,
01939 const char * cstr
01940 ) const;
01941
01942
01943
01944
01945
01946
01947
01948 PCaselessString(int dummy, const PCaselessString * str);
01949 };
01950
01952
01953 class PStringStream;
01954
01961 class PStringStream : public PString, public iostream
01962 {
01963 PCLASSINFO(PStringStream, PString);
01964
01965 public:
01971 PStringStream();
01972
01977 PStringStream(
01978 PINDEX fixedBufferSize
01979 );
01980
01987 PStringStream(
01988 const PString & str
01989 );
01990
01995 PStringStream(
01996 const char * cstr
01997 );
01998
02001 virtual PString & MakeEmpty();
02002
02014 PStringStream & operator=(
02015 const PStringStream & strm
02016 );
02017
02029 PStringStream & operator=(
02030 const PString & str
02031 );
02032
02048 PStringStream & operator=(
02049 const char * cstr
02050 );
02051
02060 PStringStream & operator=(
02061 char ch
02062 );
02063
02064
02066 virtual ~PStringStream();
02067
02068
02069 protected:
02070 virtual void AssignContents(const PContainer & cont);
02071
02072 private:
02073 PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
02074
02075 class Buffer : public streambuf {
02076 public:
02077 Buffer(PStringStream & str, PINDEX size);
02078 Buffer(const Buffer & sbuf);
02079 Buffer & operator=(const Buffer & sbuf);
02080 virtual int overflow(int=EOF);
02081 virtual int underflow();
02082 virtual int sync();
02083 #if __USE_STL__
02084 virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
02085 virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
02086 #else
02087 virtual streampos seekoff(streamoff, ios::seek_dir, int);
02088 #endif
02089 PStringStream & string;
02090 BOOL fixedBufferSize;
02091 };
02092 };
02093
02094
02095 class PStringList;
02096 class PSortedStringList;
02097
02110 #ifdef DOC_PLUS_PLUS
02111 class PStringArray : public PArray {
02112 #endif
02113 PDECLARE_ARRAY(PStringArray, PString);
02114 public:
02121 PStringArray(
02122 PINDEX count,
02123 char const * const * strarr,
02124 BOOL caseless = FALSE
02125 );
02128 PStringArray(
02129 const PString & str
02130 );
02133 PStringArray(
02134 const PStringList & list
02135 );
02138 PStringArray(
02139 const PSortedStringList & list
02140 );
02141
02145 PStringArray(
02146 const std::vector<PString> & vec
02147 )
02148 {
02149 for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02150 AppendString(*r);
02151 }
02152
02156 PStringArray(
02157 const std::vector<std::string> & vec
02158 )
02159 {
02160 for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02161 AppendString(PString(*r));
02162 }
02163
02167 template <typename stlContainer>
02168 static PStringArray container(
02169 const stlContainer & vec
02170 )
02171 {
02172 PStringArray list;
02173 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02174 list.AppendString(PString(*r));
02175 return list;
02176 }
02177
02179
02187 virtual void ReadFrom(
02188 istream &strm
02189 );
02191
02200 PINDEX GetStringsIndex(
02201 const PString & str
02202 ) const;
02203
02204 PString operator[](
02205 PINDEX index
02206 ) const;
02207
02215 PString & operator[](
02216 PINDEX index
02217 );
02218
02221 PINDEX AppendString(
02222 const PString & str
02223 );
02224
02230 PStringArray & operator +=(const PStringArray & array);
02231 PStringArray & operator +=(const PString & str);
02232
02233
02240 PStringArray operator + (const PStringArray & array);
02241 PStringArray operator + (const PString & str);
02242
02250 char ** ToCharArray(
02251 PCharArray * storage = NULL
02252 ) const;
02254 };
02255
02256
02269 #ifdef DOC_PLUS_PLUS
02270 class PStringList : public PList {
02271 #endif
02272 PDECLARE_LIST(PStringList, PString);
02273 public:
02278 PStringList(
02279 PINDEX count,
02280 char const * const * strarr,
02281 BOOL caseless = FALSE
02282 );
02285 PStringList(
02286 const PString & str
02287 );
02290 PStringList(
02291 const PStringArray & array
02292 );
02295 PStringList(
02296 const PSortedStringList & list
02297 );
02299
02307 virtual void ReadFrom(
02308 istream &strm
02309 );
02311
02316 PINDEX AppendString(
02317 const PString & str
02318 );
02319
02322 PINDEX InsertString(
02323 const PString & before,
02324 const PString & str
02325 );
02326
02330 PINDEX GetStringsIndex(
02331 const PString & str
02332 ) const;
02333
02339 PStringList & operator +=(const PStringList & list);
02340 PStringList & operator +=(const PString & str);
02341
02342
02349 PStringList operator + (const PStringList & array);
02350 PStringList operator + (const PString & str);
02351
02355 template <typename stlContainer>
02356 static PStringList container(
02357 const stlContainer & vec
02358 )
02359 {
02360 PStringList list;
02361 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02362 list.AppendString(PString(*r));
02363 return list;
02364 }
02366 };
02367
02368
02381 #ifdef DOC_PLUS_PLUS
02382 class PSortedStringList : public PSortedList {
02383 #endif
02384 PDECLARE_SORTED_LIST(PSortedStringList, PString);
02385 public:
02390 PSortedStringList(
02391 PINDEX count,
02392 char const * const * strarr,
02393 BOOL caseless = FALSE
02394 );
02397 PSortedStringList(
02398 const PString & str
02399 );
02402 PSortedStringList(
02403 const PStringArray & array
02404 );
02407 PSortedStringList(
02408 const PStringList & list
02409 );
02411
02419 virtual void ReadFrom(
02420 istream &strm
02421 );
02423
02429 PINDEX AppendString(
02430 const PString & str
02431 );
02432
02436 PINDEX GetStringsIndex(
02437 const PString & str
02438 ) const;
02439
02444 PINDEX GetNextStringsIndex(
02445 const PString & str
02446 ) const;
02448
02449 protected:
02450 PINDEX InternalStringSelect(
02451 const char * str,
02452 PINDEX len,
02453 Element * thisElement
02454 ) const;
02455 };
02456
02457
02474 #ifdef DOC_PLUS_PLUS
02475 class PStringSet : public PSet {
02476 #endif
02477 PDECLARE_SET(PStringSet, PString, TRUE);
02478 public:
02483 PStringSet(
02484 PINDEX count,
02485 char const * const * strarr,
02486 BOOL caseless = FALSE
02487 );
02490 PStringSet(
02491 const PString & str
02492 );
02494
02502 virtual void ReadFrom(
02503 istream &strm
02504 );
02506
02510 void Include(
02511 const PString & key
02512 );
02514 PStringSet & operator+=(
02515 const PString & key
02516 );
02518 void Exclude(
02519 const PString & key
02520 );
02522 PStringSet & operator-=(
02523 const PString & key
02524 );
02526 };
02527
02528
02529 #ifdef PHAS_TEMPLATES
02530
02538 template <class K> class PStringDictionary : public PAbstractDictionary
02539 {
02540 PCLASSINFO(PStringDictionary, PAbstractDictionary);
02541
02542 public:
02551 PStringDictionary()
02552 : PAbstractDictionary() { }
02554
02561 virtual PObject * Clone() const
02562 { return PNEW PStringDictionary(0, this); }
02564
02579 const PString & operator[](const K & key) const
02580 { return (const PString &)GetRefAt(key); }
02581
02595 PString operator()(const K & key, const char * dflt = "") const
02596 { if (AbstractContains(key)) return (*this)[key]; return dflt; }
02597
02606 BOOL Contains(
02607 const K & key
02608 ) const { return AbstractContains(key); }
02609
02621 virtual PString * RemoveAt(
02622 const K & key
02623 ) {
02624 PString * s = GetAt(key); AbstractSetAt(key, NULL);
02625 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s;
02626 }
02627
02634 virtual PString * GetAt(
02635 const K & key
02636 ) const { return (PString *)AbstractGetAt(key); }
02637
02646 virtual BOOL SetDataAt(
02647 PINDEX index,
02648 const PString & str
02649 ) { return PAbstractDictionary::SetDataAt(index, PNEW PString(str)); }
02650
02662 virtual BOOL SetAt(
02663 const K & key,
02664 const PString & str
02665 ) { return AbstractSetAt(key, PNEW PString(str)); }
02666
02678 const K & GetKeyAt(PINDEX index) const
02679 { return (const K &)AbstractGetKeyAt(index); }
02680
02692 PString & GetDataAt(PINDEX index) const
02693 { return (PString &)AbstractGetDataAt(index); }
02695
02696 protected:
02697 PStringDictionary(int dummy, const PStringDictionary * c)
02698 : PAbstractDictionary(dummy, c) { }
02699 };
02700
02701
02716 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02717 PDECLARE_CLASS(cls, PStringDictionary<K>) \
02718 protected: \
02719 cls(int dummy, const cls * c) \
02720 : PStringDictionary<K>(dummy, c) { } \
02721 public: \
02722 cls() \
02723 : PStringDictionary<K>() { } \
02724 virtual PObject * Clone() const \
02725 { return PNEW cls(0, this); } \
02726
02727
02740 #define PSTRING_DICTIONARY(cls, K) typedef PStringDictionary<K> cls
02741
02742
02743 #else // PHAS_TEMPLATES
02744
02745
02746 #define PSTRING_DICTIONARY(cls, K) \
02747 class cls : public PAbstractDictionary { \
02748 PCLASSINFO(cls, PAbstractDictionary) \
02749 protected: \
02750 inline cls(int dummy, const cls * c) \
02751 : PAbstractDictionary(dummy, c) { } \
02752 public: \
02753 inline cls() \
02754 : PAbstractDictionary() { } \
02755 inline PObject * Clone() const \
02756 { return PNEW cls(0, this); } \
02757 inline PString & operator[](const K & key) const \
02758 { return (PString &)GetRefAt(key); } \
02759 inline PString operator()(const K & key, const char * dflt = "") const \
02760 { if (Contains(key)) return (PString &)GetRefAt(key); return dflt; } \
02761 virtual BOOL Contains(const K & key) const \
02762 { return AbstractContains(key); } \
02763 virtual PString * RemoveAt(const K & key) \
02764 { PString * s = GetAt(key); AbstractSetAt(key, NULL); \
02765 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s; } \
02766 virtual PString * GetAt(const K & key) const \
02767 { return (PString *)AbstractGetAt(key); } \
02768 virtual BOOL SetDataAt(PINDEX index, const PString & str) \
02769 { return PAbstractDictionary::SetDataAt(index,PNEW PString(str));} \
02770 virtual BOOL SetAt(const K & key, const PString & str) \
02771 { return AbstractSetAt(key, PNEW PString(str)); } \
02772 inline const K & GetKeyAt(PINDEX index) const \
02773 { return (const K &)AbstractGetKeyAt(index); } \
02774 inline PString & GetDataAt(PINDEX index) const \
02775 { return (PString &)AbstractGetDataAt(index); } \
02776 }
02777
02778 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02779 PSTRING_DICTIONARY(cls##_PTemplate, K); \
02780 PDECLARE_CLASS(cls, cls##_PTemplate) \
02781 protected: \
02782 cls(int dummy, const cls * c) \
02783 : cls##_PTemplate(dummy, c) { } \
02784 public: \
02785 cls() \
02786 : cls##_PTemplate() { } \
02787 virtual PObject * Clone() const \
02788 { return PNEW cls(0, this); } \
02789
02790 #endif // PHAS_TEMPLATES
02791
02792
02807 #ifdef DOC_PLUS_PLUS
02808 class POrdinalToString : public PStringDictionary {
02809 #endif
02810 PDECLARE_STRING_DICTIONARY(POrdinalToString, POrdinalKey);
02811 public:
02814
02815 struct Initialiser {
02817 PINDEX key;
02819 const char * value;
02820 };
02823 POrdinalToString(
02824 PINDEX count,
02825 const Initialiser * init
02826 );
02828
02836 virtual void ReadFrom(
02837 istream &strm
02838 );
02840 };
02841
02854 #ifdef DOC_PLUS_PLUS
02855 class PStringToOrdinal : public POrdinalDictionary {
02856 #endif
02857 PDECLARE_ORDINAL_DICTIONARY(PStringToOrdinal, PString);
02858 public:
02861
02862 struct Initialiser {
02864 const char * key;
02866 PINDEX value;
02867 };
02870 PStringToOrdinal(
02871 PINDEX count,
02872 const Initialiser * init,
02873 BOOL caseless = FALSE
02874 );
02876
02884 virtual void ReadFrom(
02885 istream &strm
02886 );
02888 };
02889
02890
02904 #ifdef DOC_PLUS_PLUS
02905 class PStringToString : public PStringDictionary {
02906 #endif
02907 PDECLARE_STRING_DICTIONARY(PStringToString, PString);
02908 public:
02911
02912 struct Initialiser {
02914 const char * key;
02916 const char * value;
02917 };
02920 PStringToString(
02921 PINDEX count,
02922 const Initialiser * init,
02923 BOOL caselessKeys = FALSE,
02924 BOOL caselessValues = FALSE
02925 );
02927
02935 virtual void ReadFrom(
02936 istream &strm
02937 );
02939 };
02940
02941
02947 class PRegularExpression : public PObject
02948 {
02949 PCLASSINFO(PRegularExpression, PObject);
02950
02951 public:
02954
02955 enum {
02957 Extended = 1,
02959 IgnoreCase = 2,
02964 AnchorNewLine = 4
02965 };
02967 enum {
02974 NotBeginningOfLine = 1,
02976 NotEndofLine = 2
02977 };
02978
02980 PRegularExpression();
02981
02984 PRegularExpression(
02985 const PString & pattern,
02986 int flags = IgnoreCase
02987 );
02988
02991 PRegularExpression(
02992 const char * cpattern,
02993 int flags = IgnoreCase
02994 );
02995
02999 PRegularExpression(
03000 const PRegularExpression &
03001 );
03002
03006 PRegularExpression & operator =(
03007 const PRegularExpression &
03008 );
03009
03011 ~PRegularExpression();
03013
03016
03017 enum ErrorCodes {
03019 NoError = 0,
03021 NoMatch,
03022
03023
03025 BadPattern,
03027 CollateError,
03029 BadClassType,
03031 BadEscape,
03033 BadSubReg,
03035 UnmatchedBracket,
03037 UnmatchedParen,
03039 UnmatchedBrace,
03041 BadBR,
03043 RangeError,
03045 OutOfMemory,
03047 BadRepitition,
03048
03049
03051 PrematureEnd,
03053 TooBig,
03055 UnmatchedRParen,
03057 NotCompiled
03058 };
03059
03065 ErrorCodes GetErrorCode() const;
03066
03073 PString GetErrorText() const;
03075
03079 BOOL Compile(
03080 const PString & pattern,
03081 int flags = IgnoreCase
03082 );
03090 BOOL Compile(
03091 const char * cpattern,
03092 int flags = IgnoreCase
03093 );
03094
03095
03097 BOOL Execute(
03098 const PString & str,
03099 PINDEX & start,
03100 int flags = 0
03101 ) const;
03103 BOOL Execute(
03104 const PString & str,
03105 PINDEX & start,
03106 PINDEX & len,
03107 int flags = 0
03108 ) const;
03110 BOOL Execute(
03111 const char * cstr,
03112 PINDEX & start,
03113 int flags = 0
03114 ) const;
03116 BOOL Execute(
03117 const char * cstr,
03118 PINDEX & start,
03119 PINDEX & len,
03120 int flags = 0
03121 ) const;
03123 BOOL Execute(
03124 const PString & str,
03125 PIntArray & starts,
03126 int flags = 0
03127 ) const;
03129 BOOL Execute(
03130 const PString & str,
03131 PIntArray & starts,
03132 PIntArray & ends,
03133 int flags = 0
03134 ) const;
03136 BOOL Execute(
03137 const char * cstr,
03138 PIntArray & starts,
03139 int flags = 0
03140 ) const;
03156 BOOL Execute(
03157 const char * cstr,
03158 PIntArray & starts,
03159 PIntArray & ends,
03160 int flags = 0
03161 ) const;
03163
03172 static PString EscapeString(
03173 const PString & str
03174 );
03176
03177 protected:
03178 PString patternSaved;
03179 int flagsSaved;
03180
03181 void * expression;
03182 int lastError;
03183 };
03184
03185
03186