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 #ifndef OFSTRING_H
00034 #define OFSTRING_H
00035
00036 #include "dcmtk/config/osconfig.h"
00037 #include "dcmtk/ofstd/oftypes.h"
00038 #include "dcmtk/ofstd/ofcast.h"
00039
00040 #ifdef HAVE_STD_STRING
00041
00042
00043
00044
00045 #include <string>
00046
00047 #define OFString std::string
00048 #define OFString_npos std::string::npos
00049
00050 #else
00051
00052
00053
00054
00055
00056 #define INCLUDE_CASSERT
00057 #define INCLUDE_CSTRING
00058 #define INCLUDE_CSTDLIB
00059 #define INCLUDE_LIBC
00060 #define INCLUDE_UNISTD
00061 #include "dcmtk/ofstd/ofstdinc.h"
00062
00063 #include "dcmtk/ofstd/ofstream.h"
00064 #include "dcmtk/ofstd/oftypes.h"
00065
00066
00067
00068
00069 #define OFSTRING_OUTOFRANGE(cond) assert (!(cond))
00070 #define OFSTRING_LENGTHERROR(cond) assert (!(cond))
00071 #define OFSTRING_MEMORYALLOCERROR(cond) assert (!(cond))
00072
00078 static const size_t OFString_npos = (OFstatic_cast(size_t, -1));
00079
00080
00084 class OFString
00085 {
00086 public:
00087
00088
00089
00090
00091
00092
00093
00094
00097 OFString();
00098
00108 OFString(const OFString& str, size_t pos = 0, size_t n = OFString_npos);
00109
00118 OFString(const char* s, size_t n);
00119
00124 OFString(const char* s);
00125
00131 OFString(size_t rep, char c);
00132
00135 ~OFString();
00136
00141 OFString& operator=(const OFString& rhs);
00142
00147 OFString& operator=(const char* s);
00148
00153 OFString& operator=(char s);
00154
00159 OFString& operator+=(const OFString& rhs);
00160
00165 OFString& operator+=(const char* s);
00166
00171 OFString& operator+=(char s);
00172
00182 OFString& append(const OFString& str, size_t pos = 0, size_t n = OFString_npos);
00183
00189 OFString& append(const char* s, size_t n);
00190
00195 OFString& append(const char* s);
00196
00202 OFString& append(size_t rep, char c);
00203
00213 OFString& assign(const OFString& str, size_t pos = 0, size_t n = OFString_npos);
00214
00220 OFString& assign(const char* s, size_t n);
00221
00226 OFString& assign(const char* s);
00227
00233 OFString& assign(size_t rep, char c);
00234
00245 OFString& insert(size_t pos1, const OFString& str,
00246 size_t pos2 = 0, size_t n = OFString_npos);
00247
00255 OFString& insert(size_t pos, const char* s, size_t n);
00256
00263 OFString& insert(size_t pos, const char* s);
00264
00272 OFString& insert(size_t pos, size_t rep, char c);
00273
00279 OFString& erase (size_t pos = 0, size_t n = OFString_npos);
00280
00296 OFString& replace(size_t pos1, size_t n1, const OFString& str,
00297 size_t pos2 = 0, size_t n2 = OFString_npos);
00298
00307 OFString& replace(size_t pos, size_t n, const char* s, size_t n2);
00308
00316 OFString& replace(size_t pos, size_t n, const char* s);
00317
00326 OFString& replace(size_t pos, size_t n, size_t rep, char s);
00327
00334 const char& at(size_t pos) const
00335 {
00336 OFSTRING_OUTOFRANGE (pos >= this->size());
00337 return this->theCString[pos];
00338 }
00339
00346 char& at(size_t pos)
00347 {
00348 OFSTRING_OUTOFRANGE (pos >= this->size());
00349 return this->theCString[pos];
00350 }
00351
00357 char operator[] (size_t pos) const
00358 {
00359 if (pos == this->size()) return '\0';
00360 else
00361 {
00362 OFSTRING_OUTOFRANGE (pos > this->size());
00363 return this->theCString[pos];
00364 }
00365 }
00366
00373 char& operator[] (size_t pos)
00374 {
00375 OFSTRING_OUTOFRANGE (pos >= this->size());
00376 return this->theCString[pos];
00377 }
00378
00384 const char* c_str() const
00385 {
00386 return (this->theCString)?(this->theCString):("");
00387 }
00388
00396 const char* data() const;
00397
00402 size_t size() const
00403 {
00404 return (this->theCString)?(strlen(this->theCString)):(0);
00405 }
00406
00411 size_t length() const
00412 {
00413 return this->size();
00414 }
00415
00419 OFBool empty() const
00420 {
00421 return (this->size() == 0)?(OFTrue):(OFFalse);
00422 }
00423
00429 void resize (size_t n, char c = '\0');
00430
00434 size_t capacity () const
00435 {
00436 return this->theCapacity;
00437 }
00438
00442 size_t max_size() const
00443 {
00444 return ((OFString_npos - 1)/sizeof(char));
00445 }
00446
00449 void clear()
00450 {
00451 this->erase();
00452 }
00453
00462 void reserve(size_t res_arg);
00463
00474 size_t copy(char* s, size_t n, size_t pos = 0) const;
00475
00481 OFString substr(size_t pos = 0, size_t n = OFString_npos) const;
00482
00487 void swap(OFString& s);
00488
00499 int compare(const OFString& str) const;
00500
00508 int compare(size_t pos1, size_t n1, const OFString& str) const;
00509
00519 int compare(size_t pos1, size_t n1, const OFString& str,
00520 size_t pos2, size_t n2) const;
00521
00527 int compare(const char* s) const;
00528
00537 int compare(size_t pos1, size_t n1,
00538 const char* s, size_t n2 = OFString_npos) const;
00539
00549 size_t find(const OFString& pattern, size_t pos = 0) const;
00550
00561 size_t find(const char* pattern, size_t pos, size_t n) const;
00562
00572 size_t find(const char* pattern, size_t pos = 0) const;
00573
00583 size_t find(char pattern, size_t pos = 0) const;
00584
00594 size_t rfind(const OFString& pattern, size_t pos = OFString_npos) const;
00595
00606 size_t rfind(const char* pattern, size_t pos, size_t n) const;
00607
00617 size_t rfind(const char* pattern, size_t pos = OFString_npos) const;
00618
00628 size_t rfind(char pattern, size_t pos = OFString_npos) const;
00629
00639 size_t find_first_of(const OFString& str, size_t pos = 0) const;
00640
00651 size_t find_first_of(const char* s, size_t pos, size_t n) const;
00652
00662 size_t find_first_of(const char* s, size_t pos = 0) const;
00663
00673 size_t find_first_of(char s, size_t pos = 0) const;
00674
00683 size_t find_last_of(const OFString& str, size_t pos = OFString_npos) const;
00684
00694 size_t find_last_of(const char* s, size_t pos, size_t n) const;
00695
00704 size_t find_last_of(const char* s, size_t pos = OFString_npos) const;
00705
00714 size_t find_last_of(char s, size_t pos = OFString_npos) const;
00715
00724 size_t find_first_not_of(const OFString& str, size_t pos = 0) const;
00725
00735 size_t find_first_not_of(const char* s, size_t pos, size_t n) const;
00736
00745 size_t find_first_not_of(const char* s, size_t pos = 0) const;
00746
00755 size_t find_first_not_of(char c, size_t pos = 0) const;
00756
00766 size_t find_last_not_of(const OFString& str, size_t pos = OFString_npos) const;
00767
00778 size_t find_last_not_of(const char* s, size_t pos, size_t n) const;
00779
00789 size_t find_last_not_of(const char* s, size_t pos = OFString_npos) const;
00790
00800 size_t find_last_not_of(char c, size_t pos = OFString_npos) const;
00801
00802 private:
00804 char* theCString;
00805
00807 size_t theCapacity;
00808
00809 };
00810
00811
00817 ostream& operator<< (ostream& o, const OFString& s);
00818
00825 istream& operator>> (istream& i, OFString& s);
00826
00832 OFString operator+ (const OFString& lhs, const OFString& rhs);
00833
00839 OFString operator+ (const char* lhs, const OFString& rhs);
00840
00846 OFString operator+ (char lhs, const OFString& rhs);
00847
00853 OFString operator+ (const OFString& lhs, const char* rhs);
00854
00860 OFString operator+ (const OFString& lhs, char rhs);
00861
00867 OFBool operator== (const OFString& lhs, const OFString& rhs);
00868
00874 OFBool operator== (const char* lhs, const OFString& rhs);
00875
00881 OFBool operator== (char lhs, const OFString& rhs);
00882
00888 OFBool operator== (const OFString& lhs, const char* rhs);
00889
00895 OFBool operator== (const OFString& lhs, char rhs);
00896
00902 OFBool operator< (const OFString& lhs, const OFString& rhs);
00903
00909 OFBool operator< (const char* lhs, const OFString& rhs);
00910
00916 OFBool operator< (char lhs, const OFString& rhs);
00917
00923 OFBool operator< (const OFString& lhs, const char* rhs);
00924
00930 OFBool operator< (const OFString& lhs, char rhs);
00931
00937 OFBool operator<= (const OFString& lhs, const OFString& rhs);
00938
00944 OFBool operator<= (const char* lhs, const OFString& rhs);
00945
00951 OFBool operator<= (char lhs, const OFString& rhs);
00952
00958 OFBool operator<= (const OFString& lhs, const char* rhs);
00959
00965 OFBool operator<= (const OFString& lhs, char rhs);
00966
00972 OFBool operator!= (const OFString& lhs, const OFString& rhs);
00973
00979 OFBool operator!= (const char* lhs, const OFString& rhs);
00980
00986 OFBool operator!= (char lhs, const OFString& rhs);
00987
00993 OFBool operator!= (const OFString& lhs, const char* rhs);
00994
01000 OFBool operator!= (const OFString& lhs, char rhs);
01001
01007 OFBool operator> (const OFString& lhs, const OFString& rhs);
01008
01014 OFBool operator> (const char* lhs, const OFString& rhs);
01015
01021 OFBool operator> (char lhs, const OFString& rhs);
01022
01028 OFBool operator> (const OFString& lhs, const char* rhs);
01029
01035 OFBool operator> (const OFString& lhs, char rhs);
01036
01042 OFBool operator>= (const OFString& lhs, const OFString& rhs);
01043
01049 OFBool operator>= (const char* lhs, const OFString& rhs);
01050
01056 OFBool operator>= (char lhs, const OFString& rhs);
01057
01063 OFBool operator>= (const OFString& lhs, const char* rhs);
01064
01070 OFBool operator>= (const OFString& lhs, char rhs);
01071
01072 #endif
01073
01074 #endif
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
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