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 #ifndef OFSTRING_H
00030 #define OFSTRING_H
00031
00032 #include "dcmtk/config/osconfig.h"
00033
00034 #include "dcmtk/ofstd/oftypes.h"
00035 #include "dcmtk/ofstd/ofcast.h"
00036
00037
00038
00039 #define OFSTRING_GUARD(c_string) ((c_string != NULL) ? (c_string) : "")
00040
00041
00042 #ifdef HAVE_STD_STRING
00043
00044
00045
00046
00047 #include <string>
00048
00049 #define OFString std::string
00050 #define OFString_npos std::string::npos
00051
00052 #else
00053
00054
00055
00056
00057
00058 #define INCLUDE_CASSERT
00059 #define INCLUDE_CSTRING
00060 #define INCLUDE_CSTDLIB
00061 #define INCLUDE_LIBC
00062 #define INCLUDE_UNISTD
00063 #include "dcmtk/ofstd/ofstdinc.h"
00064
00065 #include "dcmtk/ofstd/ofstream.h"
00066 #include "dcmtk/ofstd/oftypes.h"
00067
00068
00069
00070
00071 #define OFSTRING_OUTOFRANGE(cond) assert (!(cond))
00072 #define OFSTRING_LENGTHERROR(cond) assert (!(cond))
00073 #define OFSTRING_MEMORYALLOCERROR(cond) assert (!(cond))
00074
00080 static const size_t OFString_npos = (OFstatic_cast(size_t, -1));
00081
00082
00086 class OFString
00087 {
00088 public:
00089
00090
00091
00092
00093
00094
00095
00096
00099 OFString();
00100
00110 OFString(const OFString& str, size_t pos = 0, size_t n = OFString_npos);
00111
00120 OFString(const char* s, size_t n);
00121
00126 OFString(const char* s);
00127
00133 OFString(size_t rep, char c);
00134
00137 ~OFString();
00138
00143 OFString& operator=(const OFString& rhs);
00144
00149 OFString& operator=(const char* s);
00150
00155 OFString& operator=(char s);
00156
00161 OFString& operator+=(const OFString& rhs);
00162
00167 OFString& operator+=(const char* s);
00168
00173 OFString& operator+=(char s);
00174
00184 OFString& append(const OFString& str, size_t pos = 0, size_t n = OFString_npos);
00185
00191 OFString& append(const char* s, size_t n);
00192
00197 OFString& append(const char* s);
00198
00204 OFString& append(size_t rep, char c);
00205
00215 OFString& assign(const OFString& str, size_t pos, size_t n);
00216
00221 OFString& assign(const OFString& str);
00222
00228 OFString& assign(const char* s, size_t n);
00229
00234 OFString& assign(const char* s);
00235
00241 OFString& assign(size_t rep, char c);
00242
00253 OFString& insert(size_t pos1, const OFString& str,
00254 size_t pos2 = 0, size_t n = OFString_npos);
00255
00263 OFString& insert(size_t pos, const char* s, size_t n);
00264
00271 OFString& insert(size_t pos, const char* s);
00272
00280 OFString& insert(size_t pos, size_t rep, char c);
00281
00287 OFString& erase(size_t pos = 0, size_t n = OFString_npos);
00288
00304 OFString& replace(size_t pos1, size_t n1, const OFString& str,
00305 size_t pos2 = 0, size_t n2 = OFString_npos);
00306
00315 OFString& replace(size_t pos, size_t n, const char* s, size_t n2);
00316
00324 OFString& replace(size_t pos, size_t n, const char* s);
00325
00334 OFString& replace(size_t pos, size_t n, size_t rep, char s);
00335
00342 const char& at(size_t pos) const
00343 {
00344 OFSTRING_OUTOFRANGE (pos >= this->size());
00345 return this->theCString[pos];
00346 }
00347
00354 char& at(size_t pos)
00355 {
00356 OFSTRING_OUTOFRANGE (pos >= this->size());
00357 return this->theCString[pos];
00358 }
00359
00365 char operator[] (size_t pos) const
00366 {
00367 if (pos == this->size()) return '\0';
00368 else
00369 {
00370 OFSTRING_OUTOFRANGE (pos > this->size());
00371 return this->theCString[pos];
00372 }
00373 }
00374
00381 char& operator[] (size_t pos)
00382 {
00383 OFSTRING_OUTOFRANGE (pos >= this->size());
00384 return this->theCString[pos];
00385 }
00386
00392 const char* c_str() const
00393 {
00394 return (this->theCString)?(this->theCString):("");
00395 }
00396
00404 const char* data() const;
00405
00410 size_t size() const
00411 {
00412 return this->theSize;
00413 }
00414
00419 size_t length() const
00420 {
00421 return this->size();
00422 }
00423
00427 OFBool empty() const
00428 {
00429 return (this->size() == 0)?(OFTrue):(OFFalse);
00430 }
00431
00437 void resize(size_t n, char c = '\0');
00438
00442 size_t capacity() const
00443 {
00444 return this->theCapacity;
00445 }
00446
00450 size_t max_size() const
00451 {
00452 return ((OFString_npos - 1)/sizeof(char));
00453 }
00454
00457 void clear()
00458 {
00459 this->erase();
00460 }
00461
00470 void reserve(size_t res_arg);
00471
00482 size_t copy(char* s, size_t n, size_t pos = 0) const;
00483
00489 OFString substr(size_t pos = 0, size_t n = OFString_npos) const;
00490
00495 void swap(OFString& s);
00496
00507 int compare(const OFString& str) const;
00508
00516 int compare(size_t pos1, size_t n1, const OFString& str) const;
00517
00527 int compare(size_t pos1, size_t n1, const OFString& str, size_t pos2, size_t n2) const;
00528
00534 int compare(const char* s) const;
00535
00544 int compare(size_t pos1, size_t n1, const char* s, size_t n2 = OFString_npos) const;
00545
00555 size_t find(const OFString& pattern, size_t pos = 0) const;
00556
00567 size_t find(const char* pattern, size_t pos, size_t n) const;
00568
00578 size_t find(const char* pattern, size_t pos = 0) const;
00579
00589 size_t find(char pattern, size_t pos = 0) const;
00590
00600 size_t rfind(const OFString& pattern, size_t pos = OFString_npos) const;
00601
00612 size_t rfind(const char* pattern, size_t pos, size_t n) const;
00613
00623 size_t rfind(const char* pattern, size_t pos = OFString_npos) const;
00624
00634 size_t rfind(char pattern, size_t pos = OFString_npos) const;
00635
00645 size_t find_first_of(const OFString& str, size_t pos = 0) const;
00646
00657 size_t find_first_of(const char* s, size_t pos, size_t n) const;
00658
00668 size_t find_first_of(const char* s, size_t pos = 0) const;
00669
00679 size_t find_first_of(char s, size_t pos = 0) const;
00680
00689 size_t find_last_of(const OFString& str, size_t pos = OFString_npos) const;
00690
00700 size_t find_last_of(const char* s, size_t pos, size_t n) const;
00701
00710 size_t find_last_of(const char* s, size_t pos = OFString_npos) const;
00711
00720 size_t find_last_of(char s, size_t pos = OFString_npos) const;
00721
00730 size_t find_first_not_of(const OFString& str, size_t pos = 0) const;
00731
00741 size_t find_first_not_of(const char* s, size_t pos, size_t n) const;
00742
00751 size_t find_first_not_of(const char* s, size_t pos = 0) const;
00752
00761 size_t find_first_not_of(char c, size_t pos = 0) const;
00762
00772 size_t find_last_not_of(const OFString& str, size_t pos = OFString_npos) const;
00773
00784 size_t find_last_not_of(const char* s, size_t pos, size_t n) const;
00785
00795 size_t find_last_not_of(const char* s, size_t pos = OFString_npos) const;
00796
00806 size_t find_last_not_of(char c, size_t pos = OFString_npos) const;
00807
00809 typedef size_t size_type;
00810
00812 typedef char value_type;
00813
00818 typedef const char* iterator;
00819
00821 typedef iterator const_iterator;
00822
00826 iterator begin() const { return theCString; }
00827
00831 iterator end() const { return begin() + length(); }
00832
00833 private:
00835 char* theCString;
00836
00838 size_t theSize;
00839
00841 size_t theCapacity;
00842
00843 };
00844
00845
00851 STD_NAMESPACE ostream& operator<< (STD_NAMESPACE ostream& o, const OFString& s);
00852
00859 STD_NAMESPACE istream& operator>> (STD_NAMESPACE istream& i, OFString& s);
00860
00866 OFString operator+ (const OFString& lhs, const OFString& rhs);
00867
00873 OFString operator+ (const char* lhs, const OFString& rhs);
00874
00880 OFString operator+ (char lhs, const OFString& rhs);
00881
00887 OFString operator+ (const OFString& lhs, const char* rhs);
00888
00894 OFString operator+ (const OFString& lhs, char rhs);
00895
00901 OFBool operator== (const OFString& lhs, const OFString& rhs);
00902
00908 OFBool operator== (const char* lhs, const OFString& rhs);
00909
00915 OFBool operator== (char lhs, const OFString& rhs);
00916
00922 OFBool operator== (const OFString& lhs, const char* rhs);
00923
00929 OFBool operator== (const OFString& lhs, char rhs);
00930
00936 OFBool operator< (const OFString& lhs, const OFString& rhs);
00937
00943 OFBool operator< (const char* lhs, const OFString& rhs);
00944
00950 OFBool operator< (char lhs, const OFString& rhs);
00951
00957 OFBool operator< (const OFString& lhs, const char* rhs);
00958
00964 OFBool operator< (const OFString& lhs, char rhs);
00965
00971 OFBool operator<= (const OFString& lhs, const OFString& rhs);
00972
00978 OFBool operator<= (const char* lhs, const OFString& rhs);
00979
00985 OFBool operator<= (char lhs, const OFString& rhs);
00986
00992 OFBool operator<= (const OFString& lhs, const char* rhs);
00993
00999 OFBool operator<= (const OFString& lhs, char rhs);
01000
01006 OFBool operator!= (const OFString& lhs, const OFString& rhs);
01007
01013 OFBool operator!= (const char* lhs, const OFString& rhs);
01014
01020 OFBool operator!= (char lhs, const OFString& rhs);
01021
01027 OFBool operator!= (const OFString& lhs, const char* rhs);
01028
01034 OFBool operator!= (const OFString& lhs, char rhs);
01035
01041 OFBool operator> (const OFString& lhs, const OFString& rhs);
01042
01048 OFBool operator> (const char* lhs, const OFString& rhs);
01049
01055 OFBool operator> (char lhs, const OFString& rhs);
01056
01062 OFBool operator> (const OFString& lhs, const char* rhs);
01063
01069 OFBool operator> (const OFString& lhs, char rhs);
01070
01076 OFBool operator>= (const OFString& lhs, const OFString& rhs);
01077
01083 OFBool operator>= (const char* lhs, const OFString& rhs);
01084
01090 OFBool operator>= (char lhs, const OFString& rhs);
01091
01097 OFBool operator>= (const OFString& lhs, const char* rhs);
01098
01104 OFBool operator>= (const OFString& lhs, char rhs);
01105
01106 #endif
01107
01108 #endif
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212