Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb::TBStr Class Reference

TBStr is a simple string class. More...

#include <tb_str.h>

Inheritance diagram for tb::TBStr:
tb::TBStrC

Public Member Functions

 TBStr (const TBStr &str)
 
 TBStr (TBStr &&str)
 
 TBStr (const char *str)
 
 TBStr (const char *str, int len)
 
bool Set (TBStr str)
 
bool SetFormatted (const char *format,...) TB_POST_FORMAT(2
 
bool void Clear ()
 
void Remove (int ofs, int len)
 
bool Insert (int ofs, const char *ins, int ins_len=TB_ALL_TO_TERMINATION)
 Insert a c-string to this TBStr at 'ofs'.
 
bool Append (const char *ins, int ins_len=TB_ALL_TO_TERMINATION)
 Append a c-string to this TBStr.
 
bool Append (const TBStr &str)
 Append another TBStr to this string.
 
char * CStr () const
 Get the c-string raw (char *)
 
double atof () const
 Call atof() on the string.
 
int atoi () const
 Call atoi() on the string.
 
long atol () const
 Call atol() on the string.
 
 operator char * () const
 Cast to a writeable (char *) byob.
 
 operator std::string () const
 Implicit cast to a std::string.
 
 operator bool () const
 Cast to a bool - answers whether this TBStr is truly empty: s == empty. More...
 
TBStroperator= (TBStr str)
 Assignment operator.
 
char & operator* ()
 Pointer dereference, returns a reference to the zeroth char of the string (or the terminator of an empty string). More...
 
const char & operator* () const
 Const pointer dereference - returns a const reference to the zeroth character (or terminator of an empty string). More...
 
- Public Member Functions inherited from tb::TBStrC
 TBStrC (const char *str)
 
int Length () const
 
bool IsEmpty () const
 
int Compare (const char *str) const
 
bool Equals (const char *str) const
 
const char * CStr () const
 
const char & operator[] (int n) const
 
 operator const char * () const
 
bool operator== (const char *b) const
 
bool operator== (const TBStrC &b) const
 
bool operator!= (const TBStrC &b) const
 
bool operator< (const TBStrC &b) const
 
bool operator== (const std::string &b) const
 

Friends

class TBValue
 

Additional Inherited Members

- Protected Attributes inherited from tb::TBStrC
char * s
 

Detailed Description

TBStr is a simple string class.

It's a compact wrapper for a char array, and doesn't do any storage magic to avoid buffer copying or remember its length. It is intended as "final storage" of strings since its buffer is compact.

Serious work on strings is better done using TBTempBuffer and then set on a TBStr for final storage (since TBTempBuffer is optimized for speed rather than being compact).

It is guaranteed to have a valid pointer at all times. If uninitialized, emptied or on out of memory, its storage will be a empty ("") const string.

Member Function Documentation

tb::TBStr::operator bool ( ) const
explicit

Cast to a bool - answers whether this TBStr is truly empty: s == empty.

This is different from IsEmpty() because you can still do a Set("") which will allocate a single byte for the string terminator.

char& tb::TBStr::operator* ( )
inline

Pointer dereference, returns a reference to the zeroth char of the string (or the terminator of an empty string).

const char& tb::TBStr::operator* ( ) const
inline

Const pointer dereference - returns a const reference to the zeroth character (or terminator of an empty string).


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