source file of Flower lib
- (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
#ifndef STRINGDATA_INL
#include <assert.h>
#include <memory.h>
+#include <string.h>
#include "string-data.hh"
const int INITIALMAX=8;
INLINE void
String_data::OKW ()
{
- assert (references == 1);
+ assert (ref_count_ == 1);
}
INLINE void
String_data::OK ()
{
- assert (maxlen >= length_i_);
- assert (bool (data_byte_p_));
- assert (references >= 1);
+ assert (maxlen >= length_);
+ assert (bool (data_byte_));
+ assert (ref_count_ >= 1);
}
INLINE
String_data::String_data ()
{
- references=0;
+ ref_count_=0;
maxlen = INITIALMAX;
- data_byte_p_ = new Byte[maxlen + 1];
- data_byte_p_[0] = 0;
- length_i_ = 0;
+ data_byte_ = new Byte[maxlen + 1];
+ data_byte_[0] = 0;
+ length_ = 0;
}
INLINE
String_data::String_data (String_data const &src)
{
- references=0;
- maxlen = length_i_ = src.length_i_;
- data_byte_p_ = new Byte[maxlen+1]; // should calc GNU 8byte overhead.
- memcpy (data_byte_p_, src.data_byte_p_, length_i_ + 1);
+ ref_count_=0;
+ maxlen = length_ = src.length_;
+ data_byte_ = new Byte[maxlen+1]; // should calc GNU 8byte overhead.
+ memcpy (data_byte_, src.data_byte_, length_ + 1);
}
INLINE
String_data::~String_data ()
{
- assert (references == 0);
- delete[] data_byte_p_;
+ assert (ref_count_ == 0);
+ delete[] data_byte_;
}
INLINE void
OKW ();
if (j > maxlen)
{
- delete data_byte_p_;
+ delete[] data_byte_;
maxlen = j;
- data_byte_p_ = new Byte[maxlen + 1];
+ data_byte_ = new Byte[maxlen + 1];
- data_byte_p_[0] = 0;
- length_i_ = 0;
+ data_byte_[0] = 0;
+ length_ = 0;
}
}
/* this is all quite hairy:
- update of length_i_
+ update of length_
update of maxlen
alloc of buffer
copying of buffer
if (j > maxlen)
{
Byte *p = new Byte[j + 1];
- memcpy (p, data_byte_p_, (maxlen <? length_i_) + 1 );
+ memcpy (p, data_byte_, (maxlen <? length_) + 1 );
maxlen = j;
- delete[] data_byte_p_;
- data_byte_p_ = p;
+ delete[] data_byte_;
+ data_byte_ = p;
}
}
INLINE void
String_data::tighten ()
{ // should be dec'd const
- maxlen = length_i_;
+ maxlen = length_;
Byte *p = new Byte[maxlen + 1];
- memcpy (p, data_byte_p_, length_i_ + 1);
- delete[] data_byte_p_;
- data_byte_p_ = p;
+ memcpy (p, data_byte_, length_ + 1);
+ delete[] data_byte_;
+ data_byte_ = p;
}
// assignment.
INLINE void
-String_data::set (Byte const* byte_C, int length_i)
+String_data::set (Byte const* byte, int length_i)
{
OKW ();
- assert (byte_C && byte_C != data_byte_p_);
+ assert (byte && byte != data_byte_);
- length_i_ = length_i;
- remax (length_i_); // copies too
- memcpy (data_byte_p_, byte_C, length_i_);
- data_byte_p_[ length_i_ ] = 0;
+ length_ = length_i;
+ remax (length_); // copies too
+ memcpy (data_byte_, byte, length_);
+ data_byte_[ length_ ] = 0;
}
INLINE
void
-String_data::set (char const* ch_C)
+String_data::set (char const* str0)
{
- set ((Byte const*)ch_C, strlen (ch_C) );
+ set ((Byte const*)str0, strlen (str0) );
}
/// concatenation.
INLINE void
-String_data::append (Byte const* byte_C, int length_i)
+String_data::append (Byte const* byte, int length_i)
{
OK ();
OKW ();
- int old_i = length_i_;
+ int old_i = length_;
- length_i_ += length_i;
- remax (length_i_);
- memcpy (data_byte_p_ + old_i, byte_C, length_i);
- data_byte_p_[ length_i_ ] = 0;
+ length_ += length_i;
+ remax (length_);
+ memcpy (data_byte_ + old_i, byte, length_i);
+ data_byte_[ length_ ] = 0;
}
INLINE
void
-String_data::operator += (char const* ch_C)
+String_data::operator += (char const* str0)
{
- append ((Byte const*)ch_C, strlen (ch_C) );
+ append ((Byte const*)str0, strlen (str0) );
}
INLINE
char const*
-String_data::ch_C () const
+String_data::to_str0 () const
{
- return (char const*)data_byte_p_;
+ return (char const*)data_byte_;
}
INLINE char*
-String_data::ch_l ()
+String_data::get_str0 ()
{
- return (char*)data_byte_p_;
+ return (char*)data_byte_;
}
INLINE Byte const*
-String_data::byte_C () const
+String_data::to_bytes () const
{
- return data_byte_p_;
+ return data_byte_;
}
INLINE Byte*
-String_data::byte_l ()
+String_data::get_bytes ()
{
OKW ();
- return data_byte_p_;
+ return data_byte_;
}
INLINE
String_data::trunc (int j)
{
OKW ();
- assert (j >= 0 && j <= length_i_);
- data_byte_p_[j] = 0;
- length_i_ = j;
+ assert (j >= 0 && j <= length_);
+ data_byte_[j] = 0;
+ length_ = j;
}
INLINE bool
String_data::is_binary_bo () const
{
- // return !memchr (data_byte_p_, length_i_, 0);
- return ((int)strlen ((char const*)data_byte_p_) != length_i_ );
+ // return !memchr (data_byte_, length_, 0);
+ return ((int)strlen ((char const*)data_byte_) != length_ );
}
INLINE Byte&
String_data::operator [] (int j)
{
- assert (j >= 0 && j <= length_i_);
- return data_byte_p_[j] ;
+ assert (j >= 0 && j <= length_);
+ return data_byte_[j] ;
}
INLINE Byte
String_data::operator [] (int j) const
{
- assert (j >= 0 && j <= length_i_);
- return data_byte_p_[j];
+ assert (j >= 0 && j <= length_);
+ return data_byte_[j];
}