libcommonc++  0.7
CString Class Reference

An implicitly shared, reference-counted container for an immutable, NUL-terminated C string. More...

#include <CString.h++>

Public Member Functions

 CString ()
 Construct a new, null CString. More...
 
 CString (const char *str)
 Construct a new CString that will take ownership of the given C string. More...
 
 CString (const CString &other)
 Copy constructor. More...
 
virtual ~CString ()
 Destructor. More...
 
const char * data () const
 Get a pointer to the character array. More...
 
const byte_tbytes () const
 Get a pointer to the character array, reinterpreted as a byte array. More...
 
size_t length () const
 Get the length of the string. More...
 
 operator const char * () const
 Cast operator. More...
 
CStringoperator= (const CString &other)
 Assignment operator. More...
 
bool isNull () const
 Test if the string is NULL. More...
 
char operator[] (int index) const
 Array index operator. More...
 

Detailed Description

An implicitly shared, reference-counted container for an immutable, NUL-terminated C string.

Instances of this class may be efficiently passed by value.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ CString() [1/3]

CString ( )

Construct a new, null CString.

◆ CString() [2/3]

CString ( const char *  str)
explicit

Construct a new CString that will take ownership of the given C string.

◆ CString() [3/3]

CString ( const CString other)

Copy constructor.

◆ ~CString()

~CString ( )
virtual

Destructor.

Member Function Documentation

◆ bytes()

const byte_t* bytes ( ) const
inline

Get a pointer to the character array, reinterpreted as a byte array.

◆ data()

const char* data ( ) const
inline

Get a pointer to the character array.

◆ isNull()

bool isNull ( ) const
inline

Test if the string is NULL.

◆ length()

size_t length ( ) const

Get the length of the string.

◆ operator const char *()

operator const char * ( ) const
inline

Cast operator.

◆ operator=()

CString & operator= ( const CString other)

Assignment operator.

◆ operator[]()

char operator[] ( int  index) const

Array index operator.

Returns the character at the given offset in the string.

Parameters
indexThe index.
Returns
The character at the specified index, as a Char.
Exceptions
OutOfBoundsExceptionIf index is out of range.

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