2 String_data.inl -- implement String_data
4 source file of Flower lib
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
10 #define STRINGDATA_INL
15 #include "stringdata.hh"
16 const int INITIALMAX=8;
20 INLINE void* mymemmove( void* dest, void* src, size_t n )
22 return memcpy( dest, src, n ); // wohltempererit: 69006
24 #define memmove mymemmove
30 assert (references == 1);
36 assert(maxlen >= length_i_);
37 assert(bool(data_byte_p_));
38 assert(references >= 1);
43 String_data::String_data()
47 data_byte_p_ = new Byte[maxlen + 1];
53 String_data::String_data(String_data const &src)
56 maxlen = length_i_ = src.length_i_;
57 data_byte_p_ = new Byte[maxlen+1]; // should calc GNU 8byte overhead.
58 memmove( data_byte_p_, src.data_byte_p_, length_i_ + 1 );
62 String_data::~String_data()
64 assert(references == 0);
65 delete[] data_byte_p_;
69 String_data::setmax(int j)
75 data_byte_p_ = new Byte[maxlen + 1];
82 /* this is all quite hairy:
89 define change authority
92 String_data::remax(int j)
97 // Byte *p = new Byte[maxlen + 1];
98 Byte *p = new Byte[j + 1];
99 memmove( p, data_byte_p_, ( maxlen <? length_i_ ) + 1 );
101 delete[] data_byte_p_;
107 String_data::tighten()
108 { // should be dec'd const
110 Byte *p = new Byte[maxlen + 1];
111 memmove( p, data_byte_p_, length_i_ + 1 );
112 delete[] data_byte_p_;
117 String_data::set( Byte const* byte_c_l, int length_i )
121 assert( byte_c_l && byte_c_l != data_byte_p_);
123 length_i_ = length_i;
124 remax( length_i_ ); // copies too
125 memmove( data_byte_p_, byte_c_l, length_i_ );
126 data_byte_p_[ length_i_ ] = 0;
131 String_data::set( char const* ch_c_l )
133 set( (Byte const*)ch_c_l, strlen( ch_c_l ) );
139 String_data::append( Byte const* byte_c_l, int length_i )
143 int old_i = length_i_;
145 length_i_ += length_i;
147 memmove( data_byte_p_ + old_i, byte_c_l, length_i );
148 data_byte_p_[ length_i_ ] = 0;
153 String_data::operator += ( char const* ch_c_l )
155 append( (Byte const*)ch_c_l, strlen( ch_c_l ) );
162 String_data::ch_c_l() const
164 return (char const*)data_byte_p_;
169 return (char*)data_byte_p_;
173 String_data::byte_c_l() const
179 String_data::byte_l()
187 String_data::trunc(int j)
190 assert(j >= 0 && j <= length_i_);
196 String_data::operator [](int j)
198 assert(j >= 0 && j <= length_i_);
199 return data_byte_p_[j] ;
203 String_data::operator [](int j) const
205 assert(j >= 0 && j <= length_i_);
206 return data_byte_p_[j];
212 #endif // __STRING_UTIL_CC //