Iridescence 1.00
Embedded Graphic Framework
Loading...
Searching...
No Matches
DsString Class Reference

DsString is a class representing a character string. More...

#include <ds_string.h>

Public Member Functions

 DsString (size_t max_length=31)
 Creates a DsString object with space for storing a string of specified length.
 
 DsString (const char *str, size_t max_length=DsString::npos)
 Creates a DsString object with space for storing the specified string or a specified length. Copies the string in the newly created DsString object.
 
 DsString (const DsString &src)
 Copy constructor.
 
 DsString (DsString &&src)
 Move constructor.
 
 ~DsString ()
 Destructor.
 
DsStringoperator= (const DsString &rhs)
 Assignment operator from another DsString.
 
DsStringoperator= (DsString &&rhs)
 Move operator.
 
DsStringoperator= (const char *rhs)
 Assignment operator from a C string.
 
DsStringoperator+= (const char *rhs)
 Addition operator - appends a string to the current DsString object.
 
DsString operator+ (const DsString &rhs)
 Addition operator - appends a DsString to the current DsString object.
 
void append (char c, size_t count)
 Appends a character a number of times to the current DsString object.
 
void append (const char *str)
 Appends a C string to the current DsString object.
 
void append (const char *str, size_t count)
 Appends a C string a number of times.
 
void append (char c)
 Appends a single character to the current DsString object.
 
void append (const DsString &str)
 Appends a DsString object to the current DsString object.
 
void insert (size_t pos, char c, size_t count)
 Inserts a character a number of times at a specified position in the current DsString object.
 
void insert (size_t pos, char c)
 Inserts a single character at a specified position in the current DsString object.
 
void insert (size_t pos, const char *str)
 Inserts a C string at a specified position in the current DsString object.
 
void erase (size_t pos, size_t count)
 Erases characters from the specified position.
 
void erase_first (size_t count)
 Erases characters from the beginning of the string.
 
void erase_last (size_t count)
 Erases characters from the end of the string.
 
void clear (void)
 Clears the entire string.
 
void substr (char *substr, size_t pos, size_t count) const
 Extracts a substring of the current string.
 
const char * c_str (void) const
 Returns the pointer to the underlaying C string.
 
 operator const char * () const
 Conversion operator to a pointer to the underlaying C string.
 
size_t length (void) const
 Returns the length of the string.
 
size_t maxLength (void) const
 Returns the maximum string length this DsString can hold.
 
bool empty (void) const
 Is the string empty?
 
char front (void)
 Returns the first character of the string.
 
char back (void)
 Returns the last character of the string.
 
bool operator== (const char *rhs) const
 Comparison operator.
 
bool operator!= (const char *rhs) const
 Comparison operator.
 
bool operator>= (const char *rhs) const
 Comparison operator.
 
bool operator<= (const char *rhs) const
 Comparison operator.
 
bool operator> (const char *rhs) const
 Comparison operator.
 
bool operator< (const char *rhs) const
 Comparison operator.
 
size_t format (const char *format,...)
 Initializes the string using printf() style.
 
size_t format (const char *format, va_list args)
 Initializes the string using vprintf() style.
 
size_t find (char c, size_t pos=0)
 Searches for a character starting at a specific position.
 
size_t find (const char *substr, size_t pos=0)
 Searches for a substring starting at a specific position.
 

Static Public Attributes

static const size_t npos = -1
 Constant representing an invalid position/size value.
 

Detailed Description

DsString is a class representing a character string.

Internally the string is represented as a C character array (C string). Once a DsString object is created with storage space of specific size, it cannot be changed or reallocated.

Constructor & Destructor Documentation

◆ DsString() [1/2]

DsString::DsString ( size_t  max_length = 31)

Creates a DsString object with space for storing a string of specified length.

Parameters
max_lengthMaximum sting length (in characters) to allocate space for. Default is 31 characters. The internal storage space size will be the next multiple of 8 bytes higher than the requested space. An extra character is needed to store the C string NULL termiantion character.

◆ DsString() [2/2]

DsString::DsString ( const char *  str,
size_t  max_length = DsString::npos 
)

Creates a DsString object with space for storing the specified string or a specified length. Copies the string in the newly created DsString object.

Parameters
strSource string
max_lengthMaximum sting length (in characters) to allocate space for. The default is to allocate just enough space for storing the supplied string. The internal storage space size will be the next multiple of 8 bytes higher than the requested space. An extra character is needed to store the C string NULL termiantion character.

Member Function Documentation

◆ append() [1/5]

void DsString::append ( char  c)
inline

Appends a single character to the current DsString object.

Parameters
cCharacter to append

◆ append() [2/5]

void DsString::append ( char  c,
size_t  count 
)

Appends a character a number of times to the current DsString object.

Parameters
cCharacter to append
countNumber of times to append the character

◆ append() [3/5]

void DsString::append ( const char *  str)

Appends a C string to the current DsString object.

Parameters
strString to append
countNumber of times to append the character

◆ append() [4/5]

void DsString::append ( const char *  str,
size_t  count 
)

Appends a C string a number of times.

Parameters
strString to append

◆ append() [5/5]

void DsString::append ( const DsString str)
inline

Appends a DsString object to the current DsString object.

Parameters
strString to append

◆ back()

char DsString::back ( void  )
inline

Returns the last character of the string.

Returns
Last character of the string

◆ c_str()

const char * DsString::c_str ( void  ) const
inline

Returns the pointer to the underlaying C string.

Returns
Pointer to C string

◆ empty()

bool DsString::empty ( void  ) const
inline

Is the string empty?

Returns
True if the string is empty

◆ erase()

void DsString::erase ( size_t  pos,
size_t  count 
)

Erases characters from the specified position.

Parameters
posPosition to erase characters from
countNumber of characters to erase

◆ erase_first()

void DsString::erase_first ( size_t  count)
inline

Erases characters from the beginning of the string.

Parameters
countNumber of characters to erase

◆ erase_last()

void DsString::erase_last ( size_t  count)
inline

Erases characters from the end of the string.

Parameters
countNumber of characters to erase

◆ find() [1/2]

size_t DsString::find ( char  c,
size_t  pos = 0 
)

Searches for a character starting at a specific position.

Parameters
cCharacter to search for
posPosition to start searching at. The default is the beginning of the string.
Returns
The postition of the character if found or DsString::npos if the character was not found

◆ find() [2/2]

size_t DsString::find ( const char *  substr,
size_t  pos = 0 
)

Searches for a substring starting at a specific position.

Parameters
substrSubstring to search for
posPosition to start searching at. The default is the beginning of the string.
Returns
The postition of the substring if found or DsString::npos if not found

◆ format() [1/2]

size_t DsString::format ( const char *  format,
va_list  args 
)

Initializes the string using vprintf() style.

Parameters
formatvprintf() style string
argsVariable argument list

◆ format() [2/2]

size_t DsString::format ( const char *  format,
  ... 
)

Initializes the string using printf() style.

Parameters
formatprintf() style string

◆ front()

char DsString::front ( void  )
inline

Returns the first character of the string.

Returns
First character of the string

◆ insert() [1/3]

void DsString::insert ( size_t  pos,
char  c 
)
inline

Inserts a single character at a specified position in the current DsString object.

Parameters
posPosition to insert at. 0 means insert at the beginning.
cCharacter to insert

◆ insert() [2/3]

void DsString::insert ( size_t  pos,
char  c,
size_t  count 
)

Inserts a character a number of times at a specified position in the current DsString object.

Parameters
posPosition to insert at. 0 means insert at the beginning.
cCharacter to insert
countNumber of times to insert the character

◆ insert() [3/3]

void DsString::insert ( size_t  pos,
const char *  str 
)

Inserts a C string at a specified position in the current DsString object.

Parameters
posPosition to insert at. 0 means insert at the beginning.
strC string to insert

◆ length()

size_t DsString::length ( void  ) const
inline

Returns the length of the string.

Returns
Size of the string

◆ maxLength()

size_t DsString::maxLength ( void  ) const
inline

Returns the maximum string length this DsString can hold.

Returns
Maximum string length

◆ operator const char *()

DsString::operator const char * ( ) const
inline

Conversion operator to a pointer to the underlaying C string.

Returns
Pointer to C string

◆ operator+()

DsString DsString::operator+ ( const DsString rhs)

Addition operator - appends a DsString to the current DsString object.

Parameters
rhsString to append

◆ operator+=()

DsString & DsString::operator+= ( const char *  rhs)

Addition operator - appends a string to the current DsString object.

Parameters
rhsString to append

◆ substr()

void DsString::substr ( char *  substr,
size_t  pos,
size_t  count 
) const

Extracts a substring of the current string.

Parameters
substrC string to extract the substring to
posPosition of the substring in the current string
countLength of the substring to extract

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