JsonParserGeneratorRK
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends
String Class Reference

Wiring String: A class to hold and manipulate a dynamically allocated string. More...

#include <spark_wiring_string.h>

Inheritance diagram for String:
StringSumHelper

Public Member Functions

 String (const char *cstr="")
 Construct a String object from a c-string (null-terminated) More...
 
 String (const char *cstr, unsigned int length)
 Construct a String object from a pointer and length. More...
 
 String (const String &str)
 Construct a String object as a copy of another string. More...
 
 String (const Printable &printable)
 Construct a String object from any Printable object. More...
 
 String (char c)
 Construct a String containing a single character. More...
 
 String (unsigned char b, unsigned char base=10)
 Construct a String from a unsigned char (uint8_t) value, expressed as a number. More...
 
 String (int value, unsigned char base=10)
 Construct a String from a int (32 bit signed integer) value, expressed as a number. More...
 
 String (unsigned int value, unsigned char base=10)
 Construct a String from a unsigned int (32 bit unsigned integer) value, expressed as a number. More...
 
 String (long value, unsigned char base=10)
 Construct a String from a long (32 bit signed integer) value, expressed as a number. More...
 
 String (unsigned long value, unsigned char base=10)
 Construct a String from a unsigned long (32 bit unsigned integer) value, expressed as a number. More...
 
 String (float value, int decimalPlaces=6)
 Construct a String from a float (32 bit single precision floating point) value, expressed as a number. More...
 
 String (double value, int decimalPlaces=6)
 Construct a String from a double (64 bit double precision floating point) value, expressed as a number. More...
 
 ~String (void)
 Destructor. Also deletes the underlying dynamically allocated string.
 
unsigned char reserve (unsigned int size)
 Reserves a buffer of size. More...
 
unsigned int length (void) const
 Returns the length of the string in bytes. More...
 
Stringoperator= (const String &rhs)
 Assigns this string to have a copy of String rhs. More...
 
Stringoperator= (const char *cstr)
 Assigns this string to have a copy of c-string (null-terminated) cstr. More...
 
 operator const char * () const
 Returns the contents this String as a c-string (null-terminated) More...
 
unsigned char concat (const String &str)
 Append (concatenate) a String object to the end of this String, modifying this string in place. More...
 
unsigned char concat (const char *cstr)
 Append (concatenate) a c-string (null-terminated) to the end of this String, modifying this string in place. More...
 
unsigned char concat (char c)
 Append (concatenate) a single character to the end of this String, modifying this string in place. More...
 
unsigned char concat (unsigned char c)
 Append (concatenate) the byte value c to the end of this String as a decimal number 0 - 255, modifying this string in place. More...
 
unsigned char concat (int num)
 Append (concatenate) the integer value num to the end of this String as a signed decimal number (base 10), modifying this string in place. More...
 
unsigned char concat (unsigned int num)
 Append (concatenate) the unsigned integer value num to the end of this String as a unsigned decimal number (base 10), modifying this string in place. More...
 
unsigned char concat (long num)
 Append (concatenate) the long integer value num to the end of this String as a signed decimal number (base 10), modifying this string in place. More...
 
unsigned char concat (unsigned long num)
 Append (concatenate) the unsigned long value num to the end of this String as a unsigned decimal number (base 10), modifying this string in place. More...
 
unsigned char concat (float num)
 Append (concatenate) the float n to the end of this String as a decimal number (base 10), modifying this string in place. More...
 
unsigned char concat (double num)
 Append (concatenate) the double precision float n to the end of this String as a decimal number (base 10), modifying this string in place. More...
 
Stringoperator+= (const String &rhs)
 Appends (concatenate) a String object to the end of this String, modifying this string in place. More...
 
Stringoperator+= (const char *cstr)
 Appends (concatenate) a c-string (null-terminated) to the end of this String, modifying this string in place. More...
 
Stringoperator+= (char c)
 Appends (concatenate) a single character to the end of this String, modifying this string in place. More...
 
Stringoperator+= (unsigned char num)
 Append (concatenate) the byte value num to the end of this String as a decimal number 0 - 255, modifying this string in place. More...
 
Stringoperator+= (int num)
 Append (concatenate) the integer value num to the end of this String as a signed decimal number (base 10), modifying this string in place. More...
 
Stringoperator+= (unsigned int num)
 Append (concatenate) the unsigned integer value num to the end of this String as a unsigned decimal number (base 10), modifying this string in place. More...
 
Stringoperator+= (long num)
 Append (concatenate) the long integer value num to the end of this String as a signed decimal number (base 10), modifying this string in place. More...
 
Stringoperator+= (unsigned long num)
 Append (concatenate) the unsigned long value num to the end of this String as a unsigned decimal number (base 10), modifying this string in place. More...
 
int compareTo (const String &s) const
 Compares this string to another string using strcmp (case-sensitive) More...
 
unsigned char equals (const String &s) const
 Returns true if this string is equal to another string (case-sensitive) More...
 
unsigned char equals (const char *cstr) const
 Returns true if this string equal to another string (case-sensitive) More...
 
unsigned char operator== (const String &rhs) const
 Returns true if this string is equal to another string (case-sensitive) More...
 
unsigned char operator== (const char *cstr) const
 Returns true if this string equal to another string (case-sensitive) More...
 
unsigned char operator!= (const String &rhs) const
 Returns true if this string is greater than to another string (case-sensitive) More...
 
unsigned char operator!= (const char *cstr) const
 Returns true if this string not equal to another string (case-sensitive) More...
 
unsigned char operator< (const String &rhs) const
 Returns true if this string is less than to another string (case-sensitive) More...
 
unsigned char operator> (const String &rhs) const
 Returns true if this string is greater than to another string (case-sensitive) More...
 
unsigned char operator<= (const String &rhs) const
 Returns true if this string is less than or equal to another string (case-sensitive) More...
 
unsigned char operator>= (const String &rhs) const
 Returns true if this string is greater than or equal to another string (case-sensitive) More...
 
unsigned char equalsIgnoreCase (const String &s) const
 Returns true if this string equals another string (case-insensitive) More...
 
unsigned char startsWith (const String &prefix) const
 Returns true if this string starts with prefix (case-sensitive) More...
 
unsigned char startsWith (const String &prefix, unsigned int offset) const
 Returns true if this string contains prefix at specified offset (case-sensitive) More...
 
unsigned char endsWith (const String &suffix) const
 Returns true if this string ends with suffix (case-sensitive) More...
 
char charAt (unsigned int index) const
 Gets the character at offset index. More...
 
void setCharAt (unsigned int index, char c)
 Set the character at offset index. More...
 
char operator[] (unsigned int index) const
 Gets the character at offset index. More...
 
char & operator[] (unsigned int index)
 Set the character at offset index. More...
 
void getBytes (unsigned char *buf, unsigned int bufsize, unsigned int index=0) const
 Copy the data out of this String into another buffer. More...
 
void toCharArray (char *buf, unsigned int bufsize, unsigned int index=0) const
 Copy the data out of this String into another buffer. More...
 
const char * c_str () const
 Returns a c-string (null-terminated) More...
 
int indexOf (char ch) const
 Search this string for a given character. More...
 
int indexOf (char ch, unsigned int fromIndex) const
 Search this string for a given character starting at an offset. More...
 
int indexOf (const String &str) const
 Search this string for a given String. More...
 
int indexOf (const String &str, unsigned int fromIndex) const
 Search this string for a given String starting at an offset. More...
 
int lastIndexOf (char ch) const
 Search this string for a given character, starting at the end. More...
 
int lastIndexOf (char ch, unsigned int fromIndex) const
 Search this string for a given character, starting at the fromIndex and going toward the beginning. More...
 
int lastIndexOf (const String &str) const
 Search this string for a last occurrence of str. More...
 
int lastIndexOf (const String &str, unsigned int fromIndex) const
 Search this string for a last occurrence of str starting at fromIndex. More...
 
String substring (unsigned int beginIndex) const
 Returns a String object with a copy of the characters starting at beginIndex through the end of the string. More...
 
String substring (unsigned int beginIndex, unsigned int endIndex) const
 Returns a String object with a copy of the characters in the specified range. More...
 
Stringreplace (char find, char replace)
 Replaces every occurrence of a character in the string with another character, modifying it in place. More...
 
Stringreplace (const String &find, const String &replace)
 Replaces every occurrence of a String with another String, modifying it in place. More...
 
Stringremove (unsigned int index)
 Removes characters from the String, modifying it in place. More...
 
Stringremove (unsigned int index, unsigned int count)
 Removes characters from the String, modifying it in place. More...
 
StringtoLowerCase (void)
 Converts this String to lower case, modifying it in place. More...
 
StringtoUpperCase (void)
 Converts this String to upper case, modifying it in place. More...
 
Stringtrim (void)
 Removes leading an trailing white spaces from this string, modifying it in place. More...
 
long toInt (void) const
 Converts this string to a signed integer (32-bit) More...
 
float toFloat (void) const
 Converts this string to a float (single precision floating point value) More...
 

Static Public Member Functions

static String format (const char *format,...)
 Uses sprintf-style formatting to build a String object [static]. More...
 

Protected Attributes

char * buffer
 The buffer containing the data. It is always null-terminated.
 
unsigned int capacity
 The capacity of the buffer. The longest string is one byte less than this.
 
unsigned int len
 The String length (not counting the null terminator).
 
unsigned char flags
 Unused, for future features.
 

Friends

class StringPrintableHelper
 
StringSumHelperoperator+ (const StringSumHelper &lhs, const String &rhs)
 Append (concatenate) a String to the end of lhs. More...
 
StringSumHelperoperator+ (const StringSumHelper &lhs, const char *cstr)
 Append (concatenate) a c-string (null-terminated) to the end of lhs. More...
 
StringSumHelperoperator+ (const StringSumHelper &lhs, char c)
 Append (concatenate) the character c the end of lhs a. More...
 
StringSumHelperoperator+ (const StringSumHelper &lhs, unsigned char num)
 Append (concatenate) the unsigned char num to the end of lhs as a decimal number (base 10) More...
 
StringSumHelperoperator+ (const StringSumHelper &lhs, int num)
 Append (concatenate) the signed int num to the end of lhs as a decimal number (base 10) More...
 
StringSumHelperoperator+ (const StringSumHelper &lhs, unsigned int num)
 Append (concatenate) the unsigned int num to the end of lhs as a decimal number (base 10) More...
 
StringSumHelperoperator+ (const StringSumHelper &lhs, long num)
 Append (concatenate) the long integer num to the end of lhs as a decimal number (base 10) More...
 
StringSumHelperoperator+ (const StringSumHelper &lhs, unsigned long num)
 Append (concatenate) the unsigned long integer to the end of lhs as a decimal number (base 10) More...
 
StringSumHelperoperator+ (const StringSumHelper &lhs, float num)
 Append (concatenate) the float num to the end of lhs as a decimal number (base 10) More...
 
StringSumHelperoperator+ (const StringSumHelper &lhs, double num)
 Append (concatenate) the double precision float num to the end of lhs as a decimal number (base 10) More...
 

Detailed Description

Wiring String: A class to hold and manipulate a dynamically allocated string.

Constructor & Destructor Documentation

◆ String() [1/12]

String::String ( const char *  cstr = "")

Construct a String object from a c-string (null-terminated)

Parameters
cstrThe string to copy, optional. If not specified, starts with an empty string

◆ String() [2/12]

String::String ( const char *  cstr,
unsigned int  length 
)

Construct a String object from a pointer and length.

Parameters
cstrPointer to a bytes, typically ASCII or UTF-8. Does not need to be null-terminated.
lengthLength in bytes of the string.

◆ String() [3/12]

String::String ( const String str)

Construct a String object as a copy of another string.

Parameters
strThe string to copy. Changes made to str in the future won't be reflected in this copy.

◆ String() [4/12]

String::String ( const Printable printable)

Construct a String object from any Printable object.

Parameters
printableThe Printable object. The toPrint() method will be called on it to print to this String the textual representation of the object.

For example, IPAddress is printable, so you can pass an IPAddress to this constructor and this string will contain a textual representation of the IPAddress (dotted quad).

◆ String() [5/12]

String::String ( char  c)
explicit

Construct a String containing a single character.

Parameters
cThe character to set the String to

◆ String() [6/12]

String::String ( unsigned char  b,
unsigned char  base = 10 
)
explicit

Construct a String from a unsigned char (uint8_t) value, expressed as a number.

Parameters
bThe value.
baseThe number base, default is 10 (decimal). Other values include 8 (octal) and 16 (hexadecimal).

◆ String() [7/12]

String::String ( int  value,
unsigned char  base = 10 
)
explicit

Construct a String from a int (32 bit signed integer) value, expressed as a number.

Parameters
valueThe value.
baseThe number base, default is 10 (decimal). Other values include 8 (octal) and 16 (hexadecimal).

◆ String() [8/12]

String::String ( unsigned int  value,
unsigned char  base = 10 
)
explicit

Construct a String from a unsigned int (32 bit unsigned integer) value, expressed as a number.

Parameters
valueThe value.
baseThe number base, default is 10 (decimal). Other values include 8 (octal) and 16 (hexadecimal).

◆ String() [9/12]

String::String ( long  value,
unsigned char  base = 10 
)
explicit

Construct a String from a long (32 bit signed integer) value, expressed as a number.

Parameters
valueThe value.
baseThe number base, default is 10 (decimal). Other values include 8 (octal) and 16 (hexadecimal).

◆ String() [10/12]

String::String ( unsigned long  value,
unsigned char  base = 10 
)
explicit

Construct a String from a unsigned long (32 bit unsigned integer) value, expressed as a number.

Parameters
valueThe value.
baseThe number base, default is 10 (decimal). Other values include 8 (octal) and 16 (hexadecimal).

◆ String() [11/12]

String::String ( float  value,
int  decimalPlaces = 6 
)
explicit

Construct a String from a float (32 bit single precision floating point) value, expressed as a number.

Parameters
valueThe value.
decimalPlacesThe number of decimal places to show. Default = 6.

◆ String() [12/12]

String::String ( double  value,
int  decimalPlaces = 6 
)
explicit

Construct a String from a double (64 bit double precision floating point) value, expressed as a number.

Parameters
valueThe value.
decimalPlacesThe number of decimal places to show. Default = 6.

Member Function Documentation

◆ c_str()

const char* String::c_str ( ) const
inline

Returns a c-string (null-terminated)

This allows the String object to be passed to anything that requires a c-string. See also operator const char *.

One place where you need to explicitly use c_str() or cast is when passing a String as a variable argument to sprintf:

String str;
snprintf(buf, sizeof(buf), "string=%s", str.c_str());

If you leave off the c_str() the value won't be printed as string. This also applies to things that use sprintf internally, like Log:

Log.info("string=%s", str.c_str());

This method returns a pointer to the internal buffer. If the underlying string is reallocated because the string is appended to, this pointer will be invalid.

◆ charAt()

char String::charAt ( unsigned int  index) const

Gets the character at offset index.

Parameters
indexThe index to set (0 = first character)
Returns
The character is 0 if the index is larger than the length of the string.

◆ compareTo()

int String::compareTo ( const String s) const

Compares this string to another string using strcmp (case-sensitive)

Parameters
sthe string to compare to
Returns
< 0 if s is less than this, == 0 is s equals this, or > 0 if s is greater than this

Uses the C standard library function strcmp which is case-sensitive and does not correctly compare UTF-8 characters.

◆ concat() [1/10]

unsigned char String::concat ( const String str)

Append (concatenate) a String object to the end of this String, modifying this string in place.

Parameters
strThe string to copy from. It is not modified.
Returns
true if the append succeeded or false if there was not enough memory or the parameter was invalid.

◆ concat() [2/10]

unsigned char String::concat ( const char *  cstr)

Append (concatenate) a c-string (null-terminated) to the end of this String, modifying this string in place.

Parameters
cstrThe string to copy from. It is not modified.
Returns
true if the append succeeded or false if there was not enough memory or the parameter was invalid.

◆ concat() [3/10]

unsigned char String::concat ( char  c)

Append (concatenate) a single character to the end of this String, modifying this string in place.

Parameters
cThe character to append.
Returns
true if the append succeeded or false if there was not enough memory.

◆ concat() [4/10]

unsigned char String::concat ( unsigned char  c)

Append (concatenate) the byte value c to the end of this String as a decimal number 0 - 255, modifying this string in place.

Parameters
cThe value to append.
Returns
true if the append succeeded or false if there was not enough memory.

◆ concat() [5/10]

unsigned char String::concat ( int  num)

Append (concatenate) the integer value num to the end of this String as a signed decimal number (base 10), modifying this string in place.

Parameters
numThe value to append.
Returns
true if the append succeeded or false if there was not enough memory.

◆ concat() [6/10]

unsigned char String::concat ( unsigned int  num)

Append (concatenate) the unsigned integer value num to the end of this String as a unsigned decimal number (base 10), modifying this string in place.

Parameters
numThe value to append.
Returns
true if the append succeeded or false if there was not enough memory.

◆ concat() [7/10]

unsigned char String::concat ( long  num)

Append (concatenate) the long integer value num to the end of this String as a signed decimal number (base 10), modifying this string in place.

Parameters
numThe value to append.
Returns
true if the append succeeded or false if there was not enough memory.

◆ concat() [8/10]

unsigned char String::concat ( unsigned long  num)

Append (concatenate) the unsigned long value num to the end of this String as a unsigned decimal number (base 10), modifying this string in place.

Parameters
numThe value to append.
Returns
true if the append succeeded or false if there was not enough memory.

◆ concat() [9/10]

unsigned char String::concat ( float  num)

Append (concatenate) the float n to the end of this String as a decimal number (base 10), modifying this string in place.

Parameters
numThe value to append.
Returns
true if the append succeeded or false if there was not enough memory.

◆ concat() [10/10]

unsigned char String::concat ( double  num)

Append (concatenate) the double precision float n to the end of this String as a decimal number (base 10), modifying this string in place.

Parameters
numThe value to append.
Returns
true if the append succeeded or false if there was not enough memory.

◆ endsWith()

unsigned char String::endsWith ( const String suffix) const

Returns true if this string ends with suffix (case-sensitive)

Parameters
suffixthe string containing the suffix to test

Uses the C standard library function strcmp which is case-sensitive and may not work properly with UTF-8 characters.

◆ equals() [1/2]

unsigned char String::equals ( const String s) const

Returns true if this string is equal to another string (case-sensitive)

Parameters
sthe string to compare to
Returns
true if the other string is equal to this string.

Uses the C standard library function strcmp which is case-sensitive and does not correctly compare UTF-8 characters.

◆ equals() [2/2]

unsigned char String::equals ( const char *  cstr) const

Returns true if this string equal to another string (case-sensitive)

Parameters
cstrthe c-string (null-terminated) to compare to
Returns
true if the other string is equal to this string.

Uses the C standard library function strcmp which is case-sensitive and does not correctly compare UTF-8 characters.

◆ equalsIgnoreCase()

unsigned char String::equalsIgnoreCase ( const String s) const

Returns true if this string equals another string (case-insensitive)

Parameters
sthe string to compare to
Returns
true if equal, false if not

Uses the C standard library function strcmp which is case-sensitive and does not correctly compare UTF-8 characters.

◆ format()

static String String::format ( const char *  format,
  ... 
)
static

Uses sprintf-style formatting to build a String object [static].

Parameters
formatThe formatting string
...Variable arguments corresponding to the formatting string
Returns
Returns a String object formatted as specified

◆ getBytes()

void String::getBytes ( unsigned char *  buf,
unsigned int  bufsize,
unsigned int  index = 0 
) const

Copy the data out of this String into another buffer.

Parameters
bufThe buffer to copy into
bufsizeThe size of the buffer. The buffer will contain a null-terminted string so the maximum string length is bufsize - 1.
indexThe index to start copying from (0 = first character). Optional. Default is from 0, the start of the string.

If bufsize is smaller than the string the string will be truncated and still null-terminated. If the string is truncated and UTF-8, it may break a multi-byte character sequence in the middle, resulting in invalid UTF-8.

◆ indexOf() [1/4]

int String::indexOf ( char  ch) const

Search this string for a given character.

Parameters
chThe ASCII character to search for
Returns
index of the character or -1 if not found. 0 = the first character.

This uses the C standard library function strchr and is only compatible with ASCII characters. It can return invalid results for UTF-8 strings.

◆ indexOf() [2/4]

int String::indexOf ( char  ch,
unsigned int  fromIndex 
) const

Search this string for a given character starting at an offset.

Parameters
chThe ASCII character to t search for
fromIndexThe index to start from (0 = first character)
Returns
index of the character or -1 if not found. 0 = the first character.

This uses the C standard library function strchr and is only compatible with ASCII characters. It can return invalid results for UTF-8 strings.

◆ indexOf() [3/4]

int String::indexOf ( const String str) const

Search this string for a given String.

Parameters
strThe string to search for
Returns
index of the string or -1 if not found. 0 = the first character.

This uses the C standard library function strstr and is only compatible with ASCII characters. It can return invalid results for UTF-8 strings. It is case-sensitive.

◆ indexOf() [4/4]

int String::indexOf ( const String str,
unsigned int  fromIndex 
) const

Search this string for a given String starting at an offset.

Parameters
strThe string to search for
fromIndexThe index to start from (0 = first character)
Returns
index of the string or -1 if not found. 0 = the first character.

This uses the C standard library function strstr and is only compatible with ASCII characters. It can return invalid results for UTF-8 strings. It is case-sensitive.

◆ lastIndexOf() [1/4]

int String::lastIndexOf ( char  ch) const

Search this string for a given character, starting at the end.

Parameters
chThe ASCII character to search for
Returns
index of the character or -1 if not found. 0 = the first character.

This uses the C standard library function strrchr and is only compatible with ASCII characters. It can return invalid results for UTF-8 strings.

◆ lastIndexOf() [2/4]

int String::lastIndexOf ( char  ch,
unsigned int  fromIndex 
) const

Search this string for a given character, starting at the fromIndex and going toward the beginning.

Parameters
chThe ASCII character to search for
fromIndexThe index to start from (0 = first character)
Returns
index of the character or -1 if not found. 0 = the first character.

This uses the C standard library function strrchr and is only compatible with ASCII characters. It can return invalid results for UTF-8 strings.

◆ lastIndexOf() [3/4]

int String::lastIndexOf ( const String str) const

Search this string for a last occurrence of str.

Parameters
strThe string to search for
Returns
index of the start of the string or -1 if not found. 0 = the first character.

This uses the C standard library function strstr and is only compatible with ASCII characters. It can return invalid results for UTF-8 strings. It is case-sensitive.

◆ lastIndexOf() [4/4]

int String::lastIndexOf ( const String str,
unsigned int  fromIndex 
) const

Search this string for a last occurrence of str starting at fromIndex.

Parameters
strThe string to search for
fromIndexThe index to start from (0 = first character)
Returns
index of the start of the string or -1 if not found. 0 = the first character.

This uses the C standard library function strstr and is only compatible with ASCII characters. It can return invalid results for UTF-8 strings. It is case-sensitive.

◆ length()

unsigned int String::length ( void  ) const
inline

Returns the length of the string in bytes.

Note that for UTF-8 strings, this is the number of bytes, not characters.

◆ operator const char *()

String::operator const char * ( ) const
inline

Returns the contents this String as a c-string (null-terminated)

See also c_str() which is another way to do this.

◆ operator!=() [1/2]

unsigned char String::operator!= ( const String rhs) const
inline

Returns true if this string is greater than to another string (case-sensitive)

Parameters
rhsthe string to compare to
Returns
true if the other string is greater than this string.

Uses the C standard library function strcmp which is case-sensitive and does not correctly compare UTF-8 characters.

◆ operator!=() [2/2]

unsigned char String::operator!= ( const char *  cstr) const
inline

Returns true if this string not equal to another string (case-sensitive)

Parameters
cstrthe c-string (null-terminated) to compare to
Returns
true if the other string is not equal to this string.

Uses the C standard library function strcmp which is case-sensitive and does not correctly compare UTF-8 characters.

◆ operator+=() [1/8]

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

Appends (concatenate) a String object to the end of this String, modifying this string in place.

Parameters
rhsThe string to copy from. It is not modified.
Returns
This string to you can chain operations together. If there was not enough memory or other error occurs, this String will be left unmodified.

◆ operator+=() [2/8]

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

Appends (concatenate) a c-string (null-terminated) to the end of this String, modifying this string in place.

Parameters
cstrThe string to copy from. It is not modified.
Returns
This string to you can chain operations together. If there was not enough memory or other error occurs, this String will be left unmodified.

◆ operator+=() [3/8]

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

Appends (concatenate) a single character to the end of this String, modifying this string in place.

Parameters
cThe character to append.
Returns
This string to you can chain operations together. If there was not enough memory or other error occurs, this String will be left unmodified.

◆ operator+=() [4/8]

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

Append (concatenate) the byte value num to the end of this String as a decimal number 0 - 255, modifying this string in place.

Parameters
numThe value to append.
Returns
This string to you can chain operations together. If there was not enough memory or other error occurs, this String will be left unmodified.

◆ operator+=() [5/8]

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

Append (concatenate) the integer value num to the end of this String as a signed decimal number (base 10), modifying this string in place.

Parameters
numThe value to append.
Returns
This string to you can chain operations together. If there was not enough memory or other error occurs, this String will be left unmodified.

◆ operator+=() [6/8]

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

Append (concatenate) the unsigned integer value num to the end of this String as a unsigned decimal number (base 10), modifying this string in place.

Parameters
numThe value to append.
Returns
This string to you can chain operations together. If there was not enough memory or other error occurs, this String will be left unmodified.

◆ operator+=() [7/8]

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

Append (concatenate) the long integer value num to the end of this String as a signed decimal number (base 10), modifying this string in place.

Parameters
numThe value to append.
Returns
This string to you can chain operations together. If there was not enough memory or other error occurs, this String will be left unmodified.

◆ operator+=() [8/8]

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

Append (concatenate) the unsigned long value num to the end of this String as a unsigned decimal number (base 10), modifying this string in place.

Parameters
numThe value to append.
Returns
This string to you can chain operations together. If there was not enough memory or other error occurs, this String will be left unmodified.

◆ operator<()

unsigned char String::operator< ( const String rhs) const

Returns true if this string is less than to another string (case-sensitive)

Parameters
rhsthe string to compare to
Returns
true if the other string is less than this string.

Uses the C standard library function strcmp which is case-sensitive and does not correctly compare UTF-8 characters.

◆ operator<=()

unsigned char String::operator<= ( const String rhs) const

Returns true if this string is less than or equal to another string (case-sensitive)

Parameters
rhsthe string to compare to
Returns
true if the other string is less than or equal to this string.

Uses the C standard library function strcmp which is case-sensitive and does not correctly compare UTF-8 characters.

◆ operator=() [1/2]

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

Assigns this string to have a copy of String rhs.

Parameters
rhsThe string to copy from.

◆ operator=() [2/2]

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

Assigns this string to have a copy of c-string (null-terminated) cstr.

Parameters
cstrThe string to copy from.

◆ operator==() [1/2]

unsigned char String::operator== ( const String rhs) const
inline

Returns true if this string is equal to another string (case-sensitive)

Parameters
rhsthe string to compare to
Returns
true if the other string is equal to this string.

Uses the C standard library function strcmp which is case-sensitive and does not correctly compare UTF-8 characters.

◆ operator==() [2/2]

unsigned char String::operator== ( const char *  cstr) const
inline

Returns true if this string equal to another string (case-sensitive)

Parameters
cstrthe c-string (null-terminated) to compare to
Returns
true if the other string is equal to this string.

Uses the C standard library function strcmp which is case-sensitive and does not correctly compare UTF-8 characters.

◆ operator>()

unsigned char String::operator> ( const String rhs) const

Returns true if this string is greater than to another string (case-sensitive)

Parameters
rhsthe string to compare to
Returns
true if the other string is greater than this string.

Uses the C standard library function strcmp which is case-sensitive and does not correctly compare UTF-8 characters.

◆ operator>=()

unsigned char String::operator>= ( const String rhs) const

Returns true if this string is greater than or equal to another string (case-sensitive)

Parameters
rhsthe string to compare to
Returns
true if the other string is greater than or equal to this string.

Uses the C standard library function strcmp which is case-sensitive and does not correctly compare UTF-8 characters.

◆ operator[]() [1/2]

char String::operator[] ( unsigned int  index) const

Gets the character at offset index.

Parameters
indexThe index to set (0 = first character)
Returns
The character is 0 if the index is larger than the length of the string.

◆ operator[]() [2/2]

char& String::operator[] ( unsigned int  index)

Set the character at offset index.

Parameters
indexThe index to set (0 = first character)
Returns
A reference to set.

If index is greater than the length of the string, a dummy reference is returned instead. This allows operation to execute without error, but also discards the change. In other words, you cannot use this to append to the string, only modify an existing character.

◆ remove() [1/2]

String& String::remove ( unsigned int  index)

Removes characters from the String, modifying it in place.

Parameters
indexIndex to start removing from, inclusive. 0 = first character of the string through the end of the string.
Returns
this String, so you can chain multiple operations

◆ remove() [2/2]

String& String::remove ( unsigned int  index,
unsigned int  count 
)

Removes characters from the String, modifying it in place.

Parameters
indexIndex to start removing from, inclusive. 0 = first character of the string.
countNumber of characters to remove. Typically 1 (remove one character) or more. Removes to the end of the string if count is larger than the size of the string.
Returns
this String, so you can chain multiple operations

◆ replace() [1/2]

String& String::replace ( char  find,
char  replace 
)

Replaces every occurrence of a character in the string with another character, modifying it in place.

Parameters
findthe character to look for
replacethe character to replace it with
Returns
this String, so you can chain multiple operations

◆ replace() [2/2]

String& String::replace ( const String find,
const String replace 
)

Replaces every occurrence of a String with another String, modifying it in place.

Parameters
findthe string to look for (case-sensitive)
replacethe string to replace it with
Returns
this String, so you can chain multiple operations

◆ reserve()

unsigned char String::reserve ( unsigned int  size)

Reserves a buffer of size.

This can improve the efficiency if you know approximately how big your string will be. Otherwise, the string is made larger in increments, which is much less efficient.

If, for example you reserve 100 bytes in a new empty string, the length will still be 0 until you append characters to it. It just will be able to append 100 bytes until it has to expand the internal dynamically allocated buffer.

◆ setCharAt()

void String::setCharAt ( unsigned int  index,
char  c 
)

Set the character at offset index.

Parameters
indexThe index to set (0 = first character)
cThe value to set the character to.

If index is greater than the length of the string, nothing is done. In other words, you cannot use this to append to the string, only modify an existing character.

◆ startsWith() [1/2]

unsigned char String::startsWith ( const String prefix) const

Returns true if this string starts with prefix (case-sensitive)

Parameters
prefixthe string containing the string to test against

Uses the C standard library function strcmp which is case-sensitive and may not work properly with UTF-8 characters.

◆ startsWith() [2/2]

unsigned char String::startsWith ( const String prefix,
unsigned int  offset 
) const

Returns true if this string contains prefix at specified offset (case-sensitive)

Parameters
prefixthe string containing the string to test against
offsetthe offset to check at (0 = first characters)

Uses the C standard library function strcmp which is case-sensitive and may not work properly with UTF-8 characters.

◆ substring() [1/2]

String String::substring ( unsigned int  beginIndex) const

Returns a String object with a copy of the characters starting at beginIndex through the end of the string.

Parameters
beginIndexThe index to start copying from, inclusive (0 = first byte, 1 = second byte, ...)
Returns
A copy of the specified substring

Note: If the String contains UTF-8 characters, beginIndex and endIndex are in bytes, not characters! It does not prevent splitting a UTF-8 multi-byte sequence.

◆ substring() [2/2]

String String::substring ( unsigned int  beginIndex,
unsigned int  endIndex 
) const

Returns a String object with a copy of the characters in the specified range.

Parameters
beginIndexThe index to start copying from, inclusive (0 = first byte, 1 = second byte, ...)
endIndexThe index to stop at, exclusive. The last character copied is the one before this one.
Returns
A copy of the specified substring

Note: If the String contains UTF-8 characters, beginIndex and endIndex are in bytes, not characters! It does not prevent splitting a UTF-8 multi-byte sequence.

◆ toCharArray()

void String::toCharArray ( char *  buf,
unsigned int  bufsize,
unsigned int  index = 0 
) const
inline

Copy the data out of this String into another buffer.

Parameters
bufThe buffer to copy into
bufsizeThe size of the buffer. The buffer will contain a null-terminted string so the maximum string length is bufsize - 1.
indexThe index to start copying from (0 = first character). Optional. Default is from 0, the start of the string.

If bufsize is smaller than the string the string will be truncated and still null-terminated. If the string is truncated and UTF-8, it may break a multi-byte character sequence in the middle, resulting in invalid UTF-8.

◆ toFloat()

float String::toFloat ( void  ) const

Converts this string to a float (single precision floating point value)

Returns
a float value or 0.0 if a parsing error occurs (not a float).

◆ toInt()

long String::toInt ( void  ) const

Converts this string to a signed integer (32-bit)

Returns
An integer value or 0 if a parsing error occurs (not an integer).

◆ toLowerCase()

String& String::toLowerCase ( void  )

Converts this String to lower case, modifying it in place.

Returns
this String, so you can chain multiple operations

This is done using the C standard library function tolower() on each character. It only works with 7-bit ASCII characters and will corrupt UTF-8 data.

◆ toUpperCase()

String& String::toUpperCase ( void  )

Converts this String to upper case, modifying it in place.

Returns
this String, so you can chain multiple operations

This is done using the C standard library function toupper() on each character. It only works with 7-bit ASCII characters and will corrupt UTF-8 data.

◆ trim()

String& String::trim ( void  )

Removes leading an trailing white spaces from this string, modifying it in place.

Returns
this String, so you can chain multiple operations

Whitespace is determined by the C standard library function isspace().

Friends And Related Function Documentation

◆ operator+ [1/10]

StringSumHelper& operator+ ( const StringSumHelper lhs,
const String rhs 
)
friend

Append (concatenate) a String to the end of lhs.

Parameters
lhsThe string to append to. String lhs is not modified.
rhsThe value to append.
Returns
the combined string

◆ operator+ [2/10]

StringSumHelper& operator+ ( const StringSumHelper lhs,
const char *  cstr 
)
friend

Append (concatenate) a c-string (null-terminated) to the end of lhs.

Parameters
lhsThe string to append to. String lhs is not modified.
cstrThe value to append.
Returns
the combined string

◆ operator+ [3/10]

StringSumHelper& operator+ ( const StringSumHelper lhs,
char  c 
)
friend

Append (concatenate) the character c the end of lhs a.

Parameters
lhsThe string to append to. String lhs is not modified.
cThe character to append
Returns
the combined string

◆ operator+ [4/10]

StringSumHelper& operator+ ( const StringSumHelper lhs,
unsigned char  num 
)
friend

Append (concatenate) the unsigned char num to the end of lhs as a decimal number (base 10)

Parameters
lhsThe string to append to. String lhs is not modified.
numThe value to append.
Returns
the combined string

◆ operator+ [5/10]

StringSumHelper& operator+ ( const StringSumHelper lhs,
int  num 
)
friend

Append (concatenate) the signed int num to the end of lhs as a decimal number (base 10)

Parameters
lhsThe string to append to. String lhs is not modified.
numThe value to append.
Returns
the combined string

◆ operator+ [6/10]

StringSumHelper& operator+ ( const StringSumHelper lhs,
unsigned int  num 
)
friend

Append (concatenate) the unsigned int num to the end of lhs as a decimal number (base 10)

Parameters
lhsThe string to append to. String lhs is not modified.
numThe value to append.
Returns
the combined string

◆ operator+ [7/10]

StringSumHelper& operator+ ( const StringSumHelper lhs,
long  num 
)
friend

Append (concatenate) the long integer num to the end of lhs as a decimal number (base 10)

Parameters
lhsThe string to append to. String lhs is not modified.
numThe value to append.
Returns
the combined string

◆ operator+ [8/10]

StringSumHelper& operator+ ( const StringSumHelper lhs,
unsigned long  num 
)
friend

Append (concatenate) the unsigned long integer to the end of lhs as a decimal number (base 10)

Parameters
lhsThe string to append to. String lhs is not modified.
numThe value to append.
Returns
the combined string

◆ operator+ [9/10]

StringSumHelper& operator+ ( const StringSumHelper lhs,
float  num 
)
friend

Append (concatenate) the float num to the end of lhs as a decimal number (base 10)

Parameters
lhsThe string to append to. String lhs is not modified.
numThe value to append.
Returns
the combined string

◆ operator+ [10/10]

StringSumHelper& operator+ ( const StringSumHelper lhs,
double  num 
)
friend

Append (concatenate) the double precision float num to the end of lhs as a decimal number (base 10)

Parameters
lhsThe string to append to. String lhs is not modified.
numThe value to append.
Returns
the combined string

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