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 "osconfig.h"
00037 #include "oftypes.h"
00038 #include "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 #include "ofstdinc.h"
00060
00061 BEGIN_EXTERN_C
00062 #ifdef HAVE_UNISTD_H
00063 #include <unistd.h>
00064 #endif
00065 #ifdef HAVE_LIBC_H
00066 #include <libc.h>
00067 #endif
00068 END_EXTERN_C
00069
00070 #include "ofstream.h"
00071 #include "oftypes.h"
00072
00073
00074
00075
00076 #define OFSTRING_OUTOFRANGE(cond) assert (!(cond))
00077 #define OFSTRING_LENGTHERROR(cond) assert (!(cond))
00078 #define OFSTRING_MEMORYALLOCERROR(cond) assert (!(cond))
00079
00085 static const size_t OFString_npos = (OFstatic_cast(size_t, -1));
00086
00087
00091 class OFString
00092 {
00093 public:
00094
00095
00096
00097
00098
00099
00100
00101
00104 OFString();
00105
00115 OFString(const OFString& str, size_t pos = 0, size_t n = OFString_npos);
00116
00125 OFString(const char* s, size_t n);
00126
00131 OFString(const char* s);
00132
00138 OFString(size_t rep, char c);
00139
00142 ~OFString();
00143
00148 OFString& operator=(const OFString& rhs);
00149
00154 OFString& operator=(const char* s);
00155
00160 OFString& operator=(char s);
00161
00166 OFString& operator+=(const OFString& rhs);
00167
00172 OFString& operator+=(const char* s);
00173
00178 OFString& operator+=(char s);
00179
00189 OFString& append(const OFString& str, size_t pos = 0, size_t n = OFString_npos);
00190
00196 OFString& append(const char* s, size_t n);
00197
00202 OFString& append(const char* s);
00203
00209 OFString& append(size_t rep, char c);
00210
00220 OFString& assign(const OFString& str, size_t pos = 0, size_t n = OFString_npos);
00221
00227 OFString& assign(const char* s, size_t n);
00228
00233 OFString& assign(const char* s);
00234
00240 OFString& assign(size_t rep, char c);
00241
00252 OFString& insert(size_t pos1, const OFString& str,
00253 size_t pos2 = 0, size_t n = OFString_npos);
00254
00262 OFString& insert(size_t pos, const char* s, size_t n);
00263
00270 OFString& insert(size_t pos, const char* s);
00271
00279 OFString& insert(size_t pos, size_t rep, char c);
00280
00286 OFString& erase (size_t pos = 0, size_t n = OFString_npos);
00287
00303 OFString& replace(size_t pos1, size_t n1, const OFString& str,
00304 size_t pos2 = 0, size_t n2 = OFString_npos);
00305
00314 OFString& replace(size_t pos, size_t n, const char* s, size_t n2);
00315
00323 OFString& replace(size_t pos, size_t n, const char* s);
00324
00333 OFString& replace(size_t pos, size_t n, size_t rep, char s);
00334
00341 const char& at(size_t pos) const
00342 {
00343 OFSTRING_OUTOFRANGE (pos >= this->size());
00344 return this->theCString[pos];
00345 }
00346
00353 char& at(size_t pos)
00354 {
00355 OFSTRING_OUTOFRANGE (pos >= this->size());
00356 return this->theCString[pos];
00357 }
00358
00364 char operator[] (size_t pos) const
00365 {
00366 if (pos == this->size()) return '\0';
00367 else
00368 {
00369 OFSTRING_OUTOFRANGE (pos > this->size());
00370 return this->theCString[pos];
00371 }
00372 }
00373
00380 char& operator[] (size_t pos)
00381 {
00382 OFSTRING_OUTOFRANGE (pos >= this->size());
00383 return this->theCString[pos];
00384 }
00385
00391 const char* c_str() const
00392 {
00393 return (this->theCString)?(this->theCString):("");
00394 }
00395
00403 const char* data() const;
00404
00409 size_t size() const
00410 {
00411 return (this->theCString)?(strlen(this->theCString)):(0);
00412 }
00413
00418 size_t length() const
00419 {
00420 return this->size();
00421 }
00422
00426 OFBool empty() const
00427 {
00428 return (this->size() == 0)?(OFTrue):(OFFalse);
00429 }
00430
00436 void resize (size_t n, char c = '\0');
00437
00441 size_t capacity () const
00442 {
00443 return this->theCapacity;
00444 }
00445
00449 size_t max_size() const
00450 {
00451 return ((OFString_npos - 1)/sizeof(char));
00452 }
00453
00456 void clear()
00457 {
00458 this->erase();
00459 }
00460
00469 void reserve(size_t res_arg);
00470
00481 size_t copy(char* s, size_t n, size_t pos = 0) const;
00482
00488 OFString substr(size_t pos = 0, size_t n = OFString_npos) const;
00489
00494 void swap(OFString& s);
00495
00506 int compare(const OFString& str) const;
00507
00515 int compare(size_t pos1, size_t n1, const OFString& str) const;
00516
00526 int compare(size_t pos1, size_t n1, const OFString& str,
00527 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,
00545 const char* s, size_t n2 = OFString_npos) const;
00546
00556 size_t find(const OFString& pattern, size_t pos = 0) const;
00557
00568 size_t find(const char* pattern, size_t pos, size_t n) const;
00569
00579 size_t find(const char* pattern, size_t pos = 0) const;
00580
00590 size_t find(char pattern, size_t pos = 0) const;
00591
00601 size_t rfind(const OFString& pattern, size_t pos = OFString_npos) const;
00602
00613 size_t rfind(const char* pattern, size_t pos, size_t n) const;
00614
00624 size_t rfind(const char* pattern, size_t pos = OFString_npos) const;
00625
00635 size_t rfind(char pattern, size_t pos = OFString_npos) const;
00636
00646 size_t find_first_of(const OFString& str, size_t pos = 0) const;
00647
00658 size_t find_first_of(const char* s, size_t pos, size_t n) const;
00659
00669 size_t find_first_of(const char* s, size_t pos = 0) const;
00670
00680 size_t find_first_of(char s, size_t pos = 0) const;
00681
00690 size_t find_last_of(const OFString& str, size_t pos = OFString_npos) const;
00691
00701 size_t find_last_of(const char* s, size_t pos, size_t n) const;
00702
00711 size_t find_last_of(const char* s, size_t pos = OFString_npos) const;
00712
00721 size_t find_last_of(char s, size_t pos = OFString_npos) const;
00722
00731 size_t find_first_not_of(const OFString& str, size_t pos = 0) const;
00732
00742 size_t find_first_not_of(const char* s, size_t pos, size_t n) const;
00743
00752 size_t find_first_not_of(const char* s, size_t pos = 0) const;
00753
00762 size_t find_first_not_of(char c, size_t pos = 0) const;
00763
00773 size_t find_last_not_of(const OFString& str, size_t pos = OFString_npos) const;
00774
00785 size_t find_last_not_of(const char* s, size_t pos, size_t n) const;
00786
00796 size_t find_last_not_of(const char* s, size_t pos = OFString_npos) const;
00797
00807 size_t find_last_not_of(char c, size_t pos = OFString_npos) const;
00808
00809 private:
00811 char* theCString;
00812
00814 size_t theCapacity;
00815
00816 };
00817
00818
00824 ostream& operator<< (ostream& o, const OFString& s);
00825
00832 istream& operator>> (istream& i, OFString& s);
00833
00839 OFString operator+ (const OFString& lhs, const OFString& rhs);
00840
00846 OFString operator+ (const char* lhs, const OFString& rhs);
00847
00853 OFString operator+ (char lhs, const OFString& rhs);
00854
00860 OFString operator+ (const OFString& lhs, const char* rhs);
00861
00867 OFString operator+ (const OFString& lhs, char rhs);
00868
00874 OFBool operator== (const OFString& lhs, const OFString& rhs);
00875
00881 OFBool operator== (const char* lhs, const OFString& rhs);
00882
00888 OFBool operator== (char lhs, const OFString& rhs);
00889
00895 OFBool operator== (const OFString& lhs, const char* rhs);
00896
00902 OFBool operator== (const OFString& lhs, char rhs);
00903
00909 OFBool operator< (const OFString& lhs, const OFString& rhs);
00910
00916 OFBool operator< (const char* lhs, const OFString& rhs);
00917
00923 OFBool operator< (char lhs, const OFString& rhs);
00924
00930 OFBool operator< (const OFString& lhs, const char* rhs);
00931
00937 OFBool operator< (const OFString& lhs, char rhs);
00938
00944 OFBool operator<= (const OFString& lhs, const OFString& rhs);
00945
00951 OFBool operator<= (const char* lhs, const OFString& rhs);
00952
00958 OFBool operator<= (char lhs, const OFString& rhs);
00959
00965 OFBool operator<= (const OFString& lhs, const char* rhs);
00966
00972 OFBool operator<= (const OFString& lhs, char rhs);
00973
00979 OFBool operator!= (const OFString& lhs, const OFString& rhs);
00980
00986 OFBool operator!= (const char* lhs, const OFString& rhs);
00987
00993 OFBool operator!= (char lhs, const OFString& rhs);
00994
01000 OFBool operator!= (const OFString& lhs, const char* rhs);
01001
01007 OFBool operator!= (const OFString& lhs, char rhs);
01008
01014 OFBool operator> (const OFString& lhs, const OFString& rhs);
01015
01021 OFBool operator> (const char* lhs, const OFString& rhs);
01022
01028 OFBool operator> (char lhs, const OFString& rhs);
01029
01035 OFBool operator> (const OFString& lhs, const char* rhs);
01036
01042 OFBool operator> (const OFString& lhs, char rhs);
01043
01049 OFBool operator>= (const OFString& lhs, const OFString& rhs);
01050
01056 OFBool operator>= (const char* lhs, const OFString& rhs);
01057
01063 OFBool operator>= (char lhs, const OFString& rhs);
01064
01070 OFBool operator>= (const OFString& lhs, const char* rhs);
01071
01077 OFBool operator>= (const OFString& lhs, char rhs);
01078
01079 #endif
01080
01081 #endif
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
01145