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;
18 #include <sys/types.h>
20 mymemmove( void* dest, void const* src, size_t n );
21 #if 0 // redef STRING_DEBUG
23 mymemmove( void* dest, void const* src, size_t n )
25 return memmove( dest, src, n ); // wohltempererit: 69006
27 #define memmove mymemmove
33 assert (references == 1);
39 assert(maxlen >= length_i_);
40 assert(bool(data_byte_p_));
41 assert(references >= 1);
46 String_data::String_data()
50 data_byte_p_ = new Byte[maxlen + 1];
56 String_data::String_data(String_data const &src)
59 maxlen = length_i_ = src.length_i_;
60 data_byte_p_ = new Byte[maxlen+1]; // should calc GNU 8byte overhead.
61 memmove( data_byte_p_, src.data_byte_p_, length_i_ + 1 );
65 String_data::~String_data()
67 assert(references == 0);
68 delete[] data_byte_p_;
72 String_data::setmax(int j)
78 data_byte_p_ = new Byte[maxlen + 1];
85 /* this is all quite hairy:
92 define change authority
95 String_data::remax(int j)
100 // Byte *p = new Byte[maxlen + 1];
101 Byte *p = new Byte[j + 1];
102 memmove( p, data_byte_p_, ( maxlen <? length_i_ ) + 1 );
104 delete[] data_byte_p_;
110 String_data::tighten()
111 { // should be dec'd const
113 Byte *p = new Byte[maxlen + 1];
114 memmove( p, data_byte_p_, length_i_ + 1 );
115 delete[] data_byte_p_;
120 String_data::set( Byte const* byte_c_l, int length_i )
124 assert( byte_c_l && byte_c_l != data_byte_p_);
126 length_i_ = length_i;
127 remax( length_i_ ); // copies too
128 memmove( data_byte_p_, byte_c_l, length_i_ );
129 data_byte_p_[ length_i_ ] = 0;
134 String_data::set( char const* ch_c_l )
136 set( (Byte const*)ch_c_l, strlen( ch_c_l ) );
142 String_data::append( Byte const* byte_c_l, int length_i )
146 int old_i = length_i_;
148 length_i_ += length_i;
150 memmove( data_byte_p_ + old_i, byte_c_l, length_i );
151 data_byte_p_[ length_i_ ] = 0;
156 String_data::operator += ( char const* ch_c_l )
158 append( (Byte const*)ch_c_l, strlen( ch_c_l ) );
165 String_data::ch_c_l() const
167 return (char const*)data_byte_p_;
172 return (char*)data_byte_p_;
176 String_data::byte_c_l() const
182 String_data::byte_l()
190 String_data::trunc(int j)
193 assert(j >= 0 && j <= length_i_);
199 String_data::operator [](int j)
201 assert(j >= 0 && j <= length_i_);
202 return data_byte_p_[j] ;
206 String_data::operator [](int j) const
208 assert(j >= 0 && j <= length_i_);
209 return data_byte_p_[j];
215 #endif // __STRING_UTIL_CC //