2 String_data.inl -- implement String_data
4 source file of Flower lib
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #define STRINGDATA_INL
17 #include "string-data.hh"
18 const int INITIALMAX=8;
20 #include <sys/types.h>
25 assert (ref_count_ == 1);
31 assert (maxlen >= length_);
32 assert (bool (data_byte_));
33 assert (ref_count_ >= 1);
38 String_data::String_data ()
42 data_byte_ = new Byte[maxlen + 1];
48 String_data::String_data (String_data const &src)
51 maxlen = length_ = src.length_;
52 data_byte_ = new Byte[maxlen+1]; // should calc GNU 8byte overhead.
53 memcpy (data_byte_, src.data_byte_, length_ + 1);
57 String_data::~String_data ()
59 assert (ref_count_ == 0);
64 String_data::setmax (int j)
71 data_byte_ = new Byte[maxlen + 1];
78 /* this is all quite hairy:
85 define change authority
88 String_data::remax (int j)
93 Byte *p = new Byte[j + 1];
94 memcpy (p, data_byte_, (maxlen <? length_) + 1 );
102 String_data::tighten ()
103 { // should be dec'd const
105 Byte *p = new Byte[maxlen + 1];
106 memcpy (p, data_byte_, length_ + 1);
112 String_data::set (Byte const* byte, int length_i)
116 assert (byte && byte != data_byte_);
119 remax (length_); // copies too
120 memcpy (data_byte_, byte, length_);
121 data_byte_[ length_ ] = 0;
126 String_data::set (char const* str0)
128 set ((Byte const*)str0, strlen (str0) );
134 String_data::append (Byte const* byte, int length_i)
142 memcpy (data_byte_ + old_i, byte, length_i);
143 data_byte_[ length_ ] = 0;
148 String_data::operator += (char const* str0)
150 append ((Byte const*)str0, strlen (str0) );
157 String_data::to_str0 () const
159 return (char const*)data_byte_;
162 String_data::get_str0 ()
164 return (char*)data_byte_;
168 String_data::to_bytes () const
174 String_data::get_bytes ()
182 String_data::trunc (int j)
185 assert (j >= 0 && j <= length_);
191 String_data::is_binary_bo () const
193 // return !memchr (data_byte_, length_, 0);
194 return ((int)strlen ((char const*)data_byte_) != length_ );
198 String_data::operator [] (int j)
200 assert (j >= 0 && j <= length_);
201 return data_byte_[j] ;
205 String_data::operator [] (int j) const
207 assert (j >= 0 && j <= length_);
208 return data_byte_[j];
214 #endif // __STRING_UTIL_CC //