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 #ifdef P_USE_PRAGMA
00330 #pragma interface
00331 #endif
00332
00333 #include <string>
00334 #include <vector>
00335
00337
00338
00339 class PStringArray;
00340 class PRegularExpression;
00341
00376 class PString : public PCharArray {
00377 PCLASSINFO(PString, PCharArray);
00378
00379
00380
00381 public:
00387 PINLINE PString();
00388
00392 PINLINE PString(
00393 const PString & str
00394 );
00395
00398 PINLINE PString(
00399 const std::string & str
00400 );
00401
00410 PString(
00411 const char * cstr
00412 );
00413
00418 PString(
00419 const WORD * ustr
00420 );
00421
00435 PString(
00436 const char * cstr,
00437 PINDEX len
00438 );
00439
00450 PString(
00451 const WORD * ustr,
00452 PINDEX len
00453 );
00454
00465 PString(
00466 const PWORDArray & ustr
00467 );
00468
00477 PString(
00478 char ch
00479 );
00480
00485 PString(
00486 short n
00487 );
00488
00493 PString(
00494 unsigned short n
00495 );
00496
00501 PString(
00502 int n
00503 );
00504
00509 PString(
00510 unsigned int n
00511 );
00512
00517 PString(
00518 long n
00519 );
00520
00525 PString(
00526 unsigned long n
00527 );
00528
00533 PString(
00534 PInt64 n
00535 );
00536
00541 PString(
00542 PUInt64 n
00543 );
00544
00545
00546 enum ConversionType {
00547 Pascal,
00548 Basic,
00549 Literal,
00550 Signed,
00551 Unsigned,
00552 Decimal,
00553 Exponent,
00554 Printf,
00555 NumConversionTypes
00556 };
00557
00558
00559
00560
00561
00562
00563 PString(
00564 ConversionType type,
00565 const char * str,
00566 ...
00567 );
00568 PString(
00569 ConversionType type,
00570 long value,
00571 unsigned base = 10
00572 );
00573 PString(
00574 ConversionType type,
00575 double value,
00576 unsigned places
00577 );
00578
00586 PString & operator=(
00587 const PString & str
00588 );
00589
00599 PString & operator=(
00600 const char * cstr
00601 );
00602
00611 PString & operator=(
00612 char ch
00613 );
00614
00619 PString & operator=(
00620 short n
00621 );
00622
00627 PString & operator=(
00628 unsigned short n
00629 );
00630
00635 PString & operator=(
00636 int n
00637 );
00638
00643 PString & operator=(
00644 unsigned int n
00645 );
00646
00651 PString & operator=(
00652 long n
00653 );
00654
00659 PString & operator=(
00660 unsigned long n
00661 );
00662
00667 PString & operator=(
00668 PInt64 n
00669 );
00670
00675 PString & operator=(
00676 PUInt64 n
00677 );
00678
00681 virtual PString & MakeEmpty();
00682
00685 static PString Empty();
00687
00694 virtual PObject * Clone() const;
00695
00705 virtual Comparison Compare(
00706 const PObject & obj
00707 ) const;
00708
00711 virtual void PrintOn(
00712 ostream & strm
00713 ) const;
00714
00720 virtual void ReadFrom(
00721 istream & strm
00722 );
00723
00737 virtual PINDEX HashFunction() const;
00739
00754 virtual BOOL SetSize(
00755 PINDEX newSize
00756 );
00757
00766 virtual BOOL IsEmpty() const;
00767
00776 virtual BOOL MakeUnique();
00778
00779
00792 BOOL MakeMinimumSize();
00793
00802 PINLINE PINDEX GetLength() const;
00803
00810 bool operator!() const;
00812
00821 PString operator+(
00822 const PString & str
00823 ) const;
00824
00836 PString operator+(
00837 const char * cstr
00838 ) const;
00839
00851 PString operator+(
00852 char ch
00853 ) const;
00854
00866 friend PString operator+(
00867 const char * cstr,
00868 const PString & str
00869 );
00870
00882 friend PString operator+(
00883 char c,
00884 const PString & str
00885 );
00886
00892 PString & operator+=(
00893 const PString & str
00894 );
00895
00905 PString & operator+=(
00906 const char * cstr
00907 );
00908
00918 PString & operator+=(
00919 char ch
00920 );
00921
00922
00929 PString operator&(
00930 const PString & str
00931 ) const;
00932
00949 PString operator&(
00950 const char * cstr
00951 ) const;
00952
00969 PString operator&(
00970 char ch
00971 ) const;
00972
00989 friend PString operator&(
00990 const char * cstr,
00991 const PString & str
00992 );
00993
01010 friend PString operator&(
01011 char ch,
01012 const PString & str
01013 );
01014
01020 PString & operator&=(
01021 const PString & str
01022 );
01023
01038 PString & operator&=(
01039 const char * cstr
01040 );
01041
01042
01057 PString & operator&=(
01058 char ch
01059 );
01061
01062
01070 bool operator*=(
01071 const PString & str
01072 ) const;
01073
01081 bool operator==(
01082 const PObject & str
01083 ) const;
01084
01092 bool operator!=(
01093 const PObject & str
01094 ) const;
01095
01103 bool operator<(
01104 const PObject & str
01105 ) const;
01106
01114 bool operator>(
01115 const PObject & str
01116 ) const;
01117
01125 bool operator<=(
01126 const PObject & str
01127 ) const;
01128
01136 bool operator>=(
01137 const PObject & str
01138 ) const;
01139
01140
01151 bool operator*=(
01152 const char * cstr
01153 ) const;
01154
01165 bool operator==(
01166 const char * cstr
01167 ) const;
01168
01179 bool operator!=(
01180 const char * cstr
01181 ) const;
01182
01193 bool operator<(
01194 const char * cstr
01195 ) const;
01196
01207 bool operator>(
01208 const char * cstr
01209 ) const;
01210
01221 bool operator<=(
01222 const char * cstr
01223 ) const;
01224
01235 bool operator>=(
01236 const char * cstr
01237 ) const;
01238
01250 Comparison NumCompare(
01251 const PString & str,
01252 PINDEX count = P_MAX_INDEX,
01253 PINDEX offset = 0
01254 ) const;
01255
01267 Comparison NumCompare(
01268 const char * cstr,
01269 PINDEX count = P_MAX_INDEX,
01270 PINDEX offset = 0
01271 ) const;
01273
01274
01278 PINDEX Find(
01279 char ch,
01280 PINDEX offset = 0
01281 ) const;
01282
01284 PINDEX Find(
01285 const PString & str,
01286 PINDEX offset = 0
01287 ) const;
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303 PINDEX Find(
01304 const char * cstr,
01305 PINDEX offset = 0
01306 ) const;
01307
01309 PINDEX FindLast(
01310 char ch,
01311 PINDEX offset = P_MAX_INDEX
01312 ) const;
01313
01315 PINDEX FindLast(
01316 const PString & str,
01317 PINDEX offset = P_MAX_INDEX
01318 ) const;
01319
01337 PINDEX FindLast(
01338 const char * cstr,
01339 PINDEX offset = P_MAX_INDEX
01340 ) const;
01341
01343 PINDEX FindOneOf(
01344 const PString & set,
01345 PINDEX offset = 0
01346 ) const;
01347
01362 PINDEX FindOneOf(
01363 const char * cset,
01364 PINDEX offset = 0
01365 ) const;
01366
01377 PINDEX FindRegEx(
01378 const PRegularExpression & regex,
01379 PINDEX offset = 0
01380 ) const;
01381
01392 BOOL FindRegEx(
01393 const PRegularExpression & regex,
01394 PINDEX & pos,
01395 PINDEX & len,
01396 PINDEX offset = 0,
01397 PINDEX maxPos = P_MAX_INDEX
01398 ) const;
01399
01400
01411 void Replace(
01412 const PString & target,
01413 const PString & subs,
01414 BOOL all = FALSE,
01415 PINDEX offset = 0
01416 );
01417
01425 void Splice(
01426 const PString & str,
01427 PINDEX pos,
01428 PINDEX len = 0
01429 );
01430
01438 void Splice(
01439 const char * cstr,
01440 PINDEX pos,
01441 PINDEX len = 0
01442 );
01443
01450 void Delete(
01451 PINDEX start,
01452 PINDEX len
01453 );
01455
01456
01476 PString operator()(
01477 PINDEX start,
01478 PINDEX end
01479 ) const;
01480
01495 PString Left(
01496 PINDEX len
01497 ) const;
01498
01513 PString Right(
01514 PINDEX len
01515 ) const;
01516
01533 PString Mid(
01534 PINDEX start,
01535 PINDEX len = P_MAX_INDEX
01536 ) const;
01537
01538
01546 PString LeftTrim() const;
01547
01555 PString RightTrim() const;
01556
01565 PString Trim() const;
01566
01567
01576 PString ToLower() const;
01577
01586 PString ToUpper() const;
01587
01588
01590 PStringArray Tokenise(
01591 const PString & separators,
01593 BOOL onePerSeparator = TRUE
01595 ) const;
01618 PStringArray Tokenise(
01619 const char * cseparators,
01621 BOOL onePerSeparator = TRUE
01623 ) const;
01624
01638 PStringArray Lines() const;
01640
01657 PString & sprintf(
01658 const char * cfmt,
01659 ...
01660 );
01661
01676 friend PString psprintf(
01677 const char * cfmt,
01678 ...
01679 );
01680
01682 PString & vsprintf(
01683 const PString & fmt,
01684 va_list args
01685 );
01700 PString & vsprintf(
01701 const char * cfmt,
01702 va_list args
01703 );
01704
01706 friend PString pvsprintf(
01707 const char * cfmt,
01708 va_list args
01709 );
01724 friend PString pvsprintf(
01725 const PString & fmt,
01726 va_list args
01727 );
01728
01729
01742 long AsInteger(
01743 unsigned base = 10
01744 ) const;
01757 DWORD AsUnsigned(
01758 unsigned base = 10
01759 ) const;
01773 PInt64 AsInt64(
01774 unsigned base = 10
01775 ) const;
01789 PUInt64 AsUnsigned64(
01790 unsigned base = 10
01791 ) const;
01792
01803 double AsReal() const;
01804
01808 PWORDArray AsUCS2() const;
01809
01820 PBYTEArray ToPascal() const;
01821
01830 PString ToLiteral() const;
01831
01839 operator const unsigned char *() const;
01840
01842
01843
01844 protected:
01845 void InternalFromUCS2(
01846 const WORD * ptr,
01847 PINDEX len
01848 );
01849 virtual Comparison InternalCompare(
01850 PINDEX offset,
01851 char c
01852 ) const;
01853 virtual Comparison InternalCompare(
01854 PINDEX offset,
01855 PINDEX length,
01856 const char * cstr
01857 ) const;
01858
01859
01860
01861
01862
01863
01864
01865 PString(int dummy, const PString * str);
01866 };
01867
01868
01870
01880 class PCaselessString : public PString
01881 {
01882 PCLASSINFO(PCaselessString, PString);
01883
01884 public:
01887 PCaselessString();
01888
01892 PCaselessString(
01893 const char * cstr
01894 );
01895
01900 PCaselessString(
01901 const PString & str
01902 );
01903
01904
01912 PCaselessString & operator=(
01913 const PString & str
01914 );
01915
01925 PCaselessString & operator=(
01926 const char * cstr
01927 );
01928
01937 PCaselessString & operator=(
01938 char ch
01939 );
01940
01941
01942
01947 virtual PObject * Clone() const;
01948
01949 protected:
01950
01951 virtual Comparison InternalCompare(
01952 PINDEX offset,
01953 char c
01954 ) const;
01955 virtual Comparison InternalCompare(
01956 PINDEX offset,
01957 PINDEX length,
01958 const char * cstr
01959 ) const;
01960
01961
01962
01963
01964
01965
01966
01967 PCaselessString(int dummy, const PCaselessString * str);
01968 };
01969
01971
01972 class PStringStream;
01973
01980 class PStringStream : public PString, public iostream
01981 {
01982 PCLASSINFO(PStringStream, PString);
01983
01984 public:
01990 PStringStream();
01991
01996 PStringStream(
01997 PINDEX fixedBufferSize
01998 );
01999
02006 PStringStream(
02007 const PString & str
02008 );
02009
02014 PStringStream(
02015 const char * cstr
02016 );
02017
02020 virtual PString & MakeEmpty();
02021
02033 PStringStream & operator=(
02034 const PStringStream & strm
02035 );
02036
02048 PStringStream & operator=(
02049 const PString & str
02050 );
02051
02067 PStringStream & operator=(
02068 const char * cstr
02069 );
02070
02079 PStringStream & operator=(
02080 char ch
02081 );
02082
02083
02085 virtual ~PStringStream();
02086
02087
02088 protected:
02089 virtual void AssignContents(const PContainer & cont);
02090
02091 private:
02092 PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
02093
02094 class Buffer : public streambuf {
02095 public:
02096 Buffer(PStringStream & str, PINDEX size);
02097 Buffer(const Buffer & sbuf);
02098 Buffer & operator=(const Buffer & sbuf);
02099 virtual int overflow(int=EOF);
02100 virtual int underflow();
02101 virtual int sync();
02102 #ifdef __USE_STL__
02103 virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
02104 virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
02105 #else
02106 virtual streampos seekoff(streamoff, ios::seek_dir, int);
02107 #endif
02108 PStringStream & string;
02109 BOOL fixedBufferSize;
02110 };
02111 };
02112
02113
02114 class PStringList;
02115 class PSortedStringList;
02116
02129 #ifdef DOC_PLUS_PLUS
02130 class PStringArray : public PArray {
02131 #endif
02132 PDECLARE_ARRAY(PStringArray, PString);
02133 public:
02140 PStringArray(
02141 PINDEX count,
02142 char const * const * strarr,
02143 BOOL caseless = FALSE
02144 );
02147 PStringArray(
02148 const PString & str
02149 );
02152 PStringArray(
02153 const PStringList & list
02154 );
02157 PStringArray(
02158 const PSortedStringList & list
02159 );
02160
02164 PStringArray(
02165 const std::vector<PString> & vec
02166 )
02167 {
02168 for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02169 AppendString(*r);
02170 }
02171
02175 PStringArray(
02176 const std::vector<std::string> & vec
02177 )
02178 {
02179 for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02180 AppendString(PString(*r));
02181 }
02182
02186 template <typename stlContainer>
02187 static PStringArray container(
02188 const stlContainer & vec
02189 )
02190 {
02191 PStringArray list;
02192 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02193 list.AppendString(PString(*r));
02194 return list;
02195 }
02196
02198
02206 virtual void ReadFrom(
02207 istream &strm
02208 );
02210
02219 PINDEX GetStringsIndex(
02220 const PString & str
02221 ) const;
02222
02223 PString operator[](
02224 PINDEX index
02225 ) const;
02226
02234 PString & operator[](
02235 PINDEX index
02236 );
02237
02240 PINDEX AppendString(
02241 const PString & str
02242 );
02243
02249 PStringArray & operator +=(const PStringArray & array);
02250 PStringArray & operator +=(const PString & str);
02251
02252
02259 PStringArray operator + (const PStringArray & array);
02260 PStringArray operator + (const PString & str);
02261
02269 char ** ToCharArray(
02270 PCharArray * storage = NULL
02271 ) const;
02273 };
02274
02275
02288 #ifdef DOC_PLUS_PLUS
02289 class PStringList : public PList {
02290 #endif
02291 PDECLARE_LIST(PStringList, PString);
02292 public:
02297 PStringList(
02298 PINDEX count,
02299 char const * const * strarr,
02300 BOOL caseless = FALSE
02301 );
02304 PStringList(
02305 const PString & str
02306 );
02309 PStringList(
02310 const PStringArray & array
02311 );
02314 PStringList(
02315 const PSortedStringList & list
02316 );
02318
02326 virtual void ReadFrom(
02327 istream &strm
02328 );
02330
02335 PINDEX AppendString(
02336 const PString & str
02337 );
02338
02341 PINDEX InsertString(
02342 const PString & before,
02343 const PString & str
02344 );
02345
02349 PINDEX GetStringsIndex(
02350 const PString & str
02351 ) const;
02352
02358 PStringList & operator +=(const PStringList & list);
02359 PStringList & operator +=(const PString & str);
02360
02361
02368 PStringList operator + (const PStringList & array);
02369 PStringList operator + (const PString & str);
02370
02374 template <typename stlContainer>
02375 static PStringList container(
02376 const stlContainer & vec
02377 )
02378 {
02379 PStringList list;
02380 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02381 list.AppendString(PString(*r));
02382 return list;
02383 }
02385 };
02386
02387
02400 #ifdef DOC_PLUS_PLUS
02401 class PSortedStringList : public PSortedList {
02402 #endif
02403 PDECLARE_SORTED_LIST(PSortedStringList, PString);
02404 public:
02409 PSortedStringList(
02410 PINDEX count,
02411 char const * const * strarr,
02412 BOOL caseless = FALSE
02413 );
02416 PSortedStringList(
02417 const PString & str
02418 );
02421 PSortedStringList(
02422 const PStringArray & array
02423 );
02426 PSortedStringList(
02427 const PStringList & list
02428 );
02430
02438 virtual void ReadFrom(
02439 istream &strm
02440 );
02442
02448 PINDEX AppendString(
02449 const PString & str
02450 );
02451
02455 PINDEX GetStringsIndex(
02456 const PString & str
02457 ) const;
02458
02463 PINDEX GetNextStringsIndex(
02464 const PString & str
02465 ) const;
02467
02468 protected:
02469 PINDEX InternalStringSelect(
02470 const char * str,
02471 PINDEX len,
02472 Element * thisElement
02473 ) const;
02474 };
02475
02476
02493 #ifdef DOC_PLUS_PLUS
02494 class PStringSet : public PSet {
02495 #endif
02496 PDECLARE_SET(PStringSet, PString, TRUE);
02497 public:
02502 PStringSet(
02503 PINDEX count,
02504 char const * const * strarr,
02505 BOOL caseless = FALSE
02506 );
02509 PStringSet(
02510 const PString & str
02511 );
02513
02521 virtual void ReadFrom(
02522 istream &strm
02523 );
02525
02529 void Include(
02530 const PString & key
02531 );
02533 PStringSet & operator+=(
02534 const PString & key
02535 );
02537 void Exclude(
02538 const PString & key
02539 );
02541 PStringSet & operator-=(
02542 const PString & key
02543 );
02545 };
02546
02547
02548 #ifdef PHAS_TEMPLATES
02549
02557 template <class K> class PStringDictionary : public PAbstractDictionary
02558 {
02559 PCLASSINFO(PStringDictionary, PAbstractDictionary);
02560
02561 public:
02570 PStringDictionary()
02571 : PAbstractDictionary() { }
02573
02580 virtual PObject * Clone() const
02581 { return PNEW PStringDictionary(0, this); }
02583
02598 const PString & operator[](const K & key) const
02599 { return (const PString &)GetRefAt(key); }
02600
02614 PString operator()(const K & key, const char * dflt = "") const
02615 { if (AbstractContains(key)) return (*this)[key]; return dflt; }
02616
02625 BOOL Contains(
02626 const K & key
02627 ) const { return AbstractContains(key); }
02628
02640 virtual PString * RemoveAt(
02641 const K & key
02642 ) {
02643 PString * s = GetAt(key); AbstractSetAt(key, NULL);
02644 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s;
02645 }
02646
02653 virtual PString * GetAt(
02654 const K & key
02655 ) const { return (PString *)AbstractGetAt(key); }
02656
02665 virtual BOOL SetDataAt(
02666 PINDEX index,
02667 const PString & str
02668 ) { return PAbstractDictionary::SetDataAt(index, PNEW PString(str)); }
02669
02681 virtual BOOL SetAt(
02682 const K & key,
02683 const PString & str
02684 ) { return AbstractSetAt(key, PNEW PString(str)); }
02685
02697 const K & GetKeyAt(PINDEX index) const
02698 { return (const K &)AbstractGetKeyAt(index); }
02699
02711 PString & GetDataAt(PINDEX index) const
02712 { return (PString &)AbstractGetDataAt(index); }
02714
02715 protected:
02716 PStringDictionary(int dummy, const PStringDictionary * c)
02717 : PAbstractDictionary(dummy, c) { }
02718 };
02719
02720
02735 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02736 PDECLARE_CLASS(cls, PStringDictionary<K>) \
02737 protected: \
02738 cls(int dummy, const cls * c) \
02739 : PStringDictionary<K>(dummy, c) { } \
02740 public: \
02741 cls() \
02742 : PStringDictionary<K>() { } \
02743 virtual PObject * Clone() const \
02744 { return PNEW cls(0, this); } \
02745
02746
02759 #define PSTRING_DICTIONARY(cls, K) typedef PStringDictionary<K> cls
02760
02761
02762 #else // PHAS_TEMPLATES
02763
02764
02765 #define PSTRING_DICTIONARY(cls, K) \
02766 class cls : public PAbstractDictionary { \
02767 PCLASSINFO(cls, PAbstractDictionary) \
02768 protected: \
02769 inline cls(int dummy, const cls * c) \
02770 : PAbstractDictionary(dummy, c) { } \
02771 public: \
02772 inline cls() \
02773 : PAbstractDictionary() { } \
02774 inline PObject * Clone() const \
02775 { return PNEW cls(0, this); } \
02776 inline PString & operator[](const K & key) const \
02777 { return (PString &)GetRefAt(key); } \
02778 inline PString operator()(const K & key, const char * dflt = "") const \
02779 { if (Contains(key)) return (PString &)GetRefAt(key); return dflt; } \
02780 virtual BOOL Contains(const K & key) const \
02781 { return AbstractContains(key); } \
02782 virtual PString * RemoveAt(const K & key) \
02783 { PString * s = GetAt(key); AbstractSetAt(key, NULL); \
02784 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s; } \
02785 virtual PString * GetAt(const K & key) const \
02786 { return (PString *)AbstractGetAt(key); } \
02787 virtual BOOL SetDataAt(PINDEX index, const PString & str) \
02788 { return PAbstractDictionary::SetDataAt(index,PNEW PString(str));} \
02789 virtual BOOL SetAt(const K & key, const PString & str) \
02790 { return AbstractSetAt(key, PNEW PString(str)); } \
02791 inline const K & GetKeyAt(PINDEX index) const \
02792 { return (const K &)AbstractGetKeyAt(index); } \
02793 inline PString & GetDataAt(PINDEX index) const \
02794 { return (PString &)AbstractGetDataAt(index); } \
02795 }
02796
02797 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02798 PSTRING_DICTIONARY(cls##_PTemplate, K); \
02799 PDECLARE_CLASS(cls, cls##_PTemplate) \
02800 protected: \
02801 cls(int dummy, const cls * c) \
02802 : cls##_PTemplate(dummy, c) { } \
02803 public: \
02804 cls() \
02805 : cls##_PTemplate() { } \
02806 virtual PObject * Clone() const \
02807 { return PNEW cls(0, this); } \
02808
02809 #endif // PHAS_TEMPLATES
02810
02811
02826 #ifdef DOC_PLUS_PLUS
02827 class POrdinalToString : public PStringDictionary {
02828 #endif
02829 PDECLARE_STRING_DICTIONARY(POrdinalToString, POrdinalKey);
02830 public:
02833
02834 struct Initialiser {
02836 PINDEX key;
02838 const char * value;
02839 };
02842 POrdinalToString(
02843 PINDEX count,
02844 const Initialiser * init
02845 );
02847
02855 virtual void ReadFrom(
02856 istream &strm
02857 );
02859 };
02860
02873 #ifdef DOC_PLUS_PLUS
02874 class PStringToOrdinal : public POrdinalDictionary {
02875 #endif
02876 PDECLARE_ORDINAL_DICTIONARY(PStringToOrdinal, PString);
02877 public:
02880
02881 struct Initialiser {
02883 const char * key;
02885 PINDEX value;
02886 };
02889 PStringToOrdinal(
02890 PINDEX count,
02891 const Initialiser * init,
02892 BOOL caseless = FALSE
02893 );
02895
02903 virtual void ReadFrom(
02904 istream &strm
02905 );
02907 };
02908
02909
02923 #ifdef DOC_PLUS_PLUS
02924 class PStringToString : public PStringDictionary {
02925 #endif
02926 PDECLARE_STRING_DICTIONARY(PStringToString, PString);
02927 public:
02930
02931 struct Initialiser {
02933 const char * key;
02935 const char * value;
02936 };
02939 PStringToString(
02940 PINDEX count,
02941 const Initialiser * init,
02942 BOOL caselessKeys = FALSE,
02943 BOOL caselessValues = FALSE
02944 );
02946
02954 virtual void ReadFrom(
02955 istream &strm
02956 );
02958 };
02959
02960
02966 class PRegularExpression : public PObject
02967 {
02968 PCLASSINFO(PRegularExpression, PObject);
02969
02970 public:
02973
02974 enum {
02976 Extended = 1,
02978 IgnoreCase = 2,
02983 AnchorNewLine = 4
02984 };
02986 enum {
02993 NotBeginningOfLine = 1,
02995 NotEndofLine = 2
02996 };
02997
02999 PRegularExpression();
03000
03003 PRegularExpression(
03004 const PString & pattern,
03005 int flags = IgnoreCase
03006 );
03007
03010 PRegularExpression(
03011 const char * cpattern,
03012 int flags = IgnoreCase
03013 );
03014
03018 PRegularExpression(
03019 const PRegularExpression &
03020 );
03021
03025 PRegularExpression & operator =(
03026 const PRegularExpression &
03027 );
03028
03030 ~PRegularExpression();
03032
03035
03036 enum ErrorCodes {
03038 NoError = 0,
03040 NoMatch,
03041
03042
03044 BadPattern,
03046 CollateError,
03048 BadClassType,
03050 BadEscape,
03052 BadSubReg,
03054 UnmatchedBracket,
03056 UnmatchedParen,
03058 UnmatchedBrace,
03060 BadBR,
03062 RangeError,
03064 OutOfMemory,
03066 BadRepitition,
03067
03068
03070 PrematureEnd,
03072 TooBig,
03074 UnmatchedRParen,
03076 NotCompiled
03077 };
03078
03084 ErrorCodes GetErrorCode() const;
03085
03092 PString GetErrorText() const;
03094
03098 BOOL Compile(
03099 const PString & pattern,
03100 int flags = IgnoreCase
03101 );
03109 BOOL Compile(
03110 const char * cpattern,
03111 int flags = IgnoreCase
03112 );
03113
03114
03116 BOOL Execute(
03117 const PString & str,
03118 PINDEX & start,
03119 int flags = 0
03120 ) const;
03122 BOOL Execute(
03123 const PString & str,
03124 PINDEX & start,
03125 PINDEX & len,
03126 int flags = 0
03127 ) const;
03129 BOOL Execute(
03130 const char * cstr,
03131 PINDEX & start,
03132 int flags = 0
03133 ) const;
03135 BOOL Execute(
03136 const char * cstr,
03137 PINDEX & start,
03138 PINDEX & len,
03139 int flags = 0
03140 ) const;
03142 BOOL Execute(
03143 const PString & str,
03144 PIntArray & starts,
03145 int flags = 0
03146 ) const;
03148 BOOL Execute(
03149 const PString & str,
03150 PIntArray & starts,
03151 PIntArray & ends,
03152 int flags = 0
03153 ) const;
03155 BOOL Execute(
03156 const char * cstr,
03157 PIntArray & starts,
03158 int flags = 0
03159 ) const;
03175 BOOL Execute(
03176 const char * cstr,
03177 PIntArray & starts,
03178 PIntArray & ends,
03179 int flags = 0
03180 ) const;
03182
03191 static PString EscapeString(
03192 const PString & str
03193 );
03195
03196 protected:
03197 PString patternSaved;
03198 int flagsSaved;
03199
03200 void * expression;
03201 int lastError;
03202 };
03203
03204 PString psprintf(const char * cfmt, ...);
03205
03206