WvStreams
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
WvString Class Reference

WvString is an implementation of a simple and efficient printable-string class. More...

#include <wvstring.h>

Inheritance diagram for WvString:
Inheritance graph
[legend]

Public Member Functions

 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. More...
 
 WvString (const WvFastString &s)
 
 WvString (const char *_str)
 Create a WvString out of a char* string. More...
 
 WvString (const QString &)
 Create a WvString out of a Qt library QString. More...
 
 WvString (const QCString &)
 
 WvString (const std::string &s)
 Create a string out of a stdc++ string. More...
 
 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. More...
 
bool is_unique () const
 returns true if this string is already unique() More...
 
char * edit ()
 make the string editable, and return a non-const (char*) More...
 
void setsize (size_t i)
 
WvFastString offset (size_t i) const
 Returns a copy of string pointed i bytes into this. More...
 
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 More...
 
const char * operator+ (int i) const
 
const char * operator- (int i) const
 
 operator const char * () const
 auto-convert WvString to (const char *), when needed. More...
 
const char * cstr () const
 return a (const char *) for this string. More...
 
 operator QString () const
 return a Qt library QString containing the contents of this string. More...
 
int num () const
 Return a stdc++ string with the contents of this string. More...
 
bool isnull () const
 returns true if this string is null More...
 
const WvFastStringifnull (WvStringParm defval) const
 returns either this string, or, if isnull(), the given string. More...
 

Static Public Member Functions

static 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. More...
 

Static Public Attributes

static const WvString empty
 
static const WvFastString null
 

Protected Member Functions

void copy_constructor (const WvFastString &s)
 
void construct (const char *_str)
 
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

static WvStringBuf nullbuf = { 0, 1 }
 

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

Constructor & Destructor Documentation

◆ WvString() [1/17]

WvString::WvString ( )
inline

Definition at line 335 of file wvstring.h.

◆ WvString() [2/17]

WvString::WvString ( short  i)
inline

Definition at line 336 of file wvstring.h.

◆ WvString() [3/17]

WvString::WvString ( unsigned short  i)
inline

Definition at line 337 of file wvstring.h.

◆ WvString() [4/17]

WvString::WvString ( int  i)
inline

Definition at line 338 of file wvstring.h.

◆ WvString() [5/17]

WvString::WvString ( unsigned int  i)
inline

Definition at line 339 of file wvstring.h.

◆ WvString() [6/17]

WvString::WvString ( long  i)
inline

Definition at line 340 of file wvstring.h.

◆ WvString() [7/17]

WvString::WvString ( unsigned long  i)
inline

Definition at line 341 of file wvstring.h.

◆ WvString() [8/17]

WvString::WvString ( long long  i)
inline

Definition at line 342 of file wvstring.h.

◆ WvString() [9/17]

WvString::WvString ( unsigned long long  i)
inline

Definition at line 343 of file wvstring.h.

◆ WvString() [10/17]

WvString::WvString ( double  i)
inline

Definition at line 344 of file wvstring.h.

◆ WvString() [11/17]

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

◆ WvString() [12/17]

WvString::WvString ( const WvFastString s)
inline

Definition at line 354 of file wvstring.h.

◆ WvString() [13/17]

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 88 of file wvstring.cc.

◆ WvString() [14/17]

WvString::WvString ( const QString &  s)

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 unique().

◆ WvString() [15/17]

WvString::WvString ( const QCString &  s)

Definition at line 57 of file wvqtstring.cc.

◆ WvString() [16/17]

WvString::WvString ( const std::string &  s)
inline

Create a string out of a stdc++ string.

To use this, #include wvstdstring.h.

Definition at line 21 of file wvstdstring.h.

◆ WvString() [17/17]

WvString::WvString ( WVSTRING_FORMAT_DECL  )
inline

Definition at line 378 of file wvstring.h.

Member Function Documentation

◆ append() [1/2]

WvString & WvString::append ( WvStringParm  s)

Definition at line 276 of file wvstring.cc.

◆ append() [2/2]

WvString & WvString::append ( WVSTRING_FORMAT_DECL  )
inline

Definition at line 382 of file wvstring.h.

◆ operator=() [1/3]

WvString & WvString::operator= ( int  i)

Definition at line 339 of file wvstring.cc.

◆ operator=() [2/3]

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

Definition at line 348 of file wvstring.cc.

◆ operator=() [3/3]

WvString & WvString::operator= ( const char *  s2)
inline

Definition at line 387 of file wvstring.h.

◆ unique()

WvString & WvString::unique ( )

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

Definition at line 306 of file wvstring.cc.

References is_unique().

Referenced by afterstr(), beforestr(), edit(), strcoll_split(), and WvString().

◆ is_unique()

bool WvString::is_unique ( ) const

returns true if this string is already unique()

Definition at line 320 of file wvstring.cc.

Referenced by unique().

◆ edit()

char * WvString::edit ( )
inline

◆ copy_constructor()

void WvString::copy_constructor ( const WvFastString s)
protected

Definition at line 65 of file wvstring.cc.

◆ construct()

void WvString::construct ( const char *  _str)
inlineprotected

Definition at line 402 of file wvstring.h.

◆ setsize()

void WvFastString::setsize ( size_t  i)
inherited

Definition at line 25 of file wvstring.cc.

◆ offset()

WvFastString WvFastString::offset ( size_t  i) const
inherited

Returns a copy of string pointed i bytes into this.

Will not make it point past the trailing null byte.

Definition at line 79 of file wvstring.cc.

◆ do_format()

void WvFastString::do_format ( WvFastString output,
const char *  format,
const WvFastString *const *  argv 
)
staticinherited

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

Accept a printf-like format specifier (but more limited) and an array of WvStrings, and render them into another WvString.

For example: WvString x[] = {"foo", "blue", 1234}; WvString ret = WvString::do_format("%s%10.2s%-10s", x);

The 'ret' string will be: "foo bl1234 " Note that only 's' is supported, though integers can be rendered automatically into WvStrings. d, f, etc are not allowed!

This function is usually called from some other function which allocates the array automatically.

$ns (n > 0) is also supported for internationalization purposes. e.g. ("%$2s is arg2, and %$1s ia arg1", arg1, arg2)

Definition at line 497 of file wvstring.cc.

References WvFastString::cstr().

Referenced by WvFastString::WvFastString().

◆ len()

size_t WvFastString::len ( ) const
inherited

Definition at line 290 of file wvstring.cc.

◆ link()

void WvFastString::link ( WvStringBuf _buf,
const char *  _str 
)
protectedinherited

Definition at line 257 of file wvstring.cc.

◆ unlink()

void WvFastString::unlink ( )
protectedinherited

Definition at line 247 of file wvstring.cc.

◆ alloc()

WvStringBuf * WvFastString::alloc ( size_t  size)
protectedinherited

Definition at line 266 of file wvstring.cc.

◆ newbuf()

void WvFastString::newbuf ( size_t  size)
protectedinherited

Definition at line 296 of file wvstring.cc.

◆ operator==() [1/2]

bool WvFastString::operator== ( WvStringParm  s2) const
inherited

Definition at line 385 of file wvstring.cc.

◆ operator==() [2/2]

bool WvFastString::operator== ( const char *  s2) const
inherited

Definition at line 406 of file wvstring.cc.

◆ operator!=() [1/2]

bool WvFastString::operator!= ( WvStringParm  s2) const
inherited

Definition at line 391 of file wvstring.cc.

◆ operator!=() [2/2]

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

Definition at line 412 of file wvstring.cc.

◆ operator<() [1/2]

bool WvFastString::operator< ( WvStringParm  s2) const
inherited

Definition at line 397 of file wvstring.cc.

◆ operator<() [2/2]

bool WvFastString::operator< ( const char *  s2) const
inherited

Definition at line 418 of file wvstring.cc.

◆ operator!()

bool WvFastString::operator! ( ) const
inherited

the not operator is 'true' if string is empty

Definition at line 428 of file wvstring.cc.

◆ operator+()

const char * WvFastString::operator+ ( int  i) const
inlineinherited

Definition at line 253 of file wvstring.h.

◆ operator-()

const char * WvFastString::operator- ( int  i) const
inlineinherited

Definition at line 255 of file wvstring.h.

◆ operator const char *()

WvFastString::operator const char * ( ) const
inlineinherited

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

Definition at line 259 of file wvstring.h.

◆ cstr()

const char * WvFastString::cstr ( ) const
inlineinherited

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

Referenced by WvBackslashEncoder::_encode(), WvCRL::decode(), WvX509::decode(), WvFastString::do_format(), UniRetryGen::exists(), UniPStoreGen::get(), UniRegistryGen::get(), UniRetryGen::get(), WvConstStringBuffer::reset(), UniPStoreGen::set(), UniRegistryGen::set(), UniReplicateGen::set(), WvStringMask::set(), spacecat(), UniConfGen::str2int(), substr(), WvLog::uwrite(), and WvStream::write().

◆ operator QString()

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.

◆ num()

int WvFastString::num ( ) const
inlineinherited

Return a stdc++ string with the contents of this string.

To use this, #include wvstdstring.h. used to convert WvString to int, when needed. we no longer provide a typecast, because it causes annoyance.

Definition at line 286 of file wvstring.h.

Referenced by WvDBusServerAuth::authorize(), UniConfDaemonConn::execute(), WvDBusMsg::Iter::get_int(), WvIPRouteList::get_kernel(), and WvDBusMsg::Iter::get_uint().

◆ isnull()

bool WvFastString::isnull ( ) const
inlineinherited

◆ ifnull()

const WvFastString & WvFastString::ifnull ( WvStringParm  defval) const
inlineinherited

returns either this string, or, if isnull(), the given string.

Definition at line 294 of file wvstring.h.

References WvFastString::isnull().

Member Data Documentation

◆ empty

const WvString WvString::empty
static

Definition at line 333 of file wvstring.h.

◆ buf

WvStringBuf* WvFastString::buf
protectedinherited

Definition at line 98 of file wvstring.h.

◆ str

char* WvFastString::str
protectedinherited

Definition at line 99 of file wvstring.h.

◆ nullbuf

WvStringBuf WvFastString::nullbuf = { 0, 1 }
staticprotectedinherited

Definition at line 102 of file wvstring.h.

◆ null

const WvFastString WvFastString::null
staticinherited

Definition at line 106 of file wvstring.h.


The documentation for this class was generated from the following files: