2 String_data.inl -- implement String_data
4 source file of Flower lib
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.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)
69 data_byte_p_ = new Byte[maxlen + 1];
76 /* this is all quite hairy:
83 define change authority
86 String_data::remax (int j)
91 Byte *p = new Byte[j + 1];
92 memcpy (p, data_byte_p_, (maxlen <? length_i_) + 1 );
94 delete[] data_byte_p_;
100 String_data::tighten ()
101 { // should be dec'd const
103 Byte *p = new Byte[maxlen + 1];
104 memcpy (p, data_byte_p_, length_i_ + 1);
105 delete[] data_byte_p_;
110 String_data::set (Byte const* byte_C, int length_i)
114 assert (byte_C && byte_C != data_byte_p_);
116 length_i_ = length_i;
117 remax (length_i_); // copies too
118 memcpy (data_byte_p_, byte_C, length_i_);
119 data_byte_p_[ length_i_ ] = 0;
124 String_data::set (char const* ch_C)
126 set ((Byte const*)ch_C, strlen (ch_C) );
132 String_data::append (Byte const* byte_C, int length_i)
136 int old_i = length_i_;
138 length_i_ += length_i;
140 memcpy (data_byte_p_ + old_i, byte_C, length_i);
141 data_byte_p_[ length_i_ ] = 0;
146 String_data::operator += (char const* ch_C)
148 append ((Byte const*)ch_C, strlen (ch_C) );
155 String_data::ch_C () const
157 return (char const*)data_byte_p_;
162 return (char*)data_byte_p_;
166 String_data::byte_C () const
172 String_data::byte_l ()
180 String_data::trunc (int j)
183 assert (j >= 0 && j <= length_i_);
189 String_data::is_binary_bo () const
191 // return !memchr (data_byte_p_, length_i_, 0);
192 return ((int)strlen ((char const*)data_byte_p_) != 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 //