#include <wvstring.h>
Inheritance diagram for WvString:
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 323 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 (const std::string &s) | |
Create a string out of a stdc++ string. | |
WvString (WVSTRING_FORMAT_DECL) | |
WvString & | append (WvStringParm s) |
WvString & | append (WVSTRING_FORMAT_DECL) |
WvString & | operator= (int i) |
WvString & | operator= (const WvFastString &s2) |
WvString & | operator= (const char *s2) |
WvString & | unique () |
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) |
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 | |
const WvFastString & | ifnull (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 () |
WvStringBuf * | alloc (size_t size) |
void | newbuf (size_t size) |
Protected Attributes | |
WvStringBuf * | buf |
char * | str |
Static Protected Attributes | |
static WvStringBuf | nullbuf = { 0, 1 } |
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 346 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 77 of file wvstring.cc.
References construct().
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(), WvFastString::nullbuf, and 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.
References construct().
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.
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.
Definition at line 470 of file wvstring.cc.
References WvFastString::cstr(), WvFastString::setsize(), and WvFastString::str.
Referenced by WvFastString::WvFastString().
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 261 of file wvstring.h.
References WvFastString::str.
Referenced by WvBackslashEncoder::_encode(), UniListIter::add(), WvConfEmu::add_callback(), WvMonikerRegistry::create(), WvCRLMgr::decode(), WvConfEmu::del_callback(), UniReplicateGen::deltacallback(), WvFastString::do_format(), WvConfEmu::get(), WvConfigSectionEmu::get(), UniRetryGen::get(), UniRegistryGen::get(), UniPStoreGen::get(), UniConfKey::hastrailingslash(), WvFastString::operator QString(), WvArgsData::parser(), WvBufBase< unsigned char >::putstr(), UniClientConn::readcmd(), UniReplicateGen::replicate(), WvConstStringBuffer::reset(), WvStringMask::set(), UniReplicateGen::set(), UniRegistryGen::set(), UniPStoreGen::set(), UniConfGen::str2int(), substr(), WvX509Mgr::unhexify(), WvStream::write(), and WvTaskMan::yield().
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] |
used to convert WvString to int, when needed.
we no longer provide a typecast, because it causes annoyance.
Definition at line 280 of file wvstring.h.
References WvFastString::str.
Referenced by UniConfDaemonConn::execute(), and WvIPRouteList::get_kernel().