|
| LwString (char *inStr, size_t maxLength) |
|
LwString & | a (const char *a0) |
|
LwString & | a (const LwString &a0) |
|
template<typename M , typename N > |
LwString & | a (const M &a0, const N &a1) |
|
template<typename M , typename N , typename O > |
LwString & | a (const M &a0, const N &a1, const O &a2) |
|
template<typename M , typename N , typename O , typename P > |
LwString & | a (const M &a0, const N &a1, const O &a2, const P &a3) |
|
template<typename M , typename N , typename O , typename P , typename Q > |
LwString & | a (const M &a0, const N &a1, const O &a2, const P &a3, const Q &a4) |
|
template<typename M , typename N , typename O , typename P , typename Q , typename R > |
LwString & | a (const M &a0, const N &a1, const O &a2, const P &a3, const Q &a4, const R &a5) |
|
template<typename M , typename N , typename O , typename P , typename Q , typename R , typename S > |
LwString & | a (const M &a0, const N &a1, const O &a2, const P &a3, const Q &a4, const R &a5, const S &a6) |
|
template<typename M , typename N , typename O , typename P , typename Q , typename R , typename S , typename T > |
LwString & | a (const M &a0, const N &a1, const O &a2, const P &a3, const Q &a4, const R &a5, const S &a6, const S &a7) |
|
LwString & | a (double a0) |
|
LwString & | a (Double a0) |
|
LwString & | a (float a0) |
|
LwString & | a (Float a0) |
|
LwString & | a (int32 a0) |
|
LwString & | a (int64 a0) |
|
LwString & | a (uint32 a0) |
|
LwString & | a (uint64 a0) |
|
LwString & | aChar (char a0) |
|
char * | begin () |
|
const char * | begin () const |
| Make every begin & end method from LwConstString available. More...
|
|
size_t | capacity () const |
|
void | clear () |
|
char * | end () |
|
const char * | end () const |
|
LwString & | operator+= (const char *pOther) |
|
LwString & | operator+= (const LwString &other) |
|
LwString & | operator= (const char *pOther) |
|
LwString & | operator= (const LwConstString &other) |
|
void | resize (size_t newSize) |
| Resizes the string. More...
|
|
void | setToSubstr (const LwConstString &source, char *_start, char *_end) |
|
void | setToSubstr (const LwConstString &source, size_t _start, size_t size) |
| Takes a subset from source in the range [_start; _start + size), and copies it to our string. More...
|
|
size_t | size () const |
|
| LwConstString (const char *inStr, size_t maxLength) |
|
| LwConstString (const LwConstString &other)=default |
|
const char * | begin () const |
|
const char * | c_str () const |
|
size_t | capacity () const |
|
const char * | end () const |
|
size_t | find (const char *val, size_t pos=0) const |
|
size_t | find (const LwConstString *val, size_t pos=0) const |
|
size_t | find_first_of (char c, size_t pos=0) const |
|
size_t | find_first_of (const char *val, size_t pos=0) const |
|
size_t | find_last_of (char c, size_t pos=static_cast< size_t >(-1)) const |
|
bool | operator!= (const char *other) const |
|
bool | operator!= (const LwConstString &other) const |
|
bool | operator< (const char *other) const |
|
bool | operator< (const LwConstString &other) const |
|
LwConstString & | operator= (const LwConstString &other)=delete |
|
bool | operator== (const char *other) const |
|
bool | operator== (const LwConstString &other) const |
|
bool | operator> (const char *other) const |
|
bool | operator> (const LwConstString &other) const |
|
size_t | size () const |
|
This is a Light-weight string wrapper around the C string interface.
This class is heavily influenced by Tom Forsyth's article "A sprintf
that isn't as ugly" https://home.comcast.net/~tom_forsyth/blog.wiki.html#[[A%20sprintf%20that%20isn%27t%20as%20ugly]]
The goals are:
- No dynamic allocation.
- Easier to read and control than snprintf()
- Type-safe (in as much as C can ever be type-safe - bloody auto-converts).
- Overflow-safe (i.e. it will refuse to scribble, and will assert in debug mode).
LwString needs to be fed a pointer and a maximum length size. The pointer's preexisting contents will be preserved. For example: char buf[1024]; buf[0] = '\0'; LwString myStr( buf, 1024 );
{ char *buf = new char[1024]; LwString myStr( buf, 1024 ); delete buf; //This class will never deallocate the pointer. }
char buf[512]; buf[0] = 'H'; buf[1] = 'i'; buf[2] = '!'; buf[3] = '\0'; LwString myStr( buf, 512 ); printf( myStr.c_str() ) //Hi!
In order to concatenate strings, you need to use the a() function. Concatenations are appended to the current string. You can concatenate strings, integers, raw char strings, and floats. Examples: Example 1: myStr.a( "Hello", " ", "World!" ); //Hello World!
Example 2: myStr.a( "Hello", " " ); myStr.a( "World!" ); //Hello World!
Example 3: char myZero = 0; myStr.a( "One", " + ", 1, " equals ", myZero ); //One + 1 equals 0
Example 4: myStr.a( 1.5f, " + ", 1.5f, " = ", 1.5f + 1.5f ); //1.5 + 1.5 = 3.0
The += operator only works with strings.
Additionally, there are a few STL-like interfaces: begin (iterator), end (iterator), find, find_first_of The input arguments, behavior and return values are the same as std::string.
Users can specify the precision of floats using LwString::Float myStr.a( LwString::Float( 3.5f, precision, minWidth ) );