2 String_data.inl -- implement String_data
4 source file of Flower lib
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #define STRINGDATA_INL
16 #include "string-data.hh"
17 const int INITIALMAX=8;
19 #include <sys/types.h>
24 assert (ref_count_ == 1);
30 assert (maxlen >= length_);
31 assert (bool (data_byte_));
32 assert (ref_count_ >= 1);
37 String_data::String_data ()
41 data_byte_ = new Byte[maxlen + 1];
47 String_data::String_data (String_data const &src)
50 maxlen = length_ = src.length_;
51 data_byte_ = new Byte[maxlen+1]; // should calc GNU 8byte overhead.
52 memcpy (data_byte_, src.data_byte_, length_ + 1);
56 String_data::~String_data ()
58 assert (ref_count_ == 0);
63 String_data::setmax (int j)
70 data_byte_ = new Byte[maxlen + 1];
77 /* this is all quite hairy:
84 define change authority
87 String_data::remax (int j)
92 Byte *p = new Byte[j + 1];
93 memcpy (p, data_byte_, (maxlen <? length_) + 1 );
101 String_data::tighten ()
102 { // should be dec'd const
104 Byte *p = new Byte[maxlen + 1];
105 memcpy (p, data_byte_, length_ + 1);
111 String_data::set (Byte const* byte, int length_i)
115 assert (byte && byte != data_byte_);
118 remax (length_); // copies too
119 memcpy (data_byte_, byte, length_);
120 data_byte_[ length_ ] = 0;
125 String_data::set (char const* str0)
127 set ((Byte const*)str0, strlen (str0) );
133 String_data::append (Byte const* byte, int length_i)
141 memcpy (data_byte_ + old_i, byte, length_i);
142 data_byte_[ length_ ] = 0;
147 String_data::operator += (char const* str0)
149 append ((Byte const*)str0, strlen (str0) );
156 String_data::to_str0 () const
158 return (char const*)data_byte_;
161 String_data::get_str0 ()
163 return (char*)data_byte_;
167 String_data::to_bytes () const
173 String_data::get_bytes ()
181 String_data::trunc (int j)
184 assert (j >= 0 && j <= length_);
190 String_data::is_binary_bo () const
192 // return !memchr (data_byte_, length_, 0);
193 return ((int)strlen ((char const*)data_byte_) != length_ );
197 String_data::operator [] (int j)
199 assert (j >= 0 && j <= length_);
200 return data_byte_[j] ;
204 String_data::operator [] (int j) const
206 assert (j >= 0 && j <= length_);
207 return data_byte_[j];
213 #endif // __STRING_UTIL_CC //