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);
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));
132 String_data::append (Byte const *byte, int length_i)
140 memcpy (data_byte_ + old_i, byte, length_i);
141 data_byte_[ length_ ] = 0;
146 String_data::operator+= (char const *str0)
148 append ((Byte const *)str0, strlen (str0));
153 String_data::to_str0 () const
155 return (char const *)data_byte_;
158 String_data::get_str0 ()
160 return (char *)data_byte_;
164 String_data::to_bytes () const
170 String_data::get_bytes ()
178 String_data::trunc (int j)
181 assert (j >= 0 && j <= length_);
187 String_data::is_binary_bo () const
189 // return !memchr (data_byte_, length_, 0);
190 return ((int)strlen ((char const *)data_byte_) != length_);
194 String_data::operator[] (int j)
196 assert (j >= 0 && j <= length_);
197 return data_byte_[j];
201 String_data::operator[] (int j) const
203 assert (j >= 0 && j <= length_);
204 return data_byte_[j];
208 #endif // __STRING_UTIL_CC //