WvStreams
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes
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]

List of all members.

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.
 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 (const std::string &s)
 Create a string out of a stdc++ string.
 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.
bool is_unique () const
 returns true if this string is already unique()
char * edit ()
 make the string editable, and return a non-const (char*)
void setsize (size_t i)
WvFastString offset (size_t i) const
 Returns a copy of string pointed i bytes into this.
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
 Return a stdc++ string with the contents of this string.
bool isnull () const
 returns true if this string is null
const WvFastStringifnull (WvStringParm defval) const
 returns either this string, or, if isnull(), the given string.

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.

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::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::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::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::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.


Member Function Documentation

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(), UniIniGen::refresh(), strcoll_split(), and WvString().

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.

void WvFastString::do_format ( WvFastString output,
const char *  format,
const WvFastString *const *  argv 
) [static, inherited]

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

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

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

Definition at line 259 of file wvstring.h.

const char* WvFastString::cstr ( ) const [inline, inherited]
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().

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

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

const WvFastString& WvFastString::ifnull ( WvStringParm  defval) const [inline, inherited]

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

Definition at line 294 of file wvstring.h.

References WvFastString::isnull().


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