#include <wvstring.h>
Public Member Functions | |
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 Member Functions | |
void | do_format (WvString &output, char *format, const WvString **a) |
void | do_format (WvString &output, char *format, const WvString **a) |
Private Member Functions | |
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 |
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.
|
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. Referenced by append(). |
|
Copy Constructor Definition at line 38 of file wvstring.cc. |
|
Create a WvString out of the char * _str Definition at line 44 of file wvstring.cc. |
|
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. References newbuf(). |
|
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 __wvs_n, and do_format(). |
|
Definition at line 65 of file wvstring.cc. References unlink(). |
|
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. |
|
Copy Constructor |
|
Create a WvString out of the char * _str |
|
NOTE: make sure that 32 bytes is big enough for your longest int. This is true up to at least 64 bits. |
|
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 __wvs_n, and do_format(). |
|
|
|
|
|
Definition at line 86 of file wvstring.cc. References buf, WvStringBuf::links, size, WvStringBuf::size, and WVSTRINGBUF_SIZE. |
|
Definition at line 188 of file utils/wvstring.h. References append(), and WvString(). |
|
|
|
Definition at line 188 of file include/wvstring.h. References append(), and WvString(). |
|
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(). |
|
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. |
|
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. Referenced by WvMD5::WvMD5(). |
|
when this is called, we assume output.str == NULL; it will be filled. |
|
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(). |
|
make the string editable, and return a non-const (char*) Definition at line 233 of file utils/wvstring.h. |
|
make the string editable, and return a non-const (char*) Definition at line 233 of file include/wvstring.h. 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(). |
|
|
|
Definition at line 108 of file wvstring.cc. References buf, and WvStringBuf::size. Referenced by backslash_escape(), and unique(). |
|
|
|
Definition at line 78 of file wvstring.cc. References buf, WvStringBuf::links, and str. Referenced by operator=(), unique(), and WvString(). |
|
|
|
Definition at line 115 of file wvstring.cc. References alloc(), buf, WvStringBuf::data, WvStringBuf::links, and str. Referenced by setsize(), and WvString(). |
|
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. |
|
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. Referenced by WvIPRouteList::get_kernel(), and WvHConf::num(). |
|
auto-convert WvString to (const char *), when needed. Definition at line 219 of file utils/wvstring.h. |
|
auto-convert WvString to (const char *), when needed. Definition at line 219 of file include/wvstring.h. |
|
the not operator is 'true' if string is empty |
|
the not operator is 'true' if string is empty Definition at line 175 of file wvstring.cc. |
|
|
|
|
|
Definition at line 168 of file wvstring.cc. References str. |
|
Definition at line 156 of file wvstring.cc. References str. |
|
Definition at line 211 of file utils/wvstring.h. |
|
Definition at line 211 of file include/wvstring.h. |
|
Definition at line 213 of file utils/wvstring.h. |
|
Definition at line 213 of file include/wvstring.h. |
|
|
|
Definition at line 139 of file wvstring.cc. |
|
|
|
|
|
Definition at line 162 of file wvstring.cc. References str. |
|
Definition at line 150 of file wvstring.cc. References str. |
|
|
|
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(). |
|
make the buf and str pointers owned only by this WvString. |
|
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, and unlink(). Referenced by WvLogBuffer::_end_line(), append(), edit(), encode_hostname_as_DN(), WvDirIter::next(), 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(). |
|
|
|
Definition at line 71 of file wvstring.cc. References buf, and WvStringBuf::links. Referenced by operator=(), setsize(), unique(), and ~WvString(). |
|
Definition at line 100 of file utils/wvstring.h. |
|
Definition at line 100 of file include/wvstring.h. Referenced by alloc(), len(), link(), newbuf(), operator!(), operator=(), unique(), unlink(), and WvString(). |
|
Definition at line 101 of file utils/wvstring.h. |
|
Definition at line 101 of file include/wvstring.h. Referenced by edit(), link(), newbuf(), operator!(), operator!=(), operator=(), operator==(), and WvString(). |