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
12 #include "string-data.hh"
21 const int INITIALMAX = 8;
23 #include <sys/types.h>
28 assert (ref_count_ == 1);
34 assert (maxlen >= length_);
35 assert (bool (data_byte_));
36 assert (ref_count_ >= 1);
40 String_data::String_data ()
44 data_byte_ = new Byte[maxlen + 1];
50 String_data::String_data (String_data const &src)
53 maxlen = length_ = src.length_;
54 data_byte_ = new Byte[maxlen + 1]; // should calc GNU 8byte overhead.
55 memcpy (data_byte_, src.data_byte_, length_ + 1);
59 String_data::~String_data ()
61 assert (ref_count_ == 0);
66 String_data::setmax (int j)
73 data_byte_ = new Byte[maxlen + 1];
80 /* this is all quite hairy:
87 define change authority
90 String_data::remax (int j)
95 Byte *p = new Byte[j + 1];
96 memcpy (p, data_byte_, min (maxlen, length_) + 1);
104 String_data::tighten ()
105 { // should be dec'd const
107 Byte *p = new Byte[maxlen + 1];
108 memcpy (p, data_byte_, length_ + 1);
114 String_data::set (Byte const *byte, int length_i)
118 assert (byte && byte != data_byte_);
121 remax (length_); // copies too
122 memcpy (data_byte_, byte, length_);
123 data_byte_[ length_ ] = 0;
128 String_data::set (char const *str0)
130 set ((Byte const *)str0, strlen (str0));
135 String_data::append (Byte const *byte, int length_i)
143 memcpy (data_byte_ + old_i, byte, length_i);
144 data_byte_[ length_ ] = 0;
149 String_data::operator += (char const *str0)
151 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];
210 #endif // __STRING_UTIL_CC //