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 #ifndef _terimber_string_h_
00029 #define _terimber_string_h_
00030
00031 #include "base/memory.h"
00032
00033 BEGIN_TERIMBER_NAMESPACE
00034 #pragma pack(4)
00035
00038 template < class T >
00039 class base_string
00040 {
00043 enum
00044 en_base_string_size
00045 {
00046 S = sizeof(T)
00047 };
00048 public:
00050 base_string< T >(byte_allocator* allocator_ = 0
00051 );
00053 ~base_string< T >();
00055 base_string< T >(const T* x,
00056 byte_allocator* allocator_ = 0
00057 );
00059 base_string< T >(const base_string< T >& x);
00062 inline
00063 operator const T*() const
00064 {
00065 return _handle;
00066 }
00068 base_string< T >& operator=(const base_string< T >& x);
00070 base_string< T >&
00071 operator=( const T* x
00072 );
00074 inline
00075 bool
00076 operator==(const base_string< T >& x) const;
00078 inline
00079 bool
00080 operator!=(const base_string< T >& x) const;
00082 inline
00083 bool
00084 operator<(const base_string< T >& x) const;
00086 inline
00087 bool
00088 operator<=(const base_string< T >& x) const;
00090 inline
00091 bool
00092 operator>(const base_string< T >& x) const;
00094 inline
00095 bool
00096 operator>=(const base_string< T >& x) const;
00098 inline
00099 base_string< T >&
00100 operator+=(const base_string< T >& x);
00103 inline
00104 bool
00105 operator==( const T* x
00106 ) const;
00108 inline
00109 bool
00110 operator!=( const T* x
00111 ) const;
00113 inline
00114 bool
00115 operator<( const T* x
00116 ) const;
00118 inline
00119 bool
00120 operator<=( const T* x
00121 ) const;
00123 inline
00124 bool
00125 operator>( const T* x
00126 ) const;
00128 inline
00129 bool
00130 operator>=( const T* x
00131 ) const;
00133 inline
00134 int
00135 compare( const T* x,
00136 size_t size = os_minus_one
00137 ) const;
00139 inline
00140 base_string< T >&
00141 operator+=( const T* x
00142 );
00144 inline
00145 base_string< T >&
00146 append( const T* x,
00147 size_t size = os_minus_one
00148 );
00150
00151 inline
00152 base_string< T >&
00153 assign( const T* x,
00154 size_t size = os_minus_one
00155 );
00157 inline
00158 size_t
00159 length() const;
00161 inline
00162 T*
00163 reserve( size_t size
00164 );
00166 inline
00167 byte_allocator*
00168 get_allocator();
00169 private:
00171 inline
00172 int
00173 _compare( const T* x,
00174 size_t len = os_minus_one
00175 ) const;
00177 inline
00178 void
00179 _assign( const T* x,
00180 size_t len = os_minus_one
00181 );
00183 inline
00184 void
00185 _add( const T* x,
00186 size_t len = os_minus_one
00187 );
00189 inline
00190 void
00191 _create();
00193 inline
00194 void
00195 _destroy();
00196
00197 private:
00198 byte_allocator* _allocator;
00199 T* _handle;
00200 size_t _length;
00201 };
00202
00205 typedef base_string< char > string_t;
00208 typedef base_string< wchar_t > wstring_t;
00209
00212 namespace str_template
00213 {
00215 template < class T >
00216 inline
00217 size_t
00218 strlen( const T* x
00219 );
00221 template < class T >
00222 inline T*
00223 strcpy( T* dest,
00224 const T* x,
00225 size_t len = os_minus_one
00226 );
00228 template < class T >
00229 inline
00230 int
00231 strcmp( const T* dest,
00232 const T* x,
00233 size_t len = os_minus_one
00234 );
00236 inline
00237 int
00238 strnocasecmp( const char* dest,
00239 const char* x,
00240 size_t len
00241 );
00243 inline
00244 int
00245 strnocasecmp( const wchar_t* dest,
00246 const wchar_t* x,
00247 size_t len
00248 );
00250 inline
00251 const char*
00252 strformat( char* buf,
00253 const char* format
00254 );
00256 inline
00257 const
00258 wchar_t*
00259 strformat( wchar_t* buf,
00260 const char* format
00261 );
00262
00264 inline
00265 int
00266 strscan( const char* buf,
00267 size_t len,
00268 const char* format,
00269 void* res
00270 );
00272 inline
00273 int
00274 strscan( const wchar_t* buf,
00275 size_t len,
00276 const wchar_t* format,
00277 void* res
00278 );
00280 inline
00281 int
00282 strprint( char* buf,
00283 size_t len,
00284 const char* format,
00285 ...
00286 );
00288 inline
00289 int
00290 strprint( wchar_t* buf,
00291 size_t len,
00292 const wchar_t* format,
00293 ...
00294 );
00296 inline
00297 size_t
00298 multibyte_to_unicode_len(const char* x,
00299 size_t len = os_minus_one
00300 );
00302 inline
00303 size_t
00304 unicode_to_multibyte_len(const wchar_t* x,
00305 size_t len = os_minus_one
00306 );
00308 inline
00309 const wchar_t*
00310 multibyte_to_unicode(wchar_t* dest,
00311 size_t dest_len,
00312 const char* x,
00313 size_t src_len = os_minus_one
00314 );
00316 inline
00317 const wchar_t*
00318 multibyte_to_unicode(wstring_t& dest,
00319 const char* x,
00320 size_t len = os_minus_one
00321 );
00323 inline
00324 const wchar_t*
00325 multibyte_to_unicode(byte_allocator& _allocator,
00326 const char* x,
00327 size_t len = os_minus_one
00328 );
00330 inline
00331 const char*
00332 unicode_to_multibyte(char* dest,
00333 size_t dest_len,
00334 const wchar_t* x,
00335 size_t src_len = os_minus_one
00336 );
00338 inline
00339 const char*
00340 unicode_to_multibyte(string_t& dest,
00341 const wchar_t* x,
00342 size_t len = os_minus_one
00343 );
00345 inline
00346 const char*
00347 unicode_to_multibyte(byte_allocator& _allocator,
00348 const wchar_t* x,
00349 size_t len = os_minus_one
00350 );
00351
00352 }
00353
00354 #pragma pack()
00355 END_TERIMBER_NAMESPACE
00356
00357 #endif // _terimber_string_h_
00358