Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

WvString Class Reference

#include <wvstring.h>

Inherits WvFastString.

Collaboration diagram for WvString:

[legend]
List of all members.

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 297 of file wvstring.h.

Public Member Functions

 WvString ()
 WvString (short i)
 WvString (unsigned short i)
 WvString (int i)
 WvString (unsigned int i)
 WvString (long i)
 WvString (unsigned long i)
 WvString (long long i)
 WvString (unsigned long long i)
 WvString (double i)
 WvString (const WvString &s)
 Magic copy constructor for "fast" char* strings.

 WvString (const WvFastString &s)
 WvString (const char *_str)
 Create a WvString out of a char* string.

 WvString (const QString &)
 Create a WvString out of a Qt library QString.

 WvString (const QCString &)
 WvString (WVSTRING_FORMAT_DECL)
WvStringappend (WvStringParm s)
WvStringappend (WVSTRING_FORMAT_DECL)
WvStringoperator= (int i)
WvStringoperator= (const WvFastString &s2)
WvStringoperator= (const char *s2)
WvStringunique ()
 make the buf and str pointers owned only by this WvString.

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

void setsize (size_t i)
size_t len () const
bool operator== (WvStringParm s2) const
bool operator== (const char *s2) const
bool operator!= (WvStringParm s2) const
bool operator!= (const char *s2) const
bool operator< (WvStringParm s2) const
bool operator< (const char *s2) const
bool operator! () const
 the not operator is 'true' if string is empty

const char * operator+ (int i) const
const char * operator- (int i) const
 operator const char * () const
 auto-convert WvString to (const char *), when needed.

const char * cstr () const
 return a (const char *) for this string.

 operator QString () const
 return a Qt library QString containing the contents of this string.

int num () const
 used to convert WvString to int, when needed.

bool isnull () const
 returns true if this string is null


Static Public Member Functions

void do_format (WvFastString &output, const char *format, const WvFastString *const *a)
 when this is called, we assume output.str == NULL; it will be filled.


Static Public Attributes

const WvString empty
const WvFastString null

Protected Member Functions

void copy_constructor (const WvFastString &s)
void link (WvStringBuf *_buf, const char *_str)
void unlink ()
WvStringBufalloc (size_t size)
void newbuf (size_t size)

Protected Attributes

WvStringBufbuf
char * str

Static Protected Attributes

WvStringBuf nullbuf = { 0, 1 }


Constructor & Destructor Documentation

WvString::WvString  )  [inline]
 

Definition at line 303 of file wvstring.h.

Referenced by append().

WvString::WvString short  i  )  [inline]
 

Definition at line 304 of file wvstring.h.

WvString::WvString unsigned short  i  )  [inline]
 

Definition at line 305 of file wvstring.h.

WvString::WvString int  i  )  [inline]
 

Definition at line 306 of file wvstring.h.

WvString::WvString unsigned int  i  )  [inline]
 

Definition at line 307 of file wvstring.h.

WvString::WvString long  i  )  [inline]
 

Definition at line 308 of file wvstring.h.

WvString::WvString unsigned long  i  )  [inline]
 

Definition at line 309 of file wvstring.h.

WvString::WvString long long  i  )  [inline]
 

Definition at line 310 of file wvstring.h.

WvString::WvString unsigned long long  i  )  [inline]
 

Definition at line 311 of file wvstring.h.

WvString::WvString double  i  )  [inline]
 

Definition at line 312 of file wvstring.h.

WvString::WvString const WvString s  )  [inline]
 

Magic copy constructor for "fast" char* strings.

When we copy from a "fast" string to a real WvString, we might need to allocate memory (equivalent to unique()) so the original char* can be safely changed or destroyed.

Definition at line 320 of file wvstring.h.

References copy_constructor().

WvString::WvString const WvFastString s  )  [inline]
 

Definition at line 322 of file wvstring.h.

References copy_constructor().

WvString::WvString const char *  _str  ) 
 

Create a WvString out of a char* string.

We always allocate memory and make a copy here. To avoid memory copies, you can (carefully) use a WvFastString. To just have quick parameter passing, use a WvStringParm instead.

Definition at line 71 of file wvstring.cc.

References WvFastString::link(), and unique().

WvString::WvString const QString &   ) 
 

Create a WvString out of a Qt library QString.

You have to link with libwvqt.so if you want to use this.

Definition at line 48 of file wvqtstring.cc.

References WvFastString::link(), and unique().

WvString::WvString const QCString &   ) 
 

Definition at line 57 of file wvqtstring.cc.

References WvFastString::link(), and unique().

WvString::WvString WVSTRING_FORMAT_DECL   )  [inline]
 

Definition at line 340 of file wvstring.h.

References WVSTRING_FORMAT_CALL.


Member Function Documentation

WvStringBuf * WvFastString::alloc size_t  size  )  [protected, inherited]
 

Definition at line 172 of file wvstring.cc.

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

Referenced by WvFastString::newbuf(), and unique().

WvString& WvString::append WVSTRING_FORMAT_DECL   )  [inline]
 

Definition at line 344 of file wvstring.h.

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

WvString & WvString::append WvStringParm  s  ) 
 

Definition at line 182 of file wvstring.cc.

References WvString(), and WvStringParm.

Referenced by append(), encode_hostname_as_DN(), WvEncoder::encodebufstr(), WvFtpStream::execute(), WvEncoder::flushstrstr(), WvUrl::operator WvString(), WvMatrix::printable(), set_name_entry(), sslcreator(), tcpcreator(), and wvtcl_escape().

void WvString::copy_constructor const WvFastString s  )  [protected]
 

Definition at line 59 of file wvstring.cc.

References WvFastString::buf, WvFastString::link(), WvFastString::str, and unique().

Referenced by WvString().

const char* WvFastString::cstr  )  const [inline, inherited]
 

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 245 of file wvstring.h.

References WvFastString::str.

Referenced by WvBackslashEncoder::_encode(), WvMonikerRegistry::add(), WvOggVorbisEncoder::add_comment(), WvOggVorbisEncoder::add_tag(), ascending(), WvMonikerRegistry::create(), WvMonikerRegistry::del(), WvFastString::do_format(), WvConfEmu::get(), WvConfigSectionEmu::get(), UniRegistryGen::get(), UniPStoreGen::get(), main(), mkdirp(), WvBdbHashBase::opendb(), WvFastString::operator QString(), WvBufBase< unsigned char >::putstr(), UniClientConn::readcmd(), WvConstStringBuffer::reset(), UniRegistryGen::set(), UniPStoreGen::set(), UniConfGen::str2int(), UniConfGremlin::test(), WvX509Mgr::unhexify(), WvStream::write(), WvGdbmHashBase::WvGdbmHashBase(), WvMonikerBase::WvMonikerBase(), WvPamStream::WvPamStream(), wvtcl_escape(), WvTaskMan::yield(), and WvMonikerBase::~WvMonikerBase().

void WvFastString::do_format WvFastString output,
const char *  format,
const WvFastString *const *  a
[static, inherited]
 

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

Definition at line 365 of file wvstring.cc.

References _max(), WvFastString::cstr(), pparse(), WvFastString::setsize(), and WvFastString::str.

Referenced by WvFastString::WvFastString().

char* WvString::edit  )  [inline]
 

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

Definition at line 356 of file wvstring.h.

References WvFastString::str, and unique().

Referenced by backslash_escape(), WvMonikerRegistry::create(), WvX509Mgr::create_selfsigned(), WvX509Mgr::decode(), WvProtoStream::Token::fill(), UniRegistryGen::get(), UniDefGen::get(), getdirname(), getfilename(), WvConfEmu::getraw(), WvConf::getraw(), WvBufBase< unsigned char >::getstr(), hexdump_buffer(), WvX509Mgr::hexify(), UniConfKey::init(), WvLogRcv::log(), main(), metriculate(), mkdirp(), nice_hostname(), non_breaking(), WvARCnetAddr::printable(), WvConfigSection::quick_set(), UniConfKey::range(), UniIniGen::refresh(), rfc1123_date(), rfc822_date(), WvConfigSection::set(), WvLogRcv::set_custom_levels(), set_name_entry(), WvConfEmu::setraw(), WvConf::setraw(), sslcreator(), strcoll_join(), strcoll_split(), strcoll_splitstrict(), tcpcreator(), UniPStoreGen::UniPStoreGen(), web_unescape(), WvX509Mgr::write_p12(), wvtcl_unescape(), WvTCPConn::WvTCPConn(), WvUrl::WvUrl(), and WvX509Mgr::WvX509Mgr().

bool WvFastString::isnull  )  const [inline, inherited]
 

returns true if this string is null

Definition at line 262 of file wvstring.h.

References WvFastString::str.

Referenced by _wv_serialize(), UniClientGen::conncallback(), UniConfDaemonConn::deltacallback(), UniConfDaemonConn::do_get(), UniConfDaemonConn::execute(), UniConfGen::exists(), UniMountTreeGen::get(), UniPermGen::getgroup(), UniPermGen::getowner(), UniConfKey::init(), main(), UniClientConn::readcmd(), UniIniGen::refresh(), UniTempGen::set(), UniClientGen::set(), UniConfGen::str2int(), wvtcl_decode(), and WVTEST_MAIN().

size_t WvFastString::len  )  const [inherited]
 

Definition at line 196 of file wvstring.cc.

References WvFastString::str.

Referenced by WvLogFileBase::_make_prefix(), WvLogRcv::_make_prefix(), backslash_escape(), WvX509Mgr::decode(), nice_hostname(), WvUrl::operator WvString(), WvBufBase< unsigned char >::putstr(), WvConstStringBuffer::reset(), unique(), url_encode(), WvStream::write(), WvPamStream::WvPamStream(), wvtcl_unescape(), and WVTEST_MAIN().

void WvFastString::link WvStringBuf _buf,
const char *  _str
[protected, inherited]
 

Definition at line 163 of file wvstring.cc.

References WvFastString::buf, WvStringBuf::links, and WvFastString::str.

Referenced by copy_constructor(), operator=(), WvFastString::operator=(), unique(), WvFastString::WvFastString(), and WvString().

void WvFastString::newbuf size_t  size  )  [protected, inherited]
 

Definition at line 202 of file wvstring.cc.

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

Referenced by operator=(), WvFastString::setsize(), and WvFastString::WvFastString().

int WvFastString::num  )  const [inline, inherited]
 

used to convert WvString to int, when needed.

we no longer provide a typecast, because it causes annoyance.

Definition at line 258 of file wvstring.h.

References WvFastString::str.

Referenced by creator(), WvIPRouteList::get_kernel(), and WVTEST_MAIN().

WvFastString::operator const char *  )  const [inline, inherited]
 

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

Definition at line 237 of file wvstring.h.

References WvFastString::str.

WvFastString::operator QString  )  const [inherited]
 

return a Qt library QString containing the contents of this string.

You need to link to libwvqt.so if you use this.

Definition at line 42 of file wvqtstring.cc.

References WvFastString::cstr().

bool WvFastString::operator!  )  const [inherited]
 

the not operator is 'true' if string is empty

Definition at line 313 of file wvstring.cc.

References WvFastString::str.

bool WvFastString::operator!= const char *  s2  )  const [inherited]
 

Definition at line 297 of file wvstring.cc.

References WvFastString::str.

bool WvFastString::operator!= WvStringParm  s2  )  const [inherited]
 

Definition at line 276 of file wvstring.cc.

References WvFastString::str, and WvStringParm.

const char* WvFastString::operator+ int  i  )  const [inline, inherited]
 

Definition at line 231 of file wvstring.h.

References WvFastString::str.

const char* WvFastString::operator- int  i  )  const [inline, inherited]
 

Definition at line 233 of file wvstring.h.

References WvFastString::str.

bool WvFastString::operator< const char *  s2  )  const [inherited]
 

Definition at line 303 of file wvstring.cc.

References WvFastString::str.

bool WvFastString::operator< WvStringParm  s2  )  const [inherited]
 

Definition at line 282 of file wvstring.cc.

References WvFastString::str, and WvStringParm.

WvString& WvString::operator= const char *  s2  )  [inline]
 

Definition at line 349 of file wvstring.h.

References WvFastString::WvFastString().

WvString & WvString::operator= const WvFastString s2  ) 
 

Reimplemented from WvFastString.

Definition at line 248 of file wvstring.cc.

References WvFastString::buf, WvFastString::link(), WvFastString::str, unique(), and WvFastString::unlink().

WvString & WvString::operator= int  i  ) 
 

Definition at line 239 of file wvstring.cc.

References WvFastString::newbuf(), and WvFastString::unlink().

bool WvFastString::operator== const char *  s2  )  const [inherited]
 

Definition at line 291 of file wvstring.cc.

References WvFastString::str.

bool WvFastString::operator== WvStringParm  s2  )  const [inherited]
 

Definition at line 270 of file wvstring.cc.

References WvFastString::str, and WvStringParm.

void WvFastString::setsize size_t  i  )  [inherited]
 

Definition at line 25 of file wvstring.cc.

References WvFastString::newbuf(), and WvFastString::unlink().

Referenced by backslash_escape(), WvFastString::do_format(), WvProtoStream::Token::fill(), UniRegistryGen::get(), UniDefGen::get(), WvBufBase< unsigned char >::getstr(), hexdump_buffer(), WvX509Mgr::hexify(), UniConfKey::init(), metriculate(), nice_hostname(), UniConfKey::range(), rfc1123_date(), rfc822_date(), strcoll_join(), web_unescape(), and WvX509Mgr::WvX509Mgr().

WvString & WvString::unique  ) 
 

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

Definition at line 212 of file wvstring.cc.

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

Referenced by copy_constructor(), edit(), main(), operator=(), UniIniGen::refresh(), WvString(), and wvtcl_getword().

void WvFastString::unlink  )  [protected, inherited]
 

Definition at line 153 of file wvstring.cc.

References WvFastString::buf, and WvStringBuf::links.

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


Member Data Documentation

WvStringBuf* WvFastString::buf [protected, inherited]
 

Definition at line 90 of file wvstring.h.

Referenced by WvFastString::alloc(), copy_constructor(), WvFastString::link(), WvFastString::newbuf(), operator=(), WvFastString::operator=(), WvFastString::unlink(), and WvFastString::WvFastString().

const WvString WvString::empty [static]
 

const WvFastString WvFastString::null [static, inherited]
 

Definition at line 13 of file wvstring.cc.

Referenced by WvFastString::WvFastString().

WvStringBuf WvFastString::nullbuf = { 0, 1 } [static, protected, inherited]
 

Definition at line 12 of file wvstring.cc.

Referenced by WvFastString::WvFastString().

char* WvFastString::str [protected, inherited]
 

Definition at line 91 of file wvstring.h.

Referenced by copy_constructor(), WvFastString::cstr(), WvFastString::do_format(), edit(), WvFastString::isnull(), WvFastString::len(), WvFastString::link(), WvFastString::newbuf(), WvFastString::num(), WvFastString::operator const char *(), WvFastString::operator!(), WvFastString::operator!=(), WvFastString::operator+(), WvFastString::operator-(), WvFastString::operator<(), operator=(), WvFastString::operator=(), WvFastString::operator==(), and WvFastString::WvFastString().


The documentation for this class was generated from the following files:
Generated on Sat Feb 21 21:07:02 2004 for WvStreams by doxygen 1.3.5