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 "string-data.hh"
16 const int INITIALMAX=8;
18 #include <sys/types.h>
23 assert (references == 1);
29 assert(maxlen >= length_i_);
30 assert(bool(data_byte_p_));
31 assert(references >= 1);
36 String_data::String_data()
40 data_byte_p_ = new Byte[maxlen + 1];
46 String_data::String_data(String_data const &src)
49 maxlen = length_i_ = src.length_i_;
50 data_byte_p_ = new Byte[maxlen+1]; // should calc GNU 8byte overhead.
51 memcpy( data_byte_p_, src.data_byte_p_, length_i_ + 1 );
55 String_data::~String_data()
57 assert(references == 0);
58 delete[] data_byte_p_;
62 String_data::setmax(int j)
68 data_byte_p_ = new Byte[maxlen + 1];
75 /* this is all quite hairy:
82 define change authority
85 String_data::remax(int j)
89 Byte *p = new Byte[j + 1];
90 memcpy( p, data_byte_p_, ( maxlen <? length_i_ ) + 1 );
92 delete[] data_byte_p_;
98 String_data::tighten()
99 { // should be dec'd const
101 Byte *p = new Byte[maxlen + 1];
102 memcpy( p, data_byte_p_, length_i_ + 1 );
103 delete[] data_byte_p_;
108 String_data::set( Byte const* byte_C, int length_i )
112 assert( byte_C && byte_C != data_byte_p_);
114 length_i_ = length_i;
115 remax( length_i_ ); // copies too
116 memcpy( data_byte_p_, byte_C, length_i_ );
117 data_byte_p_[ length_i_ ] = 0;
122 String_data::set( char const* ch_C )
124 set( (Byte const*)ch_C, strlen( ch_C ) );
130 String_data::append( Byte const* byte_C, int length_i )
134 int old_i = length_i_;
136 length_i_ += length_i;
138 memcpy( data_byte_p_ + old_i, byte_C, length_i );
139 data_byte_p_[ length_i_ ] = 0;
144 String_data::operator += ( char const* ch_C )
146 append( (Byte const*)ch_C, strlen( ch_C ) );
153 String_data::ch_C() const
155 return (char const*)data_byte_p_;
160 return (char*)data_byte_p_;
164 String_data::byte_C() const
170 String_data::byte_l()
178 String_data::trunc(int j)
181 assert(j >= 0 && j <= length_i_);
187 String_data::is_binary_bo()const
189 // return !memchr(data_byte_p_, length_i_, 0);
190 return ( (int)strlen( (char const*)data_byte_p_ ) != length_i_ );
194 String_data::operator [](int j)
196 assert(j >= 0 && j <= length_i_);
197 return data_byte_p_[j] ;
201 String_data::operator [](int j) const
203 assert(j >= 0 && j <= length_i_);
204 return data_byte_p_[j];
210 #endif // __STRING_UTIL_CC //