#include <WString.h>

Inheritance diagram for StringSumHelper:
[legend]
Collaboration diagram for StringSumHelper:
[legend]

Public Member Functions

 StringSumHelper (const String &s)
 
 StringSumHelper (const char *p)
 
 StringSumHelper (char c)
 
 StringSumHelper (unsigned char num)
 
 StringSumHelper (int num)
 
 StringSumHelper (unsigned int num)
 
 StringSumHelper (long num)
 
 StringSumHelper (long long num)
 
 StringSumHelper (unsigned long num)
 
 StringSumHelper (unsigned long long num)
 
 StringSumHelper (float num)
 
 StringSumHelper (double num)
 
void setString (const char *cstr, int length=-1)
 
void setString (flash_string_t pstr, int length=-1)
 
bool reserve (size_t size)
 Pre-allocate String memory. More...
 
bool setLength (size_t length)
 set the string length accordingly, expanding if necessary More...
 
size_t length (void) const
 Obtain the String length in characters, excluding NUL terminator. More...
 
 operator StringIfHelperType () const
 Provides safe bool() operator. 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...
 
bool endsWith (const String &suffix) const
 Compare the end of a String. More...
 
char charAt (size_t index) const
 Obtain the character at the given index. More...
 
void setCharAt (size_t index, char c)
 Sets the character at a given index. More...
 
size_t getBytes (unsigned char *buf, size_t bufsize, size_t index=0) const
 Read contents of a String into a buffer. More...
 
void toCharArray (char *buf, size_t bufsize, size_t index=0) const
 Read contents of String into a buffer. More...
 
const char * c_str () const
 Get a constant (un-modifiable) pointer to String content. More...
 
char * begin ()
 Get a modifiable pointer to String content. More...
 
const char * begin () const
 
char * end ()
 Get a modifiable pointer to one-past the end of the String. More...
 
const char * end () const
 
void toLowerCase (void)
 Convert the entire String content to lower case. More...
 
void toUpperCase (void)
 Convert the entire String content to upper case. More...
 
void trim (void)
 Remove all leading and trailing whitespace characters from the String. More...
 
long toInt (void) const
 
float toFloat (void) const
 
Concatenation methods
Return values
booltrue on success, false on failure

Works with built-in types. On failure, the string is left unchanged. If the argument is null or invalid, the concatenation is considered unsucessful.

bool concat (const String &str)
 
bool concat (const FlashString &fstr)
 
bool concat (const char *cstr)
 
bool concat (const char *cstr, size_t length)
 
bool concat (char c)
 
bool concat (unsigned char num)
 
bool concat (int num)
 
bool concat (unsigned int num)
 
bool concat (long num)
 
bool concat (long long num)
 
bool concat (unsigned long num)
 
bool concat (unsigned long long num)
 
bool concat (float num)
 
bool concat (double num)
 
Concatenation operators

If there's not enough memory for the concatenated value, the string will be left unchanged (but this isn't signalled in any way)

Stringoperator+= (const String &rhs)
 
Stringoperator+= (const FlashString &rhs)
 
Stringoperator+= (const char *cstr)
 
Stringoperator+= (char c)
 
Stringoperator+= (unsigned char num)
 
Stringoperator+= (int num)
 
Stringoperator+= (unsigned int num)
 
Stringoperator+= (long num)
 
Stringoperator+= (long long num)
 
Stringoperator+= (unsigned long num)
 
Stringoperator+= (unsigned long long num)
 
Stringoperator+= (float num)
 
Stringoperator+= (double num)
 
Comparison methods

Works with String and 'c' string

Return values
intReturns < 0 if String is lexically before the argument, > 0 if after or 0 if the same

Comparisons are case-sensitive, binary comparison null strings (including cstr == nullptr) are treated as empty.

int compareTo (const char *cstr, size_t length) const
 
int compareTo (const String &s) const
 
Test for equality

Compares content byte-for-byte using binary comparison

Return values
boolReturns true if strings are identical

null strings (including cstr == nullptr) are treated as empty.

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
 
Equality operator ==
Return values
booltrue if Strings are identical
bool operator== (const String &rhs) const
 
bool operator== (const char *cstr) const
 
bool operator== (const FlashString &fstr) const
 
In-equality operator !=
Return values
boolReturns true if strings are not identical
bool operator!= (const String &rhs) const
 
bool operator!= (const char *cstr) const
 
Comparison operators
bool operator< (const String &rhs) const
 
bool operator> (const String &rhs) const
 
bool operator<= (const String &rhs) const
 
bool operator>= (const String &rhs) const
 
Test for equality, without case-sensitivity
Return values
booltrue if strings are considered the same

null strings are treated as empty.

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
 
Array operators

If index is invalid, returns NUL \0

char operator[] (size_t index) const
 
char & operator[] (size_t index)
 
int indexOf(...)

Locate a character or String within another String.

Return values
intIndex if found, -1 if not found

By default, searches from the beginning of the String, but can also start from a given index, allowing for the locating of all instances of the character or String.

int indexOf (char ch, size_t fromIndex=0) const
 
int indexOf (const char *s2_buf, size_t fromIndex, size_t s2_len) const
 
int indexOf (const char *s2_buf, size_t fromIndex=0) const
 
int indexOf (const String &s2, size_t fromIndex=0) const
 
int lastIndexOf(...)

Locate a character or String within another String

Return values
intIndex if found, -1 if not found

By default, searches from the end of the String, but can also work backwards from a given index, allowing for the locating of all instances of the character or String.

int lastIndexOf (char ch) const
 
int lastIndexOf (char ch, size_t fromIndex) const
 
int lastIndexOf (const String &s2) const
 
int lastIndexOf (const String &s2, size_t fromIndex) const
 
int lastIndexOf (const char *s2_buf, size_t fromIndex, size_t s2_len) const
 
String substring(...)

Get a substring of a String.

Parameters
fromIndex of first character to retrieve
to(optional) One-past the ending character to retrieve

The starting index is inclusive (the corresponding character is included in the substring), but the optional ending index is exclusive (the corresponding character is not included in the substring).

If the ending index is omitted, the substring continues to the end of the String.

If you don't need the original String, consider using remove() instead:

    String original("This is the original string.");
    String sub = original.substring(0, 13);

This produces the same result:

    original.remove(13);
String substring (size_t from, size_t to) const
 
String substring (size_t from) const
 
replace(...)

Replace all instances of a given character or substring with another character or substring.

Return values
booltrue on success, false on allocation failure

Replacing a single character always succeeds as this is handled in-place.

Where replace is longer than find the String may need to be re-allocated, which could fail. If this happens the method returns false and the String is left unchanged.

void replace (char find, char replace)
 
bool replace (const String &find, const String &replace)
 
bool replace (const char *find_buf, size_t find_len, const char *replace_buf, size_t replace_len)
 
remove()

Remove characters from a String.

Parameters
indexIndex of the first character to remove
countNumber of characters to remove
Note
The String is modified in-situ without any reallocation

If no count is provided then all characters from the given index to the end of the String are removed.

void remove (size_t index)
 
void remove (size_t index, size_t count)
 

Static Public Attributes

static const String nullstr
 A null string evaluates to false. More...
 
static const String empty
 An empty string evaluates to true. More...
 
static constexpr size_t SSO_CAPACITY = STRING_OBJECT_SIZE - 2
 Max chars. (excluding NUL terminator) we can store in SSO mode. More...
 

Protected Member Functions

void invalidate (void)
 
bool isNull () const
 
char * buffer ()
 
const char * cbuffer () const
 
size_t capacity () const
 
void setlen (size_t len)
 
Stringcopy (const char *cstr, size_t length)
 
Stringcopy (flash_string_t pstr, size_t length)
 
void move (String &rhs)
 

Protected Attributes

union {
   PtrBuf   ptr
 
   SsoBuf   sso
 
}; 
 

Constructor & Destructor Documentation

◆ StringSumHelper() [1/12]

StringSumHelper::StringSumHelper ( const String s)
inline

◆ StringSumHelper() [2/12]

StringSumHelper::StringSumHelper ( const char *  p)
inline

◆ StringSumHelper() [3/12]

StringSumHelper::StringSumHelper ( char  c)
inline

◆ StringSumHelper() [4/12]

StringSumHelper::StringSumHelper ( unsigned char  num)
inline

◆ StringSumHelper() [5/12]

StringSumHelper::StringSumHelper ( int  num)
inline

◆ StringSumHelper() [6/12]

StringSumHelper::StringSumHelper ( unsigned int  num)
inline

◆ StringSumHelper() [7/12]

StringSumHelper::StringSumHelper ( long  num)
inline

◆ StringSumHelper() [8/12]

StringSumHelper::StringSumHelper ( long long  num)
inline

◆ StringSumHelper() [9/12]

StringSumHelper::StringSumHelper ( unsigned long  num)
inline

◆ StringSumHelper() [10/12]

StringSumHelper::StringSumHelper ( unsigned long long  num)
inline

◆ StringSumHelper() [11/12]

StringSumHelper::StringSumHelper ( float  num)
inline

◆ StringSumHelper() [12/12]

StringSumHelper::StringSumHelper ( double  num)
inline

Member Function Documentation

◆ begin() [1/2]

char* String::begin ( )
inlineinherited

Get a modifiable pointer to String content.

Note
If String is NUL, returns nullptr.

◆ begin() [2/2]

const char* String::begin ( ) const
inlineinherited

◆ buffer()

char* String::buffer ( )
inlineprotectedinherited

◆ c_str()

const char* String::c_str ( ) const
inlineinherited

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

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

◆ capacity()

size_t String::capacity ( ) const
inlineprotectedinherited

◆ cbuffer()

const char* String::cbuffer ( ) const
inlineprotectedinherited

◆ charAt()

char String::charAt ( size_t  index) const
inlineinherited

Obtain the character at the given index.

Parameters
index
Return values
char
Note
If index is invalid, returns NUL \0

◆ compareTo() [1/2]

int String::compareTo ( const char *  cstr,
size_t  length 
) const
inherited

◆ compareTo() [2/2]

int String::compareTo ( const String s) const
inlineinherited

◆ concat() [1/14]

bool String::concat ( const String str)
inlineinherited

◆ concat() [2/14]

bool String::concat ( const FlashString fstr)
inherited

◆ concat() [3/14]

bool String::concat ( const char *  cstr)
inherited

◆ concat() [4/14]

bool String::concat ( const char *  cstr,
size_t  length 
)
inherited

◆ concat() [5/14]

bool String::concat ( char  c)
inlineinherited

◆ concat() [6/14]

bool String::concat ( unsigned char  num)
inherited

◆ concat() [7/14]

bool String::concat ( int  num)
inherited

◆ concat() [8/14]

bool String::concat ( unsigned int  num)
inherited

◆ concat() [9/14]

bool String::concat ( long  num)
inherited

◆ concat() [10/14]

bool String::concat ( long long  num)
inherited

◆ concat() [11/14]

bool String::concat ( unsigned long  num)
inherited

◆ concat() [12/14]

bool String::concat ( unsigned long long  num)
inherited

◆ concat() [13/14]

bool String::concat ( float  num)
inherited

◆ concat() [14/14]

bool String::concat ( double  num)
inherited

◆ copy() [1/2]

String& String::copy ( const char *  cstr,
size_t  length 
)
protectedinherited

◆ copy() [2/2]

String& String::copy ( flash_string_t  pstr,
size_t  length 
)
protectedinherited

◆ end() [1/2]

char* String::end ( )
inlineinherited

Get a modifiable pointer to one-past the end of the String.

Note
Points to the terminating NUL character. If String is NUL, returns nullptr.

◆ end() [2/2]

const char* String::end ( ) const
inlineinherited

◆ endsWith()

bool String::endsWith ( const String suffix) const
inherited

Compare the end of a String.

Parameters
suffix
Return values
booltrue on match

◆ equals() [1/4]

bool String::equals ( const String s) const
inlineinherited

◆ equals() [2/4]

bool String::equals ( const char *  cstr) const
inherited

◆ equals() [3/4]

bool String::equals ( const char *  cstr,
size_t  length 
) const
inherited

◆ equals() [4/4]

bool String::equals ( const FlashString fstr) const
inlineinherited

◆ equalsIgnoreCase() [1/4]

bool String::equalsIgnoreCase ( const char *  cstr) const
inherited

◆ equalsIgnoreCase() [2/4]

bool String::equalsIgnoreCase ( const char *  cstr,
size_t  length 
) const
inherited

◆ equalsIgnoreCase() [3/4]

bool String::equalsIgnoreCase ( const String s2) const
inlineinherited

◆ equalsIgnoreCase() [4/4]

bool String::equalsIgnoreCase ( const FlashString fstr) const
inlineinherited

◆ getBytes()

size_t String::getBytes ( unsigned char *  buf,
size_t  bufsize,
size_t  index = 0 
) const
inherited

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

◆ indexOf() [1/4]

int String::indexOf ( char  ch,
size_t  fromIndex = 0 
) const
inherited

◆ indexOf() [2/4]

int String::indexOf ( const char *  s2_buf,
size_t  fromIndex,
size_t  s2_len 
) const
inherited

◆ indexOf() [3/4]

int String::indexOf ( const char *  s2_buf,
size_t  fromIndex = 0 
) const
inlineinherited

◆ indexOf() [4/4]

int String::indexOf ( const String s2,
size_t  fromIndex = 0 
) const
inlineinherited

◆ invalidate()

void String::invalidate ( void  )
protectedinherited

◆ isNull()

bool String::isNull ( ) const
inlineprotectedinherited

◆ lastIndexOf() [1/5]

int String::lastIndexOf ( char  ch) const
inherited

◆ lastIndexOf() [2/5]

int String::lastIndexOf ( char  ch,
size_t  fromIndex 
) const
inherited

◆ lastIndexOf() [3/5]

int String::lastIndexOf ( const String s2) const
inherited

◆ lastIndexOf() [4/5]

int String::lastIndexOf ( const String s2,
size_t  fromIndex 
) const
inherited

◆ lastIndexOf() [5/5]

int String::lastIndexOf ( const char *  s2_buf,
size_t  fromIndex,
size_t  s2_len 
) const
inherited

◆ length()

size_t String::length ( void  ) const
inlineinherited

Obtain the String length in characters, excluding NUL terminator.

◆ move()

void String::move ( String rhs)
protectedinherited

◆ operator StringIfHelperType()

String::operator StringIfHelperType ( ) const
inlineinherited

Provides safe bool() operator.

Evaluates as false if String is null, otherwise evaluates as true

◆ operator!=() [1/2]

bool String::operator!= ( const String rhs) const
inlineinherited

◆ operator!=() [2/2]

bool String::operator!= ( const char *  cstr) const
inlineinherited

◆ operator+=() [1/13]

String& String::operator+= ( const String rhs)
inlineinherited

◆ operator+=() [2/13]

String& String::operator+= ( const FlashString rhs)
inlineinherited

◆ operator+=() [3/13]

String& String::operator+= ( const char *  cstr)
inlineinherited

◆ operator+=() [4/13]

String& String::operator+= ( char  c)
inlineinherited

◆ operator+=() [5/13]

String& String::operator+= ( unsigned char  num)
inlineinherited

◆ operator+=() [6/13]

String& String::operator+= ( int  num)
inlineinherited

◆ operator+=() [7/13]

String& String::operator+= ( unsigned int  num)
inlineinherited

◆ operator+=() [8/13]

String& String::operator+= ( long  num)
inlineinherited

◆ operator+=() [9/13]

String& String::operator+= ( long long  num)
inlineinherited

◆ operator+=() [10/13]

String& String::operator+= ( unsigned long  num)
inlineinherited

◆ operator+=() [11/13]

String& String::operator+= ( unsigned long long  num)
inlineinherited

◆ operator+=() [12/13]

String& String::operator+= ( float  num)
inlineinherited

◆ operator+=() [13/13]

String& String::operator+= ( double  num)
inlineinherited

◆ operator<()

bool String::operator< ( const String rhs) const
inlineinherited

◆ operator<=()

bool String::operator<= ( const String rhs) const
inlineinherited

◆ operator==() [1/3]

bool String::operator== ( const String rhs) const
inlineinherited

◆ operator==() [2/3]

bool String::operator== ( const char *  cstr) const
inlineinherited

◆ operator==() [3/3]

bool String::operator== ( const FlashString fstr) const
inlineinherited

◆ operator>()

bool String::operator> ( const String rhs) const
inlineinherited

◆ operator>=()

bool String::operator>= ( const String rhs) const
inlineinherited

◆ operator[]() [1/2]

char String::operator[] ( size_t  index) const
inherited

◆ operator[]() [2/2]

char& String::operator[] ( size_t  index)
inherited

◆ remove() [1/2]

void String::remove ( size_t  index)
inlineinherited

◆ remove() [2/2]

void String::remove ( size_t  index,
size_t  count 
)
inherited

◆ replace() [1/3]

void String::replace ( char  find,
char  replace 
)
inherited

◆ replace() [2/3]

bool String::replace ( const String find,
const String replace 
)
inherited

◆ replace() [3/3]

bool String::replace ( const char *  find_buf,
size_t  find_len,
const char *  replace_buf,
size_t  replace_len 
)
inherited

◆ reserve()

bool String::reserve ( size_t  size)
inherited

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)

◆ setCharAt()

void String::setCharAt ( size_t  index,
char  c 
)
inherited

Sets the character at a given index.

Parameters
index
c
Note
If index is invalid, does nothing

◆ setlen()

void String::setlen ( size_t  len)
inlineprotectedinherited

◆ setLength()

bool String::setLength ( size_t  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

◆ setString() [1/2]

void String::setString ( const char *  cstr,
int  length = -1 
)
inherited

◆ setString() [2/2]

void String::setString ( flash_string_t  pstr,
int  length = -1 
)
inherited

◆ startsWith() [1/2]

bool String::startsWith ( const String prefix) const
inlineinherited

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 ( const String prefix,
size_t  offset 
) const
inherited

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

◆ substring() [1/2]

String String::substring ( size_t  from,
size_t  to 
) const
inherited

◆ substring() [2/2]

String String::substring ( size_t  from) const
inlineinherited

◆ toCharArray()

void String::toCharArray ( char *  buf,
size_t  bufsize,
size_t  index = 0 
) const
inlineinherited

Read contents of String into a buffer.

See also
See getBytes()

◆ toFloat()

float String::toFloat ( void  ) const
inherited

◆ toInt()

long String::toInt ( void  ) const
inherited

◆ toLowerCase()

void String::toLowerCase ( void  )
inherited

Convert the entire String content to lower case.

◆ toUpperCase()

void String::toUpperCase ( void  )
inherited

Convert the entire String content to upper case.

◆ trim()

void String::trim ( void  )
inherited

Remove all leading and trailing whitespace characters from the String.

Member Data Documentation

◆ @2

union { ... }

◆ empty

const String String::empty
staticinherited

An empty string evaluates to true.

◆ nullstr

const String String::nullstr
staticinherited

A null string evaluates to false.

◆ ptr

PtrBuf String::ptr
inherited

◆ sso

SsoBuf String::sso
inherited

◆ SSO_CAPACITY

constexpr size_t String::SSO_CAPACITY = STRING_OBJECT_SIZE - 2
staticinherited

Max chars. (excluding NUL terminator) we can store in SSO mode.


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