2 #ifndef __STRING_UTIL_CC
3 #define __STRING_UTIL_CC
6 // * reading stringutil.hh, or
7 // * string util stuff not inlined
8 #if !defined STRING_UTILS_INLINED
12 #include "stringutil.hh"
15 // namespace StringData { namespaces are broken in this version of g++
16 // gcc version 2.7.2.1
19 StringData::StringData()
23 data_by_p_ = new Byte[maxlen + 1];
28 StringData::StringData(StringData const &src)
31 maxlen = length_i_ = src.length_i_;
32 data_by_p_ = new Byte[maxlen+1]; // should calc GNU 8byte overhead.
33 memmove( data_by_p_, src.data_by_p_, length_i_ + 1 );
37 StringData::~StringData()
39 assert(references == 0);
44 StringData::setmax(int j)
50 data_by_p_ = new Byte[maxlen + 1];
59 StringData::remax(int j)
64 Byte *p = new Byte[maxlen + 1];
65 memmove( p, data_by_p_, length_i_ + 1 );
68 // length_i_ = strlength_i(data_by_p_);
76 assert (references == 1);
82 // can-t do this with binary data
83 // assert(strlen(data_by_p_) == size_t(length_i_));
84 assert(maxlen >= length_i_);
85 assert(bool(data_by_p_));
86 assert(references >= 1);
90 // well, we can't -> depreciated
92 // length_i_ = strlen (data_by_p_);
98 { // should be dec'd const
100 Byte *p = new Byte[maxlen + 1];
101 memmove( p, data_by_p_, length_i_ + 1 );
108 StringData::set( Byte const* by_c_l, int length_i )
112 assert( by_c_l && by_c_l != data_by_p_);
114 length_i_ = length_i;
116 memmove( data_by_p_, by_c_l, length_i_ );
117 data_by_p_[ length_i_ ] = 0;
122 StringData::set( char const* ch_c_l )
124 set( (Byte const*)ch_c_l, strlen( ch_c_l ) );
130 StringData::append( Byte const* by_c_l, int length_i )
134 int old_i = length_i_;
136 length_i_ += length_i;
138 memmove( data_by_p_ + old_i, by_c_l, length_i );
139 data_by_p_[ length_i_ ] = 0;
144 StringData::operator += ( char const* ch_c_l )
146 append( (Byte const*)ch_c_l, strlen( ch_c_l ) );
150 StringData::ch_c_l() const
152 return (char const*)data_by_p_;
158 return (char*)data_by_p_;
162 StringData::by_c_l() const
176 StringData::trunc(int j)
179 assert(j >= 0 && j <= length_i_);
185 StringData::operator [](int j)
187 assert(j >= 0 && j <= length_i_);
188 return data_by_p_[j] ;
192 StringData::operator [](int j) const
194 assert(j >= 0 && j <= length_i_);
195 return data_by_p_[j];
199 // } namespace broken
204 // namespace String_handle {
208 String_handle::down()
210 if (!(--data->references)) delete data; data = 0;
213 /// increase ref count
215 String_handle::up(StringData *d)
217 data=d; data->references ++;
221 String_handle::copy()
223 if (data->references !=1){
224 StringData *newdata = new StringData(*data);
230 String_handle::String_handle()
234 String_handle::~String_handle()
238 String_handle::String_handle(String_handle const & src)
244 String_handle::by_l()
251 String_handle::ch_l()
254 return (char*)data->by_l();
258 const* String_handle::by_c_l() const
260 return data->by_c_l();
264 String_handle::ch_c_l() const
266 return (char const*)data->by_c_l();
270 String_handle::operator =(String_handle const &src)
279 String_handle::operator += (char const *s)
287 String_handle::operator[](int j) const
293 // don't use this for loops. Use by_c_l()
295 String_handle::operator[](int j)
297 copy(); // hmm. Not efficient
298 return data->by_l()[j];
302 String_handle::append( Byte const* by_c_l, int length_i )
305 data->append( by_c_l, length_i );
309 String_handle::set( Byte const* by_c_l, int length_i )
312 data->set( by_c_l, length_i );
316 String_handle::operator = (char const *p)
323 String_handle::trunc(int j)
325 copy(); data->trunc(j);
329 String_handle::length_i() const
331 return data->length_i_;
335 // } namespaces broken
338 #endif // not STRING_UTILS_INLINED //
340 #endif // __STRING_UTIL_CC //