00001 #ifndef _CTBstring_HXX
00002 #define _CTBstring_HXX 1
00003
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CTBgrab.hxx"
00017 #include "CTBsharedBuffer.hxx"
00018
00019 class CTBstring {
00020 public:
00021 CTBstring();
00022 CTBstring(const CTBstring& rhs);
00023 CTBstring(CTBstring& rhs, bool b_grab);
00024 CTBstring(const CTBstring& rhs, CTBint i_length);
00025 CTBstring(const CTBstring& rhs, CTBint i_offset,
00026 CTBint i_length);
00027 CTBstring(const char* c_rhs);
00028 CTBstring(const char* c_rhs, CTBint i_length);
00029
00030 ~CTBstring();
00031
00032 const char* Data() const;
00033 CTBint Length() const;
00034
00035 bool IsNull() const;
00036 bool IsEmpty() const;
00037
00038 void Copy(const CTBstring& rhs);
00039 void Copy(const char* c_rhs);
00040 void Copy(char c_rhs);
00041
00042 void Append(const CTBstring& rhs);
00043 void Append(const char* c_rhs);
00044 void Append(const char* c_rhs, CTBint i_length);
00045 void Append(char c_rhs);
00046
00047 void Clear();
00048
00049 int Compare(const CTBstring& rhs) const;
00050 int Compare(const char* c_rhs) const;
00051
00052 int CompareCaseBlind(const CTBstring& rhs) const;
00053 int CompareCaseBlind(const char* c_rhs) const;
00054
00055 bool IsWhite() const;
00056 bool IsUpperCase() const;
00057 bool IsLowerCase() const;
00058
00059 void TrimWhite();
00060 void CollapseWhite();
00061 void ToUpperCase();
00062 void ToLowerCase();
00063
00064 bool Get(long& i_val, int i_base = 0) const;
00065 bool Get(unsigned long& i_val, int i_base = 0) const;
00066 bool Get(int& i_val, int i_base = 0) const;
00067 bool Get(unsigned int& i_val, int i_base = 0) const;
00068 bool Get(double& d_val) const;
00069 bool Get(float& f_val) const;
00070
00071 CTBint FindCharacter(char c, CTBint i_offset=0) const;
00072 CTBint FindCharacter(const char* c_set, CTBint i_offset=0) const;
00073 CTBint FindCharacter(const CTBstring& set,
00074 CTBint i_offset=0) const;
00075
00076 CTBstring Escape() const;
00077 CTBstring Unescape() const;
00078
00079 bool GetLine(istream& is);
00080
00081 void Grab(CTBstring& rhs);
00082
00083 void Dump(int i_indent=0, ostream& os=cout,
00084 const char* p_text=0) const;
00085
00086 CTBstring& operator=(const CTBstring& rhs);
00087 CTBstring& operator=(const char* c_rhs);
00088 CTBstring& operator=(char c_rhs);
00089
00090 CTBstring& operator+=(const CTBstring& rhs);
00091 CTBstring& operator+=(const char* c_rhs);
00092 CTBstring& operator+=(char c_rhs);
00093
00094 CTBstring& operator<<(const CTBstring& rhs);
00095 CTBstring& operator<<(const char* c_rhs);
00096 CTBstring& operator<<(char c_rhs);
00097
00098
00099 char operator[](CTBint i_ind) const;
00100
00101 CTBstring operator()(CTBint i_length) const;
00102 CTBstring operator()(CTBint i_offset, CTBint i_length) const;
00103
00104 operator const char*() const;
00105
00106 friend CTBstring operator+(const CTBstring& lhs,
00107 const CTBstring& rhs);
00108 friend CTBstring operator+(const CTBstring& lhs,
00109 const char* c_rhs);
00110 friend CTBstring operator+(const char* c_lhs,
00111 const CTBstring& rhs);
00112
00113 friend bool operator==(const CTBstring& lhs,
00114 const CTBstring& rhs);
00115 friend bool operator<(const CTBstring& lhs,
00116 const CTBstring& rhs);
00117
00118 friend bool operator==(const CTBstring& lhs,
00119 const char* c_rhs);
00120 friend bool operator<(const CTBstring& lhs,
00121 const char* c_rhs);
00122
00123 friend bool operator==(const char* c_lhs,
00124 const CTBstring& rhs);
00125 friend bool operator<(const char* c_lhs,
00126 const CTBstring& rhs);
00127
00128 friend ostream& operator<<(ostream& os, const CTBstring& rhs);
00129
00130 public:
00131 static const CTBstring& NullString();
00132 static const CTBstring& EmptyString();
00133
00134 private:
00135 void Unshare();
00136 void EnsureUnsharedCapacity(CTBint i_capacity);
00137 void NewString(const char* c_str, CTBint i_len);
00138 void NewString(const char* c_str1, CTBint i_len1,
00139 const char* c_str2, CTBint i_len2);
00140 void AppendData(const char* c_str, CTBint i_len);
00141 void Terminate();
00142
00143 CTBint FindCharacter(const char* c_set, CTBint i_len,
00144 CTBint i_offset) const;
00145
00146 private:
00147 CTBsharedBuffer<char> m_sbuf;
00148 CTBint mi_offset;
00149 CTBint mi_length;
00150 };
00151
00152 class CTBgrab<CTBstring> : public CTBgrabable<CTBstring> {};
00153
00154
00155
00156 #include "CTBstring.icc"
00157
00158 #endif