CString Class Reference

#include <string.h>

Inheritance diagram for CString:

Detailed Description

Class to store 8 bit strings. The CString stores 8 bit characters. Any characters are legal, including 0C (for example CString("\0\0\0\0", 4) will result in a CString with length 4). CStrings are reference-counted objects. This means that as long as you copy and do not modify strings they are just referenced. The first modification breaks the link and it becomes a unique new object. For error handling see String.

Public Types

using ConstIterator = BaseIterator< const CString, false >
 
using Iterator = ConstIterator
 
using ValueType = Char
 

Public Member Functions

 MAXON_DEFAULT_REFERENCE_CONSTRUCTORS (CString, Reference)
 
 CString (const Char *str, Int count=-1)
 
 CString (Int count, Char fillChar)
 
 CString (const Block< const Char > &str)
 
 CString (const String &str, const StringEncodingRef &stringEncoding=GetUtf8DefaultEncoder())
 
Char operator[] (Int pos) const
 
MAXON_ATTRIBUTE_FORCE_INLINE CStringInterface::CharPtr operator[] (Int position)
 
ConstIterator Begin () const
 
ConstIterator End () const
 
Bool IsEmpty () const
 
Bool IsPopulated () const
 
CStringoperator+= (const CString &str)
 
 operator const Char * () const
 
 operator Block< const Char > () const
 

Static Public Member Functions

static const CStringGetLineEnd ()
 

Private Member Functions

void operator-> () const
 

Member Typedef Documentation

◆ ConstIterator

using ConstIterator = BaseIterator<const CString, false>

◆ Iterator

◆ ValueType

using ValueType = Char

Constructor & Destructor Documentation

◆ CString() [1/4]

CString ( const Char str,
Int  count = -1 
)
explicit

Constructor for Char array. If you have static Char strings use "..."_cs instead.

Parameters
[in]strC string block.
[in]countNumber of characters, -1 to auto detect the length of the string (search for the first 0).

◆ CString() [2/4]

CString ( Int  count,
Char  fillChar 
)
explicit

Constructor to create a string with a specific length and a default character.

Parameters
[in]countNumber of characters of the new string.
[in]fillCharCharacter to fill the string with.

◆ CString() [3/4]

CString ( const Block< const Char > &  str)
explicit

Constructor from a Char Block. If you have static strings use "..."_cs instead.

Parameters
[in]strChar block, for example a BaseArray<Char>.

◆ CString() [4/4]

CString ( const String str,
const StringEncodingRef &  stringEncoding = GetUtf8DefaultEncoder() 
)
explicit

Constructor to create a CString from a String. The lower byte of each character will be copied, whereas the upper byte will be discarded.

Parameters
[in]strUnicode string.
[in]stringEncodingEncoding for the string. By default utf8 is selected. If a nullptr is passed the data is truncated to Char and no conversion takes place.

Member Function Documentation

◆ MAXON_DEFAULT_REFERENCE_CONSTRUCTORS()

MAXON_DEFAULT_REFERENCE_CONSTRUCTORS ( CString  ,
Reference   
)

◆ operator[]() [1/2]

Char operator[] ( Int  pos) const

Index operator to access single characters of the string.

Parameters
[in]posPosition within the string the first character starts with an index of 0. If the position is out of boundaries 0 will be returned.
Returns
Utf32Char for read (right of =), Utf32Char& for write (left of =).

◆ operator[]() [2/2]

MAXON_ATTRIBUTE_FORCE_INLINE CStringInterface::CharPtr operator[] ( Int  position)

Index operator to access single characters of the string.

Parameters
[in]positionPosition within the string the first character starts with an index of 0. if the position is out of boundaries no changes will be made.
Returns
Utf32Char for read (right of =), Utf32Char& for write (left of =).

◆ Begin()

ConstIterator Begin ( ) const

◆ End()

ConstIterator End ( ) const

◆ IsEmpty()

Bool IsEmpty ( ) const

Returns if the string length is zero.

Returns
True if the string doesn't contain any character, or if it is a nullptr.

◆ IsPopulated()

Bool IsPopulated ( ) const

Returns if the string contains any characters.

Returns
True if the string contains any character.

◆ operator+=()

CString& operator+= ( const CString str)

◆ operator const Char *()

operator const Char * ( ) const

Conversion to const Char*, returns the pointer to a null-terminated C string.

Returns
Pointer to null terminated C string (can never be a nullptr).

◆ operator Block< const Char >()

operator Block< const Char > ( ) const

Converts this CString to a block of characters. The null-terminator isn't part of the block.

Returns
Block of characters of this CString.

◆ GetLineEnd()

static const CString& GetLineEnd ( )
static

Returns a string with the platform specific line ending.

Returns
String containing the line ending ("\r\n" or "\r").

◆ operator->()

void operator-> ( ) const
private