#include <wvstring.h>
When we copy to a normal WvString object, _then_ we allocate the memory. If that never happens, we never need to allocate.
DON'T CREATE INSTANCES OF THIS! It's mostly useful for parameter passing, and for that you should use WvStringParm. You can get yourself into _big_ trouble if you have an instance of a WvFastString created from a (char *) object and then you modify the original (char *).
For almost all purposes, use WvString instead. At worst, it's a bit slower.
Definition at line 93 of file wvstring.h.
Public Member Functions | |
WvFastString () | |
Create an empty, NULL string. | |
void | setsize (size_t i) |
WvFastString (const WvFastString &s) | |
Copy constructor. | |
WvFastString (const WvString &s) | |
WvFastString (const char *_str) | |
Create a string out of a (char *)-style string _without_ copying any memory. | |
WvFastString (const QString &s) | |
Create a string out of a Qt library QString. | |
WvFastString (const QCString &s) | |
WvFastString (const std::string &s) | |
Create a string out of a stdc++ string. | |
WvFastString (short i) | |
NOTE: make sure that 32 bytes is big enough for your longest int. | |
WvFastString (unsigned short i) | |
WvFastString (int i) | |
WvFastString (unsigned int i) | |
WvFastString (long i) | |
WvFastString (unsigned long i) | |
WvFastString (long long i) | |
WvFastString (unsigned long long i) | |
WvFastString (double i) | |
WvFastString (WVSTRING_FORMAT_DECL) | |
Now, you're probably thinking to yourself: Boy, does this ever look ridiculous. | |
~WvFastString () | |
size_t | len () const |
bool | operator== (WvStringParm s2) const |
bool | operator!= (WvStringParm s2) const |
bool | operator< (WvStringParm s2) const |
bool | operator== (const char *s2) const |
bool | operator!= (const char *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 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 WvFastString | null |
Protected Member Functions | |
void | construct (const char *_str) |
WvFastString & | operator= (const WvFastString &s2) |
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 } |
Friends | |
class | WvString |
WvFastString::WvFastString | ( | ) |
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 33 of file wvstring.cc.
References link(), and nullbuf.
Referenced by WvString::operator=().
WvFastString::WvFastString | ( | const WvFastString & | s | ) |
Copy constructor.
We can safely copy from a normal WvString like this too, since no special behaviour is required in this direction. (Note that copying from a WvFastString to a WvString _does_ require special care!)
Definition at line 39 of file wvstring.cc.
WvFastString::WvFastString | ( | const char * | _str | ) |
Create a string out of a (char *)-style string _without_ copying any memory.
It's fast, but we have to trust that the _str won't change for the lifetime of our WvFastString. That's usually safe, if you didn't use WvFastString where you should have used a WvString.
Definition at line 59 of file wvstring.cc.
References construct().
WvFastString::WvFastString | ( | const QString & | s | ) |
WvFastString::WvFastString | ( | const std::string & | s | ) | [inline] |
Create a string out of a stdc++ string.
To use this, include wvstdstring.h.
Definition at line 15 of file wvstdstring.h.
References construct().
WvFastString::WvFastString | ( | short | i | ) |
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 169 of file wvstring.cc.
WvFastString::WvFastString | ( | WVSTRING_FORMAT_DECL | ) | [inline] |
Now, you're probably thinking to yourself: Boy, does this ever look ridiculous.
And indeed it does. However, it is completely type-safe and when 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 182 of file wvstring.h.
References do_format(), link(), null, and nullbuf.
void WvFastString::do_format | ( | WvFastString & | output, | |
const char * | format, | |||
const WvFastString *const * | argv | |||
) | [static] |
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 488 of file wvstring.cc.
References cstr(), setsize(), and str.
Referenced by WvFastString().
WvFastString::operator const char * | ( | ) | const [inline] |
auto-convert WvString to (const char *), when needed.
Definition at line 253 of file wvstring.h.
References str.
const char* WvFastString::cstr | ( | ) | const [inline] |
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 str.
Referenced by WvBackslashEncoder::_encode(), UniListIter::add(), WvConfEmu::add_callback(), WvMonikerRegistry::create(), WvCRLMgr::decode(), WvConfEmu::del_callback(), UniReplicateGen::deltacallback(), do_format(), WvLogBuffer::feed_receiver(), WvConfEmu::get(), WvConfigSectionEmu::get(), UniRetryGen::get(), UniRegistryGen::get(), UniPStoreGen::get(), UniConfKey::hastrailingslash(), 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(), UniRetryGen::UniRetryGen(), WvLog::uwrite(), WvStream::write(), and WvTaskMan::yield().
WvFastString::operator QString | ( | ) | const |
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 cstr().
int WvFastString::num | ( | ) | const [inline] |
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 280 of file wvstring.h.
References str.
Referenced by WvDaemon::do_load(), UniConfDaemonConn::execute(), and WvIPRouteList::get_kernel().
const WvFastString& WvFastString::ifnull | ( | WvStringParm | defval | ) | const [inline] |
returns either this string, or, if isnull(), the given string.
Definition at line 288 of file wvstring.h.
References isnull().