Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
CStringArray Class Reference

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

#include <CStringArray.h>

Inheritance diagram for CStringArray:
String

Public Member Functions

bool add (const char *str, unsigned length=0)
 Append a new string to the end of the array. More...
 
bool add (const String &str)
 Append a new string to the end of the array. More...
 
int indexOf (const char *str) const
 Find the given string and return its index. More...
 
int indexOf (const String &str) const
 Find the given string and return its index. More...
 
bool contains (const char *str) const
 Check if array contains a string. More...
 
bool contains (const String &str) 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...
 
void clear ()
 Empty the array. More...
 
unsigned count () const
 Get quantity of strings in array. More...
 

Protected Member Functions

void setString (const char *cstr, int length=-1)
 
void setString (flash_string_t pstr, int length=-1)
 
bool reserve (unsigned int size)
 
bool setLength (unsigned int length)
 set the string length accordingly, expanding if necessary More...
 
unsigned int length (void) const
 
bool concat (const String &str)
 
bool concat (const char *cstr)
 
bool STRING_IRAM_ATTR concat (const char *cstr, unsigned int length)
 
bool concat (char c)
 
bool concat (unsigned char c)
 
bool concat (int num)
 
bool concat (unsigned int num)
 
bool concat (long num)
 
bool concat (unsigned long num)
 
bool concat (float num)
 
bool concat (double num)
 
Stringoperator+= (const String &rhs)
 
Stringoperator+= (const char *cstr)
 
Stringoperator+= (char c)
 
Stringoperator+= (unsigned char num)
 
Stringoperator+= (int num)
 
Stringoperator+= (unsigned int num)
 
Stringoperator+= (long num)
 
Stringoperator+= (unsigned long num)
 
Stringoperator+= (float num)
 
Stringoperator+= (double num)
 
 operator StringIfHelperType () const
 
int STRING_IRAM_ATTR compareTo (const String &s) const
 
bool STRING_IRAM_ATTR equals (const String &s) const
 
bool STRING_IRAM_ATTR equals (const char *cstr) const
 
bool equals (const FlashString &fstr) const
 
bool STRING_IRAM_ATTR operator== (const String &rhs) const
 
bool STRING_IRAM_ATTR operator== (const char *cstr) const
 
bool STRING_IRAM_ATTR operator== (const FlashString &fstr) const
 
bool STRING_IRAM_ATTR operator!= (const String &rhs) const
 
bool STRING_IRAM_ATTR 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
 
bool equalsIgnoreCase (const char *cstr) const
 
bool equalsIgnoreCase (const String &s2) const
 
bool equalsIgnoreCase (const FlashString &fstr) const
 
bool startsWith (const String &prefix) const
 
bool startsWith (const String &prefix, unsigned int offset) const
 
bool endsWith (const String &suffix) const
 
char STRING_IRAM_ATTR charAt (unsigned int index) const
 
void STRING_IRAM_ATTR setCharAt (unsigned int index, char c)
 
char STRING_IRAM_ATTR operator[] (unsigned int index) const
 
char &STRING_IRAM_ATTR operator[] (unsigned int index)
 
unsigned int getBytes (unsigned char *buf, unsigned int bufsize, unsigned int index=0) const
 read contents of string into a buffer More...
 
void toCharArray (char *buf, unsigned int bufsize, unsigned int index=0) const
 
const char * c_str () const
 
char * begin ()
 
const char * begin () const
 
char * end ()
 
const char * end () const
 
int STRING_IRAM_ATTR indexOf (char ch) const
 
int indexOf (char ch, unsigned int fromIndex) const
 
int indexOf (const String &s2, unsigned int fromIndex) const
 
int lastIndexOf (char ch) const
 
int lastIndexOf (char ch, unsigned int fromIndex) const
 
int lastIndexOf (const String &s2) const
 
int lastIndexOf (const String &s2, unsigned int fromIndex) const
 
String substring (unsigned int beginIndex) const
 
String substring (unsigned int beginIndex, unsigned int endIndex) const
 
void replace (char find, char replace)
 
void replace (const String &find, const String &replace)
 
void remove (unsigned int index)
 
void remove (unsigned int index, unsigned int count)
 
void toLowerCase (void)
 
void toUpperCase (void)
 
void trim (void)
 
long toInt (void) const
 
float toFloat (void) const
 
void STRING_IRAM_ATTR invalidate (void)
 
bool STRING_IRAM_ATTR changeBuffer (unsigned int maxStrLen)
 
Stringcopy (const char *cstr, unsigned int length)
 
Stringcopy (flash_string_t pstr, unsigned int length)
 
void move (String &rhs)
 

Protected Attributes

char * buffer = nullptr
 
uint16_t capacity = 0
 
uint16_t len = 0
 

Static Protected Attributes

static const String nullstr
 A null string evaluates to false. More...
 
static const String empty
 An empty string evaluates to true. More...
 

Detailed Description

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

Note

Comparison with Vector<String>

Advantages: More memory efficient. Uses only a single heap allocation Useful for simple lookups, e.g. mapping enumerated values to strings

Disadvantages:

Slower. Items must be iterated using multiple strlen() calls
Ordering not supported
Insertions / deletions not supported (yet)

Member Function Documentation

bool CStringArray::add ( const char *  str,
unsigned  length = 0 
)

Append a new string 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
bool CStringArray::add ( const String str)
inline

Append a new string to the end of the array.

Parameters
str
Return values
boolfalse on memory allocation error
void CStringArray::clear ( )
inline

Empty the array.

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

Check if array contains a string.

Parameters
strString to search for
Return values
boolTrue if string exists in array
Note
Search is not case-sensitive
bool CStringArray::contains ( const String str) const
inline

Check if array contains a string.

Parameters
strString to search for
Return values
boolTrue if string exists in array
Note
Search is not case-sensitive
unsigned CStringArray::count ( ) const

Get quantity of strings in array.

Return values
unsignedQuantity of strings
unsigned int String::getBytes ( unsigned char *  buf,
unsigned int  bufsize,
unsigned int  index = 0 
) const
inherited

read contents of 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
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
int CStringArray::indexOf ( const char *  str) const

Find the given string and return its index.

Parameters
strString to find
Return values
intindex of given string, -1 if not found
Note
Comparison is not case-sensitive
int CStringArray::indexOf ( const String str) const
inline

Find the given string and return its index.

Parameters
strString to find
Return values
intindex of given string, -1 if not found
Note
Comparison is not case-sensitive
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
bool String::setLength ( unsigned int  length)
inherited

set the string length accordingly, expanding if necessary

Parameters
lengthrequired for string (nul terminator additional)
Return values
trueon success, false on failure
Note
extra characters are undefined

Member Data Documentation

const String String::empty
staticinherited

An empty string evaluates to true.

const String String::nullstr
staticinherited

A null string evaluates to false.