Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

WvString Class Reference

#include <wvstring.h>

List of all members.

Public Methods

 WvString ()
void setsize (size_t i)
 WvString (const WvString &s)
 WvString (const char *_str)
 WvString (int i)
 WvString (const WvString &__wvs_format, const WvString &__wvs_a0, const WvString &__wvs_a1=__wvs_n, const WvString &__wvs_a2=__wvs_n, const WvString &__wvs_a3=__wvs_n, const WvString &__wvs_a4=__wvs_n, const WvString &__wvs_a5=__wvs_n, const WvString &__wvs_a6=__wvs_n, const WvString &__wvs_a7=__wvs_n, const WvString &__wvs_a8=__wvs_n, const WvString &__wvs_a9=__wvs_n, const WvString &__wvs_a10=__wvs_n, const WvString &__wvs_a11=__wvs_n, const WvString &__wvs_a12=__wvs_n, const WvString &__wvs_a13=__wvs_n, const WvString &__wvs_a14=__wvs_n, const WvString &__wvs_a15=__wvs_n, const WvString &__wvs_a16=__wvs_n, const WvString &__wvs_a17=__wvs_n, const WvString &__wvs_a18=__wvs_n, const WvString &__wvs_a19=__wvs_n)
 ~WvString ()
void append (const WvString &s)
void append (const WvString &__wvs_format, const WvString &__wvs_a0, const WvString &__wvs_a1=__wvs_n, const WvString &__wvs_a2=__wvs_n, const WvString &__wvs_a3=__wvs_n, const WvString &__wvs_a4=__wvs_n, const WvString &__wvs_a5=__wvs_n, const WvString &__wvs_a6=__wvs_n, const WvString &__wvs_a7=__wvs_n, const WvString &__wvs_a8=__wvs_n, const WvString &__wvs_a9=__wvs_n, const WvString &__wvs_a10=__wvs_n, const WvString &__wvs_a11=__wvs_n, const WvString &__wvs_a12=__wvs_n, const WvString &__wvs_a13=__wvs_n, const WvString &__wvs_a14=__wvs_n, const WvString &__wvs_a15=__wvs_n, const WvString &__wvs_a16=__wvs_n, const WvString &__wvs_a17=__wvs_n, const WvString &__wvs_a18=__wvs_n, const WvString &__wvs_a19=__wvs_n)
size_t len () const
WvString & operator= (const WvString &s2)
WvString & unique ()
bool operator== (const WvString &s2) const
bool operator!= (const WvString &s2) const
bool operator== (const char *s2) const
bool operator!= (const char *s2) const
bool operator! () const
const char * operator+ (int i) const
const char * operator- (int i) const
 operator const char * () const
const char * cstr () const
char * edit ()
int num () const
 WvString ()
void setsize (size_t i)
 WvString (const WvString &s)
 WvString (const char *_str)
 WvString (int i)
 WvString (const WvString &__wvs_format, const WvString &__wvs_a0, const WvString &__wvs_a1=__wvs_n, const WvString &__wvs_a2=__wvs_n, const WvString &__wvs_a3=__wvs_n, const WvString &__wvs_a4=__wvs_n, const WvString &__wvs_a5=__wvs_n, const WvString &__wvs_a6=__wvs_n, const WvString &__wvs_a7=__wvs_n, const WvString &__wvs_a8=__wvs_n, const WvString &__wvs_a9=__wvs_n, const WvString &__wvs_a10=__wvs_n, const WvString &__wvs_a11=__wvs_n, const WvString &__wvs_a12=__wvs_n, const WvString &__wvs_a13=__wvs_n, const WvString &__wvs_a14=__wvs_n, const WvString &__wvs_a15=__wvs_n, const WvString &__wvs_a16=__wvs_n, const WvString &__wvs_a17=__wvs_n, const WvString &__wvs_a18=__wvs_n, const WvString &__wvs_a19=__wvs_n)
 ~WvString ()
void append (const WvString &s)
void append (const WvString &__wvs_format, const WvString &__wvs_a0, const WvString &__wvs_a1=__wvs_n, const WvString &__wvs_a2=__wvs_n, const WvString &__wvs_a3=__wvs_n, const WvString &__wvs_a4=__wvs_n, const WvString &__wvs_a5=__wvs_n, const WvString &__wvs_a6=__wvs_n, const WvString &__wvs_a7=__wvs_n, const WvString &__wvs_a8=__wvs_n, const WvString &__wvs_a9=__wvs_n, const WvString &__wvs_a10=__wvs_n, const WvString &__wvs_a11=__wvs_n, const WvString &__wvs_a12=__wvs_n, const WvString &__wvs_a13=__wvs_n, const WvString &__wvs_a14=__wvs_n, const WvString &__wvs_a15=__wvs_n, const WvString &__wvs_a16=__wvs_n, const WvString &__wvs_a17=__wvs_n, const WvString &__wvs_a18=__wvs_n, const WvString &__wvs_a19=__wvs_n)
size_t len () const
WvString & operator= (const WvString &s2)
WvString & unique ()
bool operator== (const WvString &s2) const
bool operator!= (const WvString &s2) const
bool operator== (const char *s2) const
bool operator!= (const char *s2) const
bool operator! () const
const char * operator+ (int i) const
const char * operator- (int i) const
 operator const char * () const
const char * cstr () const
char * edit ()
int num () const

Static Public Methods

void do_format (WvString &output, char *format, const WvString **a)
void do_format (WvString &output, char *format, const WvString **a)

Private Methods

void unlink ()
void link (WvStringBuf *_buf, const char *_str)
WvStringBuf * alloc (size_t size)
void newbuf (size_t size)
void unlink ()
void link (WvStringBuf *_buf, const char *_str)
WvStringBuf * alloc (size_t size)
void newbuf (size_t size)

Private Attributes

WvStringBuf * buf
char * str
WvStringBuf * buf
char * str


Detailed Description

WvString is an implementation of a simple and efficient printable-string class. It leaves out many of the notational conveniences provided by other string classes, because they waste too much CPU time and space.

It does the one thing really missing from char* strings, that is, dynamic buffer management.

When you copy one WvString to another, it does _not_ duplicate the buffer; it just creates another pointer to it. To really duplicate the buffer, call the unique() member function.

To change the contents of a WvString, you need to run its edit() member function, which executes unique() and then returns a char* pointer to the WvString contents.

The most annoying side-effect of this implementation is that if you construct a WvString from a char* buffer or static string, WvString won't duplicate it. Usually this is okay and much faster (for example, if you just want to print a static string). However, if you construct a WvString from a dynamic variable, changing the dynamic variable will change the WvString unless you run unique() or edit(). Worse still, deleting the dynamic variable will make WvString act unpredictably.

But it does cut out extra dynamic memory allocation for the most common cases, and it almost always avoids manual 'new' and 'delete' of string objects.

Definition at line 98 of file include/wvstring.h.


Constructor & Destructor Documentation

WvString::WvString (    ) 
 

Create an empty, NULL string. In the past, these were dangerous and could only be filled with operator= or setsize(); nowadays, NULL strings are explicitly allowed, since it's useful to express the difference between a zero-length string and a NULL result.

Definition at line 31 of file wvstring.cc.

References buf, and str.

Referenced by append().

WvString::WvString (  const WvString &    s ) 
 

Copy Constructor

Definition at line 38 of file wvstring.cc.

References buf, link(), and str.

WvString::WvString (  const char *    _str ) 
 

Create a WvString out of the char * _str

Definition at line 44 of file wvstring.cc.

References buf, link(), and str.

WvString::WvString (  int    i ) 
 

NOTE: make sure that 32 bytes is big enough for your longest int. This is true up to at least 64 bits.

Definition at line 58 of file wvstring.cc.

WvString::WvString (  const WvString &    __wvs_format,
const WvString &    __wvs_a0,
const WvString &    __wvs_a1 = __wvs_n,
const WvString &    __wvs_a2 = __wvs_n,
const WvString &    __wvs_a3 = __wvs_n,
const WvString &    __wvs_a4 = __wvs_n,
const WvString &    __wvs_a5 = __wvs_n,
const WvString &    __wvs_a6 = __wvs_n,
const WvString &    __wvs_a7 = __wvs_n,
const WvString &    __wvs_a8 = __wvs_n,
const WvString &    __wvs_a9 = __wvs_n,
const WvString &    __wvs_a10 = __wvs_n,
const WvString &    __wvs_a11 = __wvs_n,
const WvString &    __wvs_a12 = __wvs_n,
const WvString &    __wvs_a13 = __wvs_n,
const WvString &    __wvs_a14 = __wvs_n,
const WvString &    __wvs_a15 = __wvs_n,
const WvString &    __wvs_a16 = __wvs_n,
const WvString &    __wvs_a17 = __wvs_n,
const WvString &    __wvs_a18 = __wvs_n,
const WvString &    __wvs_a19 = __wvs_n
)  [inline]
 

Now, you are probably thinking to yourself: Boy, does this ever look ridiculous. And indeed it does. However, it is completely type-safe and when inline functions are enabled, it reduces automatically to its minimum possible implementation. (ie. all extra comparisons with wv_null go away if the parameter really _is_ wv_null, and that is the default!)

I failed to find a way to optimize out the comparisons for parameters that _are_ provided, however.

There is a small problem, which is that only up to 20 (numbers 0 to 19) additional arguments are allowed. Luckily, no one has ever used that many on one "printf"-type line in the history of the world.

Definition at line 156 of file include/wvstring.h.

References do_format(), and WVSTRING_FORMAT_DECL.

WvString::~WvString (    ) 
 

Definition at line 65 of file wvstring.cc.

References unlink().

WvString::WvString (    ) 
 

Create an empty, NULL string. In the past, these were dangerous and could only be filled with operator= or setsize(); nowadays, NULL strings are explicitly allowed, since it's useful to express the difference between a zero-length string and a NULL result.

WvString::WvString (  const WvString &    s ) 
 

Copy Constructor

WvString::WvString (  const char *    _str ) 
 

Create a WvString out of the char * _str

WvString::WvString (  int    i ) 
 

NOTE: make sure that 32 bytes is big enough for your longest int. This is true up to at least 64 bits.

WvString::WvString (  const WvString &    __wvs_format,
const WvString &    __wvs_a0,
const WvString &    __wvs_a1 = __wvs_n,
const WvString &    __wvs_a2 = __wvs_n,
const WvString &    __wvs_a3 = __wvs_n,
const WvString &    __wvs_a4 = __wvs_n,
const WvString &    __wvs_a5 = __wvs_n,
const WvString &    __wvs_a6 = __wvs_n,
const WvString &    __wvs_a7 = __wvs_n,
const WvString &    __wvs_a8 = __wvs_n,
const WvString &    __wvs_a9 = __wvs_n,
const WvString &    __wvs_a10 = __wvs_n,
const WvString &    __wvs_a11 = __wvs_n,
const WvString &    __wvs_a12 = __wvs_n,
const WvString &    __wvs_a13 = __wvs_n,
const WvString &    __wvs_a14 = __wvs_n,
const WvString &    __wvs_a15 = __wvs_n,
const WvString &    __wvs_a16 = __wvs_n,
const WvString &    __wvs_a17 = __wvs_n,
const WvString &    __wvs_a18 = __wvs_n,
const WvString &    __wvs_a19 = __wvs_n
)  [inline]
 

Now, you are probably thinking to yourself: Boy, does this ever look ridiculous. And indeed it does. However, it is completely type-safe and when inline functions are enabled, it reduces automatically to its minimum possible implementation. (ie. all extra comparisons with wv_null go away if the parameter really _is_ wv_null, and that is the default!)

I failed to find a way to optimize out the comparisons for parameters that _are_ provided, however.

There is a small problem, which is that only up to 20 (numbers 0 to 19) additional arguments are allowed. Luckily, no one has ever used that many on one "printf"-type line in the history of the world.

Definition at line 156 of file utils/wvstring.h.

References do_format(), and WVSTRING_FORMAT_DECL.

WvString::~WvString (    ) 
 


Member Function Documentation

WvStringBuf* WvString::alloc (  size_t    size )  [private]
 

WvStringBuf * WvString::alloc (  size_t    size )  [private]
 

Definition at line 86 of file wvstring.cc.

References buf, WvStringBuf::links, WvStringBuf::size, size, and WVSTRINGBUF_SIZE.

Referenced by newbuf(), and unique().

void WvString::append (  const WvString &    __wvs_format,
const WvString &    __wvs_a0,
const WvString &    __wvs_a1 = __wvs_n,
const WvString &    __wvs_a2 = __wvs_n,
const WvString &    __wvs_a3 = __wvs_n,
const WvString &    __wvs_a4 = __wvs_n,
const WvString &    __wvs_a5 = __wvs_n,
const WvString &    __wvs_a6 = __wvs_n,
const WvString &    __wvs_a7 = __wvs_n,
const WvString &    __wvs_a8 = __wvs_n,
const WvString &    __wvs_a9 = __wvs_n,
const WvString &    __wvs_a10 = __wvs_n,
const WvString &    __wvs_a11 = __wvs_n,
const WvString &    __wvs_a12 = __wvs_n,
const WvString &    __wvs_a13 = __wvs_n,
const WvString &    __wvs_a14 = __wvs_n,
const WvString &    __wvs_a15 = __wvs_n,
const WvString &    __wvs_a16 = __wvs_n,
const WvString &    __wvs_a17 = __wvs_n,
const WvString &    __wvs_a18 = __wvs_n,
const WvString &    __wvs_a19 = __wvs_n
)  [inline]
 

Definition at line 188 of file utils/wvstring.h.

References append(), WvString(), WVSTRING_FORMAT_CALL, and WVSTRING_FORMAT_DECL.

void WvString::append (  const WvString &    s ) 
 

void WvString::append (  const WvString &    __wvs_format,
const WvString &    __wvs_a0,
const WvString &    __wvs_a1 = __wvs_n,
const WvString &    __wvs_a2 = __wvs_n,
const WvString &    __wvs_a3 = __wvs_n,
const WvString &    __wvs_a4 = __wvs_n,
const WvString &    __wvs_a5 = __wvs_n,
const WvString &    __wvs_a6 = __wvs_n,
const WvString &    __wvs_a7 = __wvs_n,
const WvString &    __wvs_a8 = __wvs_n,
const WvString &    __wvs_a9 = __wvs_n,
const WvString &    __wvs_a10 = __wvs_n,
const WvString &    __wvs_a11 = __wvs_n,
const WvString &    __wvs_a12 = __wvs_n,
const WvString &    __wvs_a13 = __wvs_n,
const WvString &    __wvs_a14 = __wvs_n,
const WvString &    __wvs_a15 = __wvs_n,
const WvString &    __wvs_a16 = __wvs_n,
const WvString &    __wvs_a17 = __wvs_n,
const WvString &    __wvs_a18 = __wvs_n,
const WvString &    __wvs_a19 = __wvs_n
)  [inline]
 

Definition at line 188 of file include/wvstring.h.

References append(), WvString(), WVSTRING_FORMAT_CALL, and WVSTRING_FORMAT_DECL.

void WvString::append (  const WvString &    s ) 
 

Definition at line 96 of file wvstring.cc.

References unique(), and WvString().

Referenced by append(), encode_hostname_as_DN(), WvMD5::md5_hash(), and set_name_entry().

const char* WvString::cstr (    )  const [inline]
 

return a (const char *) for this string. The typecast operator does this automatically when needed, but sometimes (especially with varargs like in printf()) that isn't convenient enough.

Definition at line 227 of file utils/wvstring.h.

References str.

const char* WvString::cstr (    )  const [inline]
 

return a (const char *) for this string. The typecast operator does this automatically when needed, but sometimes (especially with varargs like in printf()) that isn't convenient enough.

Definition at line 227 of file include/wvstring.h.

References str.

Referenced by WvMD5::WvMD5().

void WvString::do_format (  WvString &    output,
char *    format,
const WvString **    a
)  [static]
 

when this is called, we assume output.str == NULL; it will be filled.

void WvString::do_format (  WvString &    output,
char *    format,
const WvString **    a
)  [static]
 

when this is called, we assume output.str == NULL; it will be filled.

Definition at line 226 of file wvstring.cc.

References _max(), edit(), pparse(), and setsize().

Referenced by WvString().

char* WvString::edit (    )  [inline]
 

make the string editable, and return a non-const (char*)

Definition at line 233 of file utils/wvstring.h.

References str, and unique().

char* WvString::edit (    )  [inline]
 

make the string editable, and return a non-const (char*)

Definition at line 233 of file include/wvstring.h.

References str, and unique().

Referenced by backslash_escape(), WvX509Mgr::createcertreq(), WvX509Mgr::createSScert(), do_format(), encode_hostname_as_DN(), WvX509Mgr::encodecert(), WvProtoStream::Token::fill(), follow_links(), WvBuffer::getstr(), hexdump_buffer(), WvStringTable::join(), WvStringList::join(), WvARCnetAddr::printable(), rfc822_date(), WvConf::save(), set_name_entry(), WvStringTable::split(), WvStringList::split(), web_unescape(), WvTCPConn::WvTCPConn(), and WvURL::WvURL().

size_t WvString::len (    )  const
 

size_t WvString::len (    )  const
 

Definition at line 108 of file wvstring.cc.

References buf, WvStringBuf::size, and str.

Referenced by backslash_escape(), and unique().

void WvString::link (  WvStringBuf *    _buf,
const char *    _str
)  [private]
 

void WvString::link (  WvStringBuf *    _buf,
const char *    _str
)  [private]
 

Definition at line 78 of file wvstring.cc.

References buf, WvStringBuf::links, and str.

Referenced by operator=(), unique(), and WvString().

void WvString::newbuf (  size_t    size )  [private]
 

void WvString::newbuf (  size_t    size )  [private]
 

Definition at line 115 of file wvstring.cc.

References alloc(), buf, WvStringBuf::data, WvStringBuf::links, size, and str.

Referenced by setsize().

int WvString::num (    )  const [inline]
 

used to convert WvString to int, when needed. we no longer provide a typecast, because it causes annoyance.

Definition at line 240 of file utils/wvstring.h.

References str.

int WvString::num (    )  const [inline]
 

used to convert WvString to int, when needed. we no longer provide a typecast, because it causes annoyance.

Definition at line 240 of file include/wvstring.h.

References str.

Referenced by WvIPRouteList::get_kernel(), and WvHConf::num().

WvString::operator const char * (    )  const [inline]
 

auto-convert WvString to (const char *), when needed.

Definition at line 219 of file utils/wvstring.h.

References str.

WvString::operator const char * (    )  const [inline]
 

auto-convert WvString to (const char *), when needed.

Definition at line 219 of file include/wvstring.h.

References str.

bool WvString::operator! (    )  const
 

the not operator is 'true' if string is empty

bool WvString::operator! (    )  const
 

the not operator is 'true' if string is empty

Definition at line 175 of file wvstring.cc.

References buf, and str.

bool WvString::operator!= (  const char *    s2 )  const
 

bool WvString::operator!= (  const WvString &    s2 )  const
 

bool WvString::operator!= (  const char *    s2 )  const
 

Definition at line 168 of file wvstring.cc.

References str.

bool WvString::operator!= (  const WvString &    s2 )  const
 

Definition at line 156 of file wvstring.cc.

References str.

const char* WvString::operator+ (  int    i )  const [inline]
 

Definition at line 211 of file utils/wvstring.h.

References str.

const char* WvString::operator+ (  int    i )  const [inline]
 

Definition at line 211 of file include/wvstring.h.

References str.

const char* WvString::operator- (  int    i )  const [inline]
 

Definition at line 213 of file utils/wvstring.h.

References str.

const char* WvString::operator- (  int    i )  const [inline]
 

Definition at line 213 of file include/wvstring.h.

References str.

WvString& WvString::operator= (  const WvString &    s2 ) 
 

WvString & WvString::operator= (  const WvString &    s2 ) 
 

Definition at line 139 of file wvstring.cc.

References buf, link(), str, and unlink().

bool WvString::operator== (  const char *    s2 )  const
 

bool WvString::operator== (  const WvString &    s2 )  const
 

bool WvString::operator== (  const char *    s2 )  const
 

Definition at line 162 of file wvstring.cc.

References str.

bool WvString::operator== (  const WvString &    s2 )  const
 

Definition at line 150 of file wvstring.cc.

References str.

void WvString::setsize (  size_t    i ) 
 

void WvString::setsize (  size_t    i ) 
 

Definition at line 23 of file wvstring.cc.

References newbuf(), and unlink().

Referenced by backslash_escape(), WvX509Mgr::createcertreq(), do_format(), WvX509Mgr::encodecert(), WvProtoStream::Token::fill(), follow_links(), WvBuffer::getstr(), hexdump_buffer(), WvStringTable::join(), WvStringList::join(), rfc822_date(), and web_unescape().

WvString& WvString::unique (    ) 
 

make the buf and str pointers owned only by this WvString.

WvString & WvString::unique (    ) 
 

make the buf and str pointers owned only by this WvString.

Definition at line 125 of file wvstring.cc.

References alloc(), buf, WvStringBuf::data, len(), link(), WvStringBuf::links, WvStringBuf::size, str, and unlink().

Referenced by WvLogBuffer::_end_line(), append(), edit(), encode_hostname_as_DN(), passwd_crypt(), WvConfigEntry::set(), WvConfigSection::set(), set_name_entry(), WvHConf::set_without_notify(), WvStringTable::split(), WvStringList::split(), WvTask::start(), WvConf::WvConf(), WvConfigEntry::WvConfigEntry(), WvConfigSection::WvConfigSection(), WvInterface::WvInterface(), WvIPRoute::WvIPRoute(), WvLog::WvLog(), WvResolverHost::WvResolverHost(), WvStringAddr::WvStringAddr(), WvUnixAddr::WvUnixAddr(), and WvURL::WvURL().

void WvString::unlink (    )  [private]
 

void WvString::unlink (    )  [private]
 

Definition at line 71 of file wvstring.cc.

References buf, and WvStringBuf::links.

Referenced by operator=(), setsize(), unique(), and ~WvString().


Member Data Documentation

WvStringBuf* WvString::buf [private]
 

Definition at line 100 of file utils/wvstring.h.

WvStringBuf* WvString::buf [private]
 

Definition at line 100 of file include/wvstring.h.

Referenced by alloc(), len(), link(), newbuf(), operator!(), operator=(), unique(), unlink(), and WvString().

char* WvString::str [private]
 

Definition at line 101 of file utils/wvstring.h.

char* WvString::str [private]
 

Definition at line 101 of file include/wvstring.h.

Referenced by cstr(), edit(), len(), link(), newbuf(), num(), operator const char *(), operator!(), operator!=(), operator+(), operator-(), operator=(), operator==(), unique(), and WvString().


The documentation for this class was generated from the following files:
Generated on Fri Apr 5 15:16:57 2002 for WvStreams by doxygen1.2.15