CStringArray Class Reference

Class to manage a double null-terminated list of strings, such as "one\0two\0three\0". More...

#include <CStringArray.h>

Inheritance diagram for CStringArray:
Collaboration diagram for CStringArray:

Classes

class  Iterator
 

Public Member Functions

CStringArrayoperator= (const char *cstr)
 
bool add (const char *str, int length=-1)
 Append a new string (or array of strings) to the end of the array. More...
 
bool add (const String &str)
 Append a new string (or array of strings) to the end of the array. More...
 
int indexOf (const char *str, bool ignoreCase=true) const
 Find the given string and return its index. More...
 
int indexOf (const String &str, bool ignoreCase=true) const
 Find the given string and return its index. More...
 
bool contains (const char *str, bool ignoreCase=true) const
 Check if array contains a string. More...
 
bool contains (const String &str, bool ignoreCase=true) const
 Check if array contains a string. More...
 
const char * getValue (unsigned index) const
 Get string at the given position. More...
 
const char * operator[] (unsigned index) const
 Get string at the given position. More...
 
const char * front () const
 Get first value in array, null if empty. More...
 
bool pushFront (const char *str)
 Insert item at start of array. More...
 
String popFront ()
 Pop first item from array (at index 0) More...
 
const char * back () const
 Get last item in array, null if empty. More...
 
bool pushBack (const char *str)
 Add item to end of array. More...
 
String popBack ()
 Pop last item from array. More...
 
void clear ()
 Empty the array. More...
 
unsigned count () const
 Get quantity of strings in array. More...
 
String join (const String &separator=",") const
 Get contents of array as delimited string. More...
 
int compareTo (const char *cstr, size_t length) const
 
int compareTo (const String &s) const
 
bool equals (const String &s) const
 
bool equals (const char *cstr) const
 
bool equals (const char *cstr, size_t length) const
 
bool equals (const FlashString &fstr) const
 
bool reserve (size_t size)
 Pre-allocate String memory. More...
 
bool operator== (const String &rhs) const
 
bool operator== (const char *cstr) const
 
bool operator== (const FlashString &fstr) const
 
bool operator!= (const String &rhs) const
 
bool operator!= (const char *cstr) const
 
bool operator< (const String &rhs) const
 
bool operator> (const String &rhs) const
 
bool operator<= (const String &rhs) const
 
bool operator>= (const String &rhs) const
 
const char * c_str () const
 Get a constant (un-modifiable) pointer to String content. More...
 
bool endsWith (char suffix) const
 Compare the end of a String. More...
 
bool endsWith (const String &suffix) const
 Compare the end of a String. More...
 
bool equalsIgnoreCase (const char *cstr) const
 
bool equalsIgnoreCase (const char *cstr, size_t length) const
 
bool equalsIgnoreCase (const String &s2) const
 
bool equalsIgnoreCase (const FlashString &fstr) const
 
size_t getBytes (unsigned char *buf, size_t bufsize, size_t index=0) const
 Read contents of a String into a buffer. More...
 
size_t length (void) const
 Obtain the String length in characters, excluding NUL terminator. More...
 
bool startsWith (const String &prefix) const
 Compare the start of a String Comparison is case-sensitive, must match exactly. More...
 
bool startsWith (const String &prefix, size_t offset) const
 Compare a string portion. More...
 
void toCharArray (char *buf, size_t bufsize, size_t index=0) const
 Read contents of String into a buffer. More...
 
void toLowerCase (void)
 Convert the entire String content to lower case. More...
 
void toUpperCase (void)
 Convert the entire String content to upper case. More...
 
Constructors
 CStringArray (const String &str)
 
 CStringArray (const char *cstr=nullptr)
 
 CStringArray (const char *cstr, unsigned int length)
 
 CStringArray (flash_string_t pstr, int length=-1)
 
 CStringArray (const FlashString &fstr)
 
Concatenation operators
CStringArrayoperator+= (const String &str)
 
CStringArrayoperator+= (const char *cstr)
 
template<typename T >
CStringArrayoperator+= (T value)
 Append numbers, etc. to the array. More...
 
Iterator support (forward only)
Iterator begin () const
 
Iterator end () const
 

Detailed Description

Class to manage a double null-terminated list of strings, such as "one\0two\0three\0".

Constructor & Destructor Documentation

◆ CStringArray() [1/5]

CStringArray::CStringArray ( const String str)
inline

◆ CStringArray() [2/5]

CStringArray::CStringArray ( const char *  cstr = nullptr)
inline

◆ CStringArray() [3/5]

CStringArray::CStringArray ( const char *  cstr,
unsigned int  length 
)
inline

◆ CStringArray() [4/5]

CStringArray::CStringArray ( flash_string_t  pstr,
int  length = -1 
)
inlineexplicit

◆ CStringArray() [5/5]

CStringArray::CStringArray ( const FlashString fstr)
inline

Member Function Documentation

◆ add() [1/2]

bool CStringArray::add ( const char *  str,
int  length = -1 
)

Append a new string (or array of strings) to the end of the array.

Parameters
str
lengthLength of new string in array (default is length of str)
Return values
boolfalse on memory allocation error
Note
If str contains any NUL characters it will be handled as an array

◆ add() [2/2]

bool CStringArray::add ( const String str)
inline

Append a new string (or array of strings) to the end of the array.

Parameters
str
Return values
boolfalse on memory allocation error
Note
If str contains any NUL characters it will be handled as an array

◆ back()

const char* CStringArray::back ( ) const

Get last item in array, null if empty.

◆ begin()

Iterator CStringArray::begin ( ) const
inline

◆ c_str()

const char* String::c_str
inline

Get a constant (un-modifiable) pointer to String content.

Return values
constchar* Always valid, even for a null string

◆ clear()

void CStringArray::clear ( )
inline

Empty the array.

◆ compareTo() [1/2]

int String::compareTo

◆ compareTo() [2/2]

int String::compareTo
inline

◆ contains() [1/2]

bool CStringArray::contains ( const char *  str,
bool  ignoreCase = true 
) const
inline

Check if array contains a string.

Parameters
strString to search for
ignoreCaseWhether search is case-sensitive or not
Return values
boolTrue if string exists in array
Note
Search is not case-sensitive

◆ contains() [2/2]

bool CStringArray::contains ( const String str,
bool  ignoreCase = true 
) const
inline

Check if array contains a string.

Parameters
strString to search for
ignoreCaseWhether search is case-sensitive or not
Return values
boolTrue if string exists in array
Note
Search is not case-sensitive

◆ count()

unsigned CStringArray::count ( ) const

Get quantity of strings in array.

Return values
unsignedQuantity of strings

◆ end()

Iterator CStringArray::end ( ) const
inline

◆ endsWith() [1/2]

bool String::endsWith

Compare the end of a String.

Parameters
suffix
Return values
booltrue on match

◆ endsWith() [2/2]

bool String::endsWith

Compare the end of a String.

Parameters
suffix
Return values
booltrue on match

◆ equals() [1/4]

bool String::equals

◆ equals() [2/4]

bool String::equals

◆ equals() [3/4]

bool String::equals
inline

◆ equals() [4/4]

bool String::equals
inline

◆ equalsIgnoreCase() [1/4]

bool String::equalsIgnoreCase

◆ equalsIgnoreCase() [2/4]

bool String::equalsIgnoreCase

◆ equalsIgnoreCase() [3/4]

bool String::equalsIgnoreCase
inline

◆ equalsIgnoreCase() [4/4]

bool String::equalsIgnoreCase
inline

◆ front()

const char* CStringArray::front ( ) const
inline

Get first value in array, null if empty.

◆ getBytes()

size_t String::getBytes

Read contents of a String into a buffer.

Parameters
bufbuffer to write data
bufsizesize of buffer in bytes
indexoffset to start
Return values
unsignednumber of bytes copied, excluding nul terminator
Note
Returned data always nul terminated so buffer size needs to take this into account

◆ getValue()

const char* CStringArray::getValue ( unsigned  index) const

Get string at the given position.

Parameters
index0-based index of string to obtain
Return values
constchar* nullptr if index is not valid

◆ indexOf() [1/2]

int CStringArray::indexOf ( const char *  str,
bool  ignoreCase = true 
) const

Find the given string and return its index.

Parameters
strString to find
ignoreCaseWhether search is case-sensitive or not
Return values
intindex of given string, -1 if not found
Note
Comparison is not case-sensitive

◆ indexOf() [2/2]

int CStringArray::indexOf ( const String str,
bool  ignoreCase = true 
) const
inline

Find the given string and return its index.

Parameters
strString to find
ignoreCaseWhether search is case-sensitive or not
Return values
intindex of given string, -1 if not found
Note
Comparison is not case-sensitive

◆ join()

String CStringArray::join ( const String separator = ",") const

Get contents of array as delimited string.

Parameters
separatorWhat to join elements with
Return values
Stringe.g. CStringArray(F("a\0b\0c")).join() returns "a,b,c"

◆ length()

size_t String::length ( void  )
inline

Obtain the String length in characters, excluding NUL terminator.

◆ operator!=() [1/2]

bool String::operator!=
inline

◆ operator!=() [2/2]

bool String::operator!=
inline

◆ operator+=() [1/3]

CStringArray& CStringArray::operator+= ( const char *  cstr)
inline

◆ operator+=() [2/3]

CStringArray& CStringArray::operator+= ( const String str)
inline

◆ operator+=() [3/3]

template<typename T >
CStringArray& CStringArray::operator+= ( value)
inline

Append numbers, etc. to the array.

Parameters
valuechar, int, float, etc. as supported by String

◆ operator<()

bool String::operator<
inline

◆ operator<=()

bool String::operator<=
inline

◆ operator=()

CStringArray& CStringArray::operator= ( const char *  cstr)
inline

◆ operator==() [1/3]

bool String::operator==
inline

◆ operator==() [2/3]

bool String::operator==
inline

◆ operator==() [3/3]

bool String::operator==
inline

◆ operator>()

bool String::operator>
inline

◆ operator>=()

bool String::operator>=
inline

◆ operator[]()

const char* CStringArray::operator[] ( unsigned  index) const
inline

Get string at the given position.

Parameters
index0-based index of string to obtain
Return values
constchar* nullptr if index is not valid

◆ popBack()

String CStringArray::popBack ( )

Pop last item from array.

Return values
Stringnull if array is empty

◆ popFront()

String CStringArray::popFront ( )

Pop first item from array (at index 0)

Return values
Stringnull if array is empty

◆ pushBack()

bool CStringArray::pushBack ( const char *  str)
inline

Add item to end of array.

Parameters
strItem to add
Return values
boolfalse on memory error

◆ pushFront()

bool CStringArray::pushFront ( const char *  str)

Insert item at start of array.

Parameters
strItem to insert
Return values
boolfalse on memory error

◆ reserve()

bool String::reserve

Pre-allocate String memory.

Parameters
size
Return values
booltrue on success, false on failure

On failure, the String is left unchanged. reserve(0), if successful, will validate an invalid string (i.e., "if (s)" will be true afterwards)

◆ startsWith() [1/2]

bool String::startsWith
inline

Compare the start of a String Comparison is case-sensitive, must match exactly.

Parameters
prefix
Return values
booltrue on match

◆ startsWith() [2/2]

bool String::startsWith

Compare a string portion.

Parameters
prefix
offsetIndex to start comparison at
Return values
booltrue on match
Note
Comparison is case-sensitive, must match exactly

mis-named as does not necessarily compare from start

◆ toCharArray()

void String::toCharArray
inline

Read contents of String into a buffer.

See also
See getBytes()

◆ toLowerCase()

void String::toLowerCase ( void  )

Convert the entire String content to lower case.

◆ toUpperCase()

void String::toUpperCase ( void  )

Convert the entire String content to upper case.


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