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
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360 #ifndef __PSTRING__
00361 #define __PSTRING__
00362
00363 #ifdef P_USE_PRAGMA
00364 #pragma interface
00365 #endif
00366
00367 #include <string>
00368 #include <vector>
00369 #include <ptlib/array.h>
00370
00372
00373
00374 class PStringArray;
00375 class PRegularExpression;
00376
00411 class PString : public PCharArray {
00412 PCLASSINFO(PString, PCharArray);
00413
00414
00415
00416 public:
00422 PINLINE PString();
00423
00427 PINLINE PString(
00428 const PString & str
00429 );
00430
00433 PINLINE PString(
00434 const std::string & str
00435 );
00436
00445 PString(
00446 const char * cstr
00447 );
00448
00453 PString(
00454 const WORD * ustr
00455 );
00456
00470 PString(
00471 const char * cstr,
00472 PINDEX len
00473 );
00474
00485 PString(
00486 const WORD * ustr,
00487 PINDEX len
00488 );
00489
00500 PString(
00501 const PWORDArray & ustr
00502 );
00503
00512 PString(
00513 char ch
00514 );
00515
00520 PString(
00521 short n
00522 );
00523
00528 PString(
00529 unsigned short n
00530 );
00531
00536 PString(
00537 int n
00538 );
00539
00544 PString(
00545 unsigned int n
00546 );
00547
00552 PString(
00553 long n
00554 );
00555
00560 PString(
00561 unsigned long n
00562 );
00563
00568 PString(
00569 PInt64 n
00570 );
00571
00576 PString(
00577 PUInt64 n
00578 );
00579
00580
00581 enum ConversionType {
00582 Pascal,
00583 Basic,
00584 Literal,
00585 Signed,
00586 Unsigned,
00587 Decimal,
00588 Exponent,
00589 Printf,
00590 NumConversionTypes
00591 };
00592
00593
00594
00595
00596
00597
00598 PString(
00599 ConversionType type,
00600 const char * str,
00601 ...
00602 );
00603 PString(
00604 ConversionType type,
00605 long value,
00606 unsigned base = 10
00607 );
00608 PString(
00609 ConversionType type,
00610 double value,
00611 unsigned places
00612 );
00613
00621 PString & operator=(
00622 const PString & str
00623 );
00624
00634 PString & operator=(
00635 const char * cstr
00636 );
00637
00646 PString & operator=(
00647 char ch
00648 );
00649
00654 PString & operator=(
00655 short n
00656 );
00657
00662 PString & operator=(
00663 unsigned short n
00664 );
00665
00670 PString & operator=(
00671 int n
00672 );
00673
00678 PString & operator=(
00679 unsigned int n
00680 );
00681
00686 PString & operator=(
00687 long n
00688 );
00689
00694 PString & operator=(
00695 unsigned long n
00696 );
00697
00702 PString & operator=(
00703 PInt64 n
00704 );
00705
00710 PString & operator=(
00711 PUInt64 n
00712 );
00713
00716 virtual PString & MakeEmpty();
00717
00720 static PString Empty();
00722
00729 virtual PObject * Clone() const;
00730
00740 virtual Comparison Compare(
00741 const PObject & obj
00742 ) const;
00743
00746 virtual void PrintOn(
00747 ostream & strm
00748 ) const;
00749
00755 virtual void ReadFrom(
00756 istream & strm
00757 );
00758
00772 virtual PINDEX HashFunction() const;
00774
00789 virtual BOOL SetSize(
00790 PINDEX newSize
00791 );
00792
00801 virtual BOOL IsEmpty() const;
00802
00811 virtual BOOL MakeUnique();
00813
00814
00827 BOOL MakeMinimumSize();
00828
00837 PINLINE PINDEX GetLength() const;
00838
00845 bool operator!() const;
00847
00856 PString operator+(
00857 const PString & str
00858 ) const;
00859
00871 PString operator+(
00872 const char * cstr
00873 ) const;
00874
00886 PString operator+(
00887 char ch
00888 ) const;
00889
00901 friend PString operator+(
00902 const char * cstr,
00903 const PString & str
00904 );
00905
00917 friend PString operator+(
00918 char c,
00919 const PString & str
00920 );
00921
00927 PString & operator+=(
00928 const PString & str
00929 );
00930
00940 PString & operator+=(
00941 const char * cstr
00942 );
00943
00953 PString & operator+=(
00954 char ch
00955 );
00956
00957
00964 PString operator&(
00965 const PString & str
00966 ) const;
00967
00984 PString operator&(
00985 const char * cstr
00986 ) const;
00987
01004 PString operator&(
01005 char ch
01006 ) const;
01007
01024 friend PString operator&(
01025 const char * cstr,
01026 const PString & str
01027 );
01028
01045 friend PString operator&(
01046 char ch,
01047 const PString & str
01048 );
01049
01055 PString & operator&=(
01056 const PString & str
01057 );
01058
01073 PString & operator&=(
01074 const char * cstr
01075 );
01076
01077
01092 PString & operator&=(
01093 char ch
01094 );
01096
01097
01105 bool operator*=(
01106 const PString & 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
01171 bool operator>=(
01172 const PObject & str
01173 ) const;
01174
01175
01186 bool operator*=(
01187 const char * cstr
01188 ) const;
01189
01200 bool operator==(
01201 const char * cstr
01202 ) const;
01203
01214 bool operator!=(
01215 const char * cstr
01216 ) const;
01217
01228 bool operator<(
01229 const char * cstr
01230 ) const;
01231
01242 bool operator>(
01243 const char * cstr
01244 ) const;
01245
01256 bool operator<=(
01257 const char * cstr
01258 ) const;
01259
01270 bool operator>=(
01271 const char * cstr
01272 ) const;
01273
01285 Comparison NumCompare(
01286 const PString & str,
01287 PINDEX count = P_MAX_INDEX,
01288 PINDEX offset = 0
01289 ) const;
01290
01302 Comparison NumCompare(
01303 const char * cstr,
01304 PINDEX count = P_MAX_INDEX,
01305 PINDEX offset = 0
01306 ) const;
01308
01309
01313 PINDEX Find(
01314 char ch,
01315 PINDEX offset = 0
01316 ) const;
01317
01319 PINDEX Find(
01320 const PString & str,
01321 PINDEX offset = 0
01322 ) const;
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338 PINDEX Find(
01339 const char * cstr,
01340 PINDEX offset = 0
01341 ) const;
01342
01344 PINDEX FindLast(
01345 char ch,
01346 PINDEX offset = P_MAX_INDEX
01347 ) const;
01348
01350 PINDEX FindLast(
01351 const PString & str,
01352 PINDEX offset = P_MAX_INDEX
01353 ) const;
01354
01372 PINDEX FindLast(
01373 const char * cstr,
01374 PINDEX offset = P_MAX_INDEX
01375 ) const;
01376
01378 PINDEX FindOneOf(
01379 const PString & set,
01380 PINDEX offset = 0
01381 ) const;
01382
01397 PINDEX FindOneOf(
01398 const char * cset,
01399 PINDEX offset = 0
01400 ) const;
01401
01403 PINDEX FindSpan(
01404 const PString & set,
01405 PINDEX offset = 0
01406 ) const;
01407
01423 PINDEX FindSpan(
01424 const char * cset,
01425 PINDEX offset = 0
01426 ) const;
01427
01438 PINDEX FindRegEx(
01439 const PRegularExpression & regex,
01440 PINDEX offset = 0
01441 ) const;
01442
01453 BOOL FindRegEx(
01454 const PRegularExpression & regex,
01455 PINDEX & pos,
01456 PINDEX & len,
01457 PINDEX offset = 0,
01458 PINDEX maxPos = P_MAX_INDEX
01459 ) const;
01460
01461
01472 void Replace(
01473 const PString & target,
01474 const PString & subs,
01475 BOOL all = FALSE,
01476 PINDEX offset = 0
01477 );
01478
01486 void Splice(
01487 const PString & str,
01488 PINDEX pos,
01489 PINDEX len = 0
01490 );
01491
01499 void Splice(
01500 const char * cstr,
01501 PINDEX pos,
01502 PINDEX len = 0
01503 );
01504
01511 void Delete(
01512 PINDEX start,
01513 PINDEX len
01514 );
01516
01517
01537 PString operator()(
01538 PINDEX start,
01539 PINDEX end
01540 ) const;
01541
01556 PString Left(
01557 PINDEX len
01558 ) const;
01559
01574 PString Right(
01575 PINDEX len
01576 ) const;
01577
01594 PString Mid(
01595 PINDEX start,
01596 PINDEX len = P_MAX_INDEX
01597 ) const;
01598
01599
01607 PString LeftTrim() const;
01608
01616 PString RightTrim() const;
01617
01626 PString Trim() const;
01627
01628
01637 PString ToLower() const;
01638
01647 PString ToUpper() const;
01648
01649
01651 PStringArray Tokenise(
01652 const PString & separators,
01654 BOOL onePerSeparator = TRUE
01656 ) const;
01681 PStringArray Tokenise(
01682 const char * cseparators,
01684 BOOL onePerSeparator = TRUE
01686 ) const;
01687
01701 PStringArray Lines() const;
01703
01720 PString & sprintf(
01721 const char * cfmt,
01722 ...
01723 );
01724
01739 friend PString psprintf(
01740 const char * cfmt,
01741 ...
01742 );
01743
01745 PString & vsprintf(
01746 const PString & fmt,
01747 va_list args
01748 );
01763 PString & vsprintf(
01764 const char * cfmt,
01765 va_list args
01766 );
01767
01769 friend PString pvsprintf(
01770 const char * cfmt,
01771 va_list args
01772 );
01787 friend PString pvsprintf(
01788 const PString & fmt,
01789 va_list args
01790 );
01791
01792
01805 long AsInteger(
01806 unsigned base = 10
01807 ) const;
01820 DWORD AsUnsigned(
01821 unsigned base = 10
01822 ) const;
01836 PInt64 AsInt64(
01837 unsigned base = 10
01838 ) const;
01852 PUInt64 AsUnsigned64(
01853 unsigned base = 10
01854 ) const;
01855
01866 double AsReal() const;
01867
01871 PWORDArray AsUCS2() const;
01872
01883 PBYTEArray ToPascal() const;
01884
01893 PString ToLiteral() const;
01894
01902 operator const unsigned char *() const;
01903
01906 operator std::string () const
01907 { return std::string(theArray); }
01908
01911 #ifdef _WIN32_WCE
01912 operator LPCWSTR() const
01913 { return AsUCS2(); }
01914 #endif
01915
01916
01917
01918 protected:
01919 void InternalFromUCS2(
01920 const WORD * ptr,
01921 PINDEX len
01922 );
01923 virtual Comparison InternalCompare(
01924 PINDEX offset,
01925 char c
01926 ) const;
01927 virtual Comparison InternalCompare(
01928 PINDEX offset,
01929 PINDEX length,
01930 const char * cstr
01931 ) const;
01932
01933
01934
01935
01936
01937
01938
01939 PString(int dummy, const PString * str);
01940 };
01941
01942
01943 inline ostream & operator<<(ostream & stream, const PString & string)
01944 {
01945 string.PrintOn(stream);
01946 return stream;
01947 }
01948
01949
01951
01961 class PCaselessString : public PString
01962 {
01963 PCLASSINFO(PCaselessString, PString);
01964
01965 public:
01968 PCaselessString();
01969
01973 PCaselessString(
01974 const char * cstr
01975 );
01976
01981 PCaselessString(
01982 const PString & str
01983 );
01984
01985
01988 PCaselessString(
01989 const std::string & str
01990 ) : PString(str)
01991 { }
01992
02000 PCaselessString & operator=(
02001 const PString & str
02002 );
02003
02013 PCaselessString & operator=(
02014 const char * cstr
02015 );
02016
02025 PCaselessString & operator=(
02026 char ch
02027 );
02028
02029
02030
02035 virtual PObject * Clone() const;
02036
02037 protected:
02038
02039 virtual Comparison InternalCompare(
02040 PINDEX offset,
02041 char c
02042 ) const;
02043 virtual Comparison InternalCompare(
02044 PINDEX offset,
02045 PINDEX length,
02046 const char * cstr
02047 ) const;
02048
02049
02050
02051
02052
02053
02054
02055 PCaselessString(int dummy, const PCaselessString * str);
02056 };
02057
02059
02060 class PStringStream;
02061
02068 class PStringStream : public PString, public iostream
02069 {
02070 PCLASSINFO(PStringStream, PString);
02071
02072 public:
02078 PStringStream();
02079
02084 PStringStream(
02085 PINDEX fixedBufferSize
02086 );
02087
02094 PStringStream(
02095 const PString & str
02096 );
02097
02102 PStringStream(
02103 const char * cstr
02104 );
02105
02108 virtual PString & MakeEmpty();
02109
02121 PStringStream & operator=(
02122 const PStringStream & strm
02123 );
02124
02136 PStringStream & operator=(
02137 const PString & str
02138 );
02139
02155 PStringStream & operator=(
02156 const char * cstr
02157 );
02158
02167 PStringStream & operator=(
02168 char ch
02169 );
02170
02171
02173 virtual ~PStringStream();
02174
02175
02176 protected:
02177 virtual void AssignContents(const PContainer & cont);
02178
02179 private:
02180 PStringStream(int, const PStringStream &) : iostream(cout.rdbuf()) { }
02181
02182 class Buffer : public streambuf {
02183 public:
02184 Buffer(PStringStream & str, PINDEX size);
02185 Buffer(const Buffer & sbuf);
02186 Buffer & operator=(const Buffer & sbuf);
02187 virtual int overflow(int=EOF);
02188 virtual int underflow();
02189 virtual int sync();
02190 #ifdef __USE_STL__
02191 virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
02192 virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
02193 #else
02194 virtual streampos seekoff(streamoff, ios::seek_dir, int);
02195 #endif
02196 PStringStream & string;
02197 BOOL fixedBufferSize;
02198 };
02199 };
02200
02201
02202 class PStringList;
02203 class PSortedStringList;
02204
02217 #ifdef DOC_PLUS_PLUS
02218 class PStringArray : public PArray {
02219 #endif
02220 PDECLARE_ARRAY(PStringArray, PString);
02221 public:
02228 PStringArray(
02229 PINDEX count,
02230 char const * const * strarr,
02231 BOOL caseless = FALSE
02232 );
02235 PStringArray(
02236 const PString & str
02237 );
02240 PStringArray(
02241 const PStringList & list
02242 );
02245 PStringArray(
02246 const PSortedStringList & list
02247 );
02248
02252 PStringArray(
02253 const std::vector<PString> & vec
02254 )
02255 {
02256 for (std::vector<PString>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02257 AppendString(*r);
02258 }
02259
02263 PStringArray(
02264 const std::vector<std::string> & vec
02265 )
02266 {
02267 for (std::vector<std::string>::const_iterator r = vec.begin(); r != vec.end(); ++r)
02268 AppendString(PString(*r));
02269 }
02270
02274 template <typename stlContainer>
02275 static PStringArray container(
02276 const stlContainer & vec
02277 )
02278 {
02279 PStringArray list;
02280 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02281 list.AppendString(PString(*r));
02282 return list;
02283 }
02284
02286
02294 virtual void ReadFrom(
02295 istream &strm
02296 );
02298
02307 PINDEX GetStringsIndex(
02308 const PString & str
02309 ) const;
02310
02311 PString operator[](
02312 PINDEX index
02313 ) const;
02314
02322 PString & operator[](
02323 PINDEX index
02324 );
02325
02328 PINDEX AppendString(
02329 const PString & str
02330 );
02331
02337 PStringArray & operator +=(const PStringArray & array);
02338 PStringArray & operator +=(const PString & str);
02339
02340
02347 PStringArray operator + (const PStringArray & array);
02348 PStringArray operator + (const PString & str);
02349
02357 char ** ToCharArray(
02358 PCharArray * storage = NULL
02359 ) const;
02361 };
02362
02363
02376 #ifdef DOC_PLUS_PLUS
02377 class PStringList : public PList {
02378 #endif
02379 PDECLARE_LIST(PStringList, PString);
02380 public:
02385 PStringList(
02386 PINDEX count,
02387 char const * const * strarr,
02388 BOOL caseless = FALSE
02389 );
02392 PStringList(
02393 const PString & str
02394 );
02397 PStringList(
02398 const PStringArray & array
02399 );
02402 PStringList(
02403 const PSortedStringList & list
02404 );
02406
02414 virtual void ReadFrom(
02415 istream &strm
02416 );
02418
02423 PINDEX AppendString(
02424 const PString & str
02425 );
02426
02429 PINDEX InsertString(
02430 const PString & before,
02431 const PString & str
02432 );
02433
02437 PINDEX GetStringsIndex(
02438 const PString & str
02439 ) const;
02440
02446 PStringList & operator +=(const PStringList & list);
02447 PStringList & operator +=(const PString & str);
02448
02449
02456 PStringList operator + (const PStringList & array);
02457 PStringList operator + (const PString & str);
02458
02462 template <typename stlContainer>
02463 static PStringList container(
02464 const stlContainer & vec
02465 )
02466 {
02467 PStringList list;
02468 for (typename stlContainer::const_iterator r = vec.begin(); r != vec.end(); ++r)
02469 list.AppendString(PString(*r));
02470 return list;
02471 }
02473 };
02474
02475
02488 #ifdef DOC_PLUS_PLUS
02489 class PSortedStringList : public PSortedList {
02490 #endif
02491 PDECLARE_SORTED_LIST(PSortedStringList, PString);
02492 public:
02497 PSortedStringList(
02498 PINDEX count,
02499 char const * const * strarr,
02500 BOOL caseless = FALSE
02501 );
02504 PSortedStringList(
02505 const PString & str
02506 );
02509 PSortedStringList(
02510 const PStringArray & array
02511 );
02514 PSortedStringList(
02515 const PStringList & list
02516 );
02518
02526 virtual void ReadFrom(
02527 istream &strm
02528 );
02530
02536 PINDEX AppendString(
02537 const PString & str
02538 );
02539
02543 PINDEX GetStringsIndex(
02544 const PString & str
02545 ) const;
02546
02551 PINDEX GetNextStringsIndex(
02552 const PString & str
02553 ) const;
02555
02556 protected:
02557 PINDEX InternalStringSelect(
02558 const char * str,
02559 PINDEX len,
02560 Element * thisElement
02561 ) const;
02562 };
02563
02564
02581 #ifdef DOC_PLUS_PLUS
02582 class PStringSet : public PSet {
02583 #endif
02584 PDECLARE_SET(PStringSet, PString, TRUE);
02585 public:
02590 PStringSet(
02591 PINDEX count,
02592 char const * const * strarr,
02593 BOOL caseless = FALSE
02594 );
02597 PStringSet(
02598 const PString & str
02599 );
02601
02609 virtual void ReadFrom(
02610 istream &strm
02611 );
02613
02617 void Include(
02618 const PString & key
02619 );
02621 PStringSet & operator+=(
02622 const PString & key
02623 );
02625 void Exclude(
02626 const PString & key
02627 );
02629 PStringSet & operator-=(
02630 const PString & key
02631 );
02633 };
02634
02635
02636 #ifdef PHAS_TEMPLATES
02637
02645 template <class K> class PStringDictionary : public PAbstractDictionary
02646 {
02647 PCLASSINFO(PStringDictionary, PAbstractDictionary);
02648
02649 public:
02658 PStringDictionary()
02659 : PAbstractDictionary() { }
02661
02668 virtual PObject * Clone() const
02669 { return PNEW PStringDictionary(0, this); }
02671
02686 const PString & operator[](const K & key) const
02687 { return (const PString &)GetRefAt(key); }
02688
02702 PString operator()(const K & key, const char * dflt = "") const
02703 { if (AbstractContains(key)) return (*this)[key]; return dflt; }
02704
02713 BOOL Contains(
02714 const K & key
02715 ) const { return AbstractContains(key); }
02716
02728 virtual PString * RemoveAt(
02729 const K & key
02730 ) {
02731 PString * s = GetAt(key); AbstractSetAt(key, NULL);
02732 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s;
02733 }
02734
02741 virtual PString * GetAt(
02742 const K & key
02743 ) const { return (PString *)AbstractGetAt(key); }
02744
02753 virtual BOOL SetDataAt(
02754 PINDEX index,
02755 const PString & str
02756 ) { return PAbstractDictionary::SetDataAt(index, PNEW PString(str)); }
02757
02769 virtual BOOL SetAt(
02770 const K & key,
02771 const PString & str
02772 ) { return AbstractSetAt(key, PNEW PString(str)); }
02773
02785 const K & GetKeyAt(PINDEX index) const
02786 { return (const K &)AbstractGetKeyAt(index); }
02787
02799 PString & GetDataAt(PINDEX index) const
02800 { return (PString &)AbstractGetDataAt(index); }
02802
02803 protected:
02804 PStringDictionary(int dummy, const PStringDictionary * c)
02805 : PAbstractDictionary(dummy, c) { }
02806 };
02807
02808
02823 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02824 PDECLARE_CLASS(cls, PStringDictionary<K>) \
02825 protected: \
02826 cls(int dummy, const cls * c) \
02827 : PStringDictionary<K>(dummy, c) { } \
02828 public: \
02829 cls() \
02830 : PStringDictionary<K>() { } \
02831 virtual PObject * Clone() const \
02832 { return PNEW cls(0, this); } \
02833
02834
02847 #define PSTRING_DICTIONARY(cls, K) typedef PStringDictionary<K> cls
02848
02849
02850 #else // PHAS_TEMPLATES
02851
02852
02853 #define PSTRING_DICTIONARY(cls, K) \
02854 class cls : public PAbstractDictionary { \
02855 PCLASSINFO(cls, PAbstractDictionary) \
02856 protected: \
02857 inline cls(int dummy, const cls * c) \
02858 : PAbstractDictionary(dummy, c) { } \
02859 public: \
02860 inline cls() \
02861 : PAbstractDictionary() { } \
02862 inline PObject * Clone() const \
02863 { return PNEW cls(0, this); } \
02864 inline PString & operator[](const K & key) const \
02865 { return (PString &)GetRefAt(key); } \
02866 inline PString operator()(const K & key, const char * dflt = "") const \
02867 { if (Contains(key)) return (PString &)GetRefAt(key); return dflt; } \
02868 virtual BOOL Contains(const K & key) const \
02869 { return AbstractContains(key); } \
02870 virtual PString * RemoveAt(const K & key) \
02871 { PString * s = GetAt(key); AbstractSetAt(key, NULL); \
02872 return reference->deleteObjects ? (s ? (PString *)-1 : NULL) : s; } \
02873 virtual PString * GetAt(const K & key) const \
02874 { return (PString *)AbstractGetAt(key); } \
02875 virtual BOOL SetDataAt(PINDEX index, const PString & str) \
02876 { return PAbstractDictionary::SetDataAt(index,PNEW PString(str));} \
02877 virtual BOOL SetAt(const K & key, const PString & str) \
02878 { return AbstractSetAt(key, PNEW PString(str)); } \
02879 inline const K & GetKeyAt(PINDEX index) const \
02880 { return (const K &)AbstractGetKeyAt(index); } \
02881 inline PString & GetDataAt(PINDEX index) const \
02882 { return (PString &)AbstractGetDataAt(index); } \
02883 }
02884
02885 #define PDECLARE_STRING_DICTIONARY(cls, K) \
02886 PSTRING_DICTIONARY(cls##_PTemplate, K); \
02887 PDECLARE_CLASS(cls, cls##_PTemplate) \
02888 protected: \
02889 cls(int dummy, const cls * c) \
02890 : cls##_PTemplate(dummy, c) { } \
02891 public: \
02892 cls() \
02893 : cls##_PTemplate() { } \
02894 virtual PObject * Clone() const \
02895 { return PNEW cls(0, this); } \
02896
02897 #endif // PHAS_TEMPLATES
02898
02899
02914 #ifdef DOC_PLUS_PLUS
02915 class POrdinalToString : public PStringDictionary {
02916 #endif
02917 PDECLARE_STRING_DICTIONARY(POrdinalToString, POrdinalKey);
02918 public:
02921
02922 struct Initialiser {
02924 PINDEX key;
02926 const char * value;
02927 };
02930 POrdinalToString(
02931 PINDEX count,
02932 const Initialiser * init
02933 );
02935
02943 virtual void ReadFrom(
02944 istream &strm
02945 );
02947 };
02948
02961 #ifdef DOC_PLUS_PLUS
02962 class PStringToOrdinal : public POrdinalDictionary {
02963 #endif
02964 PDECLARE_ORDINAL_DICTIONARY(PStringToOrdinal, PString);
02965 public:
02968
02969 struct Initialiser {
02971 const char * key;
02973 PINDEX value;
02974 };
02977 PStringToOrdinal(
02978 PINDEX count,
02979 const Initialiser * init,
02980 BOOL caseless = FALSE
02981 );
02983
02991 virtual void ReadFrom(
02992 istream &strm
02993 );
02995 };
02996
02997
03011 #ifdef DOC_PLUS_PLUS
03012 class PStringToString : public PStringDictionary {
03013 #endif
03014 PDECLARE_STRING_DICTIONARY(PStringToString, PString);
03015 public:
03018
03019 struct Initialiser {
03021 const char * key;
03023 const char * value;
03024 };
03027 PStringToString(
03028 PINDEX count,
03029 const Initialiser * init,
03030 BOOL caselessKeys = FALSE,
03031 BOOL caselessValues = FALSE
03032 );
03034
03042 virtual void ReadFrom(
03043 istream &strm
03044 );
03046 };
03047
03048
03054 class PRegularExpression : public PObject
03055 {
03056 PCLASSINFO(PRegularExpression, PObject);
03057
03058 public:
03061
03062 enum {
03064 Extended = 1,
03066 IgnoreCase = 2,
03071 AnchorNewLine = 4
03072 };
03074 enum {
03081 NotBeginningOfLine = 1,
03083 NotEndofLine = 2
03084 };
03085
03087 PRegularExpression();
03088
03091 PRegularExpression(
03092 const PString & pattern,
03093 int flags = IgnoreCase
03094 );
03095
03098 PRegularExpression(
03099 const char * cpattern,
03100 int flags = IgnoreCase
03101 );
03102
03106 PRegularExpression(
03107 const PRegularExpression &
03108 );
03109
03113 PRegularExpression & operator =(
03114 const PRegularExpression &
03115 );
03116
03118 ~PRegularExpression();
03120
03123
03124 enum ErrorCodes {
03126 NoError = 0,
03128 NoMatch,
03129
03130
03132 BadPattern,
03134 CollateError,
03136 BadClassType,
03138 BadEscape,
03140 BadSubReg,
03142 UnmatchedBracket,
03144 UnmatchedParen,
03146 UnmatchedBrace,
03148 BadBR,
03150 RangeError,
03152 OutOfMemory,
03154 BadRepitition,
03155
03156
03158 PrematureEnd,
03160 TooBig,
03162 UnmatchedRParen,
03164 NotCompiled
03165 };
03166
03172 ErrorCodes GetErrorCode() const;
03173
03180 PString GetErrorText() const;
03182
03186 BOOL Compile(
03187 const PString & pattern,
03188 int flags = IgnoreCase
03189 );
03197 BOOL Compile(
03198 const char * cpattern,
03199 int flags = IgnoreCase
03200 );
03201
03202
03204 BOOL Execute(
03205 const PString & str,
03206 PINDEX & start,
03207 int flags = 0
03208 ) const;
03210 BOOL Execute(
03211 const PString & str,
03212 PINDEX & start,
03213 PINDEX & len,
03214 int flags = 0
03215 ) const;
03217 BOOL Execute(
03218 const char * cstr,
03219 PINDEX & start,
03220 int flags = 0
03221 ) const;
03223 BOOL Execute(
03224 const char * cstr,
03225 PINDEX & start,
03226 PINDEX & len,
03227 int flags = 0
03228 ) const;
03230 BOOL Execute(
03231 const PString & str,
03232 PIntArray & starts,
03233 int flags = 0
03234 ) const;
03236 BOOL Execute(
03237 const PString & str,
03238 PIntArray & starts,
03239 PIntArray & ends,
03240 int flags = 0
03241 ) const;
03243 BOOL Execute(
03244 const char * cstr,
03245 PIntArray & starts,
03246 int flags = 0
03247 ) const;
03263 BOOL Execute(
03264 const char * cstr,
03265 PIntArray & starts,
03266 PIntArray & ends,
03267 int flags = 0
03268 ) const;
03270
03279 static PString EscapeString(
03280 const PString & str
03281 );
03283
03284 protected:
03285 PString patternSaved;
03286 int flagsSaved;
03287
03288 void * expression;
03289 mutable ErrorCodes lastError;
03290 };
03291
03292 PString psprintf(const char * cfmt, ...);
03293
03294 #endif // #ifndef __PSTRING__
03295