SafeString
4.1.27
SafeString is a safe, robust and debuggable replacement for string processing in Arduino
|
To create SafeStrings use one of the four (4) macros createSafeString or cSF, createSafeStringFromCharArray or cSFA, createSafeStringFromCharPtr or cSFP, createSafeStringFromCharPtrWithSize or cSFPS see the detailed description. More...
#include <SafeString.h>
Inherits Printable, and Print.
Inherited by SafeStringReader, and SerialComs.
Classes | |
class | DebugPrint |
class | noDebugPrint |
Public Member Functions | |
SafeString (unsigned int maxLen, char *buf, const char *cstr, const char *_name=NULL, bool _fromBuffer=false, bool _fromPtr=true) | |
SafeString Constructor called from the four (4) macros createSafeString or cSF, createSafeStringFromCharArray or cSFA, createSafeStringFromCharPtr or cSFP, createSafeStringFromCharPtrWithSize or cSFPS. More... | |
unsigned char | hasError () |
Returns non-zero if any error detected for this SafeString, each call clears the internal flag. More... | |
const char * | debug (bool verbose=true) |
Output the details about the this SafeString to the output specified by setOutput(). More... | |
const char * | debug (const char *title, bool verbose=true) |
Output the details about the this SafeString to the output specified by setOutput(). More... | |
const char * | debug (const __FlashStringHelper *title, bool verbose=true) |
Output the details about the this SafeString to the output specified by setOutput(). More... | |
const char * | debug (SafeString &stitle, bool verbose=true) |
Output the details about the this SafeString to the output specified by setOutput(). More... | |
virtual size_t | write (uint8_t b) |
Write (concatinate) a byte to this SafeString, from Print class. More... | |
virtual size_t | write (const uint8_t *buffer, size_t length) |
Write (concatinate) bytes to this SafeString, from Print class. More... | |
size_t | printTo (Print &p) const |
Implements the Printable interface. More... | |
unsigned char | reserve (unsigned int size) |
Checks there is enough free space in this SafeString for the current operation. More... | |
unsigned int | length (void) |
Number of characters current in the SafeString, excluding the terminating '\0'. More... | |
unsigned int | capacity (void) |
The maximum number of characters this SafeString can hold, excluding the terminating '\0'. More... | |
unsigned char | isFull (void) |
Returns non-zero if the SafeString is full. More... | |
unsigned char | isEmpty (void) |
Returns non-zero if the SafeString is empty. More... | |
int | availableForWrite (void) |
Returns the number chars that can be added to this SafeString before it is full. More... | |
SafeString & | clear (void) |
Empties this SafeString. More... | |
size_t | print (unsigned char, int=DEC) |
size_t | print (int, int=DEC) |
size_t | print (unsigned int, int=DEC) |
size_t | print (long, int=DEC) |
size_t | print (unsigned long, int=DEC) |
size_t | print (double, int=2) |
size_t | print (const __FlashStringHelper *) |
size_t | print (const char *) |
size_t | print (char) |
size_t | print (SafeString &str) |
size_t | println (unsigned char, int=DEC) |
size_t | println (int, int=DEC) |
size_t | println (unsigned int, int=DEC) |
size_t | println (long, int=DEC) |
size_t | println (unsigned long, int=DEC) |
size_t | println (double, int=2) |
size_t | println (const __FlashStringHelper *) |
size_t | println (const char *) |
size_t | println (char) |
size_t | println (SafeString &str) |
size_t | println (void) |
size_t | println (double d, int decs, int width, bool forceSign=false) |
Prints a double (or long/int) to this SafeString padded with spaces (left or right) and limited to the specified width and adds a trailing CR NL. More... | |
size_t | print (double d, int decs, int width, bool forceSign=false) |
Prints a double (or long/int) to this SafeString padded with spaces (left or right) and limited to the specified width. More... | |
SafeString & | operator= (char c) |
Clears this SafeString and concatinates a single char. More... | |
SafeString & | operator= (unsigned char num) |
Clears this SafeString and concatinates the text version of the argument. More... | |
SafeString & | operator= (int num) |
Clears this SafeString and concatinates the text version of the argument. More... | |
SafeString & | operator= (unsigned int num) |
Clears this SafeString and concatinates the text version of the argument. More... | |
SafeString & | operator= (long num) |
Clears this SafeString and concatinates the text version of the argument. More... | |
SafeString & | operator= (unsigned long num) |
Clears this SafeString and concatinates the text version of the argument. More... | |
SafeString & | operator= (float num) |
Clears this SafeString and concatinates the text version of the argument. More... | |
SafeString & | operator= (double num) |
Clears this SafeString and concatinates the text version of the argument. More... | |
SafeString & | operator= (SafeString &sfStr) |
Clears this SafeString and copies and concatinates the contents of the argument. More... | |
SafeString & | operator= (const char *cstr) |
Clears this SafeString and copies and concatinates the contents of the argument. More... | |
SafeString & | operator= (const __FlashStringHelper *pstr) |
Clears this SafeString and copies and concatinates the contents of the argument. More... | |
SafeString & | prefix (SafeString &s) |
prefix methods add to the front of the current SafeString. More... | |
SafeString & | prefix (const char *cstr) |
SafeString & | prefix (char c) |
SafeString & | prefix (unsigned char c) |
SafeString & | prefix (int num) |
SafeString & | prefix (unsigned int num) |
SafeString & | prefix (long num) |
SafeString & | prefix (unsigned long num) |
SafeString & | prefix (float num) |
SafeString & | prefix (double num) |
SafeString & | prefix (const __FlashStringHelper *str) |
SafeString & | prefix (const char *cstr, size_t length) |
SafeString & | prefix (const __FlashStringHelper *str, size_t length) |
SafeString & | concat (SafeString &str) |
concat methods add to the end of the current SafeString. More... | |
SafeString & | concat (const char *cstr) |
SafeString & | concat (char c) |
SafeString & | concat (unsigned char c) |
SafeString & | concat (int num) |
SafeString & | concat (unsigned int num) |
SafeString & | concat (long num) |
SafeString & | concat (unsigned long num) |
SafeString & | concat (float num) |
SafeString & | concat (double num) |
SafeString & | concat (const __FlashStringHelper *str) |
SafeString & | concat (const char *cstr, size_t length) |
SafeString & | concat (const __FlashStringHelper *str, size_t length) |
SafeString & | newline () |
Adds \r\n to this SafeString. More... | |
SafeString & | operator-= (SafeString &rhs) |
-= operator prefixes the SafeString. More... | |
SafeString & | operator-= (const char *cstr) |
SafeString & | operator-= (char c) |
SafeString & | operator-= (unsigned char num) |
SafeString & | operator-= (int num) |
SafeString & | operator-= (unsigned int num) |
SafeString & | operator-= (long num) |
SafeString & | operator-= (unsigned long num) |
SafeString & | operator-= (float num) |
SafeString & | operator-= (double num) |
SafeString & | operator-= (const __FlashStringHelper *str) |
SafeString & | operator+= (SafeString &rhs) |
+= operator concatinate to the SafeString. More... | |
SafeString & | operator+= (const char *cstr) |
SafeString & | operator+= (char c) |
SafeString & | operator+= (unsigned char num) |
SafeString & | operator+= (int num) |
SafeString & | operator+= (unsigned int num) |
SafeString & | operator+= (long num) |
SafeString & | operator+= (unsigned long num) |
SafeString & | operator+= (float num) |
SafeString & | operator+= (double num) |
SafeString & | operator+= (const __FlashStringHelper *str) |
int | compareTo (SafeString &s) |
returns -1 if this SafeString is < s, 0 if this SafeString == s and +1 if this SafeString > s More... | |
int | compareTo (const char *cstr) |
returns -1 if this SafeString is < cstr, 0 if this SafeString == cstr and +1 if this SafeString > cst More... | |
unsigned char | equals (SafeString &s) |
unsigned char | equals (const char *cstr) |
unsigned char | equals (const char c) |
unsigned char | operator== (SafeString &rhs) |
unsigned char | operator== (const char *cstr) |
unsigned char | operator== (const char c) |
unsigned char | operator!= (SafeString &rhs) |
unsigned char | operator!= (const char *cstr) |
unsigned char | operator!= (const char c) |
unsigned char | operator< (SafeString &rhs) |
unsigned char | operator> (SafeString &rhs) |
unsigned char | operator<= (SafeString &rhs) |
unsigned char | operator>= (SafeString &rhs) |
unsigned char | operator< (const char *rhs) |
unsigned char | operator> (const char *rhs) |
unsigned char | operator<= (const char *rhs) |
unsigned char | operator>= (const char *rhs) |
unsigned char | equalsIgnoreCase (SafeString &s) |
unsigned char | equalsIgnoreCase (const char *str2) |
unsigned char | equalsConstantTime (SafeString &s) |
unsigned char | startsWith (const char c, unsigned int fromIndex=0) |
returns non-zero of this SafeString starts this argument looking from fromIndex onwards. More... | |
unsigned char | startsWith (const char *str2, unsigned int fromIndex=0) |
returns non-zero of this SafeString starts this argument looking from fromIndex onwards. More... | |
unsigned char | startsWith (SafeString &s2, unsigned int fromIndex=0) |
returns non-zero of this SafeString starts this argument looking from fromIndex onwards. More... | |
unsigned char | startsWithIgnoreCase (const char c, unsigned int fromIndex=0) |
returns non-zero of this SafeString starts this argument, ignoring case, looking from fromIndex onwards. More... | |
unsigned char | startsWithIgnoreCase (const char *str2, unsigned int fromIndex=0) |
returns non-zero of this SafeString starts this argument, ignoring case, looking from fromIndex onwards. More... | |
unsigned char | startsWithIgnoreCase (SafeString &s2, unsigned int fromIndex=0) |
returns non-zero of this SafeString starts this argument, ignoring case, looking from fromIndex onwards. More... | |
unsigned char | endsWith (const char c) |
returns non-zero of this SafeString ends with the argument More... | |
unsigned char | endsWith (SafeString &suffix) |
returns non-zero of this SafeString ends with the argument More... | |
unsigned char | endsWith (const char *suffix) |
returns non-zero of this SafeString ends with the argument More... | |
unsigned char | endsWithCharFrom (SafeString &suffix) |
returns non-zero of this SafeString ends any one of the chars in the argument More... | |
unsigned char | endsWithCharFrom (const char *suffix) |
returns non-zero of this SafeString ends any one of the chars in the argument More... | |
char | charAt (unsigned int index) |
returns the char at that location in this SafeString. More... | |
char | operator[] (unsigned int index) |
returns the char at that location in this SafeString. More... | |
void | setCharAt (unsigned int index, char c) |
sets the char at that location in this SafeString. More... | |
const char * | c_str () |
returns a const char* to the underlying char[ ] in this SafeString. More... | |
int | indexOf (char ch, unsigned int fromIndex=0) |
returns the index of the char, searching from fromIndex. More... | |
int | indexOf (const char *str, unsigned int fromIndex=0) |
returns the index of the string, searching from fromIndex. More... | |
int | indexOf (SafeString &str, unsigned int fromIndex=0) |
returns the index of the SafeString, searching from fromIndex. More... | |
int | lastIndexOf (char ch) |
returns the last index of the char, searching backwards from fromIndex (inclusive). More... | |
int | lastIndexOf (char ch, unsigned int fromIndex) |
returns the last index of the char, searching backwards from fromIndex (inclusive). More... | |
int | lastIndexOf (SafeString &str) |
returns the last index of the arguement, searching backwards from fromIndex (inclusive). More... | |
int | lastIndexOf (SafeString &str, unsigned int fromIndex) |
returns the last index of the char, searching backwards from fromIndex (inclusive). More... | |
int | lastIndexOf (const char *cstr) |
returns the last index of the arguement, searching backwards from fromIndex (inclusive). More... | |
int | lastIndexOf (const char *cstr, unsigned int fromIndex) |
returns the last index of the char, searching backwards from fromIndex (inclusive). More... | |
int | indexOfCharFrom (SafeString &str, unsigned int fromIndex=0) |
returns the first index of any char from the argument. More... | |
int | indexOfCharFrom (const char *chars, unsigned int fromIndex=0) |
returns the first index of any char from the argument More... | |
SafeString & | substring (SafeString &result, unsigned int beginIdx) |
The result is the substring from the beginIdx to the end of the SafeString. More... | |
SafeString & | substring (SafeString &result, unsigned int beginIdx, unsigned int endIdx) |
The result is the substring from the beginIdx to endIdx (exclusive), that is the endIdx is NOT included. More... | |
void | replace (char findChar, char replaceChar) |
replace the findChar with the replaceChar More... | |
void | replace (const char findChar, const char *replaceStr) |
replace the findChar with the replace string More... | |
void | replace (const char findChar, SafeString &sfReplace) |
replace the findChar with the sfReplace SafeString contents More... | |
void | replace (const char *findStr, const char *replaceStr) |
replace the findStr string with the replace string More... | |
void | replace (SafeString &sfFind, SafeString &sfReplace) |
replace the occurances of the sfFind string, with the sfReplace SafeString contents More... | |
void | removeFrom (unsigned int startIndex) |
remove all chars from startIndex to the end of the SafeString (inclusive) More... | |
void | removeBefore (unsigned int startIndex) |
remove all chars from 0 to startIndex (exclusive), that is the char at startIndex is NOT removed More... | |
void | remove (unsigned int index) |
remove all chars from index to the end of the SafeString (inclusive) More... | |
void | remove (unsigned int index, unsigned int count) |
remove count chars starting from index More... | |
void | removeLast (unsigned int count) |
remove the last count chars More... | |
void | keepLast (unsigned int count) |
keep the last count chars and remove the rest More... | |
void | toLowerCase (void) |
convert this SafeString to all lower case More... | |
void | toUpperCase (void) |
convert this SafeString to all lower case More... | |
void | trim (void) |
remove all white space from the front and back of this SafeString. More... | |
void | processBackspaces (void) |
recursively remove backspaces, '\b' and the preceeding char. More... | |
unsigned char | toInt (int &i) |
convert the SafeString to an int. More... | |
unsigned char | toLong (long &l) |
convert the SafeString to a long. More... | |
unsigned char | binToLong (long &l) |
convert the SafeString to a long assuming the SafeString in binary (0/1). More... | |
unsigned char | octToLong (long &l) |
convert the SafeString to a long assuming the SafeString in octal (0 to 7). More... | |
unsigned char | hexToLong (long &l) |
convert the SafeString to a long assuming the SafeString in HEX (0 to f or 0 to F). More... | |
unsigned char | toUnsignedLong (unsigned long &l) |
convert the SafeString to an unsigned long. More... | |
unsigned char | binToUnsignedLong (unsigned long &l) |
convert the SafeString to an unsigned long assuming the SafeString in binary (0/1). More... | |
unsigned char | octToUnsignedLong (unsigned long &l) |
convert the SafeString to an unsigned long assuming the SafeString in octal (0 to 7). More... | |
unsigned char | hexToUnsignedLong (unsigned long &l) |
convert the SafeString to an unsigned long assuming the SafeString in HEX (0 to f or 0 to F). More... | |
unsigned char | toFloat (float &f) |
convert the SafeString to a float assuming the SafeString in the decimal format (not scientific) More... | |
unsigned char | toDouble (double &d) |
convert the SafeString to a float assuming the SafeString in the decimal format (not scientific) More... | |
int | stoken (SafeString &token, unsigned int fromIndex, const char delimiter, bool returnEmptyFields=false, bool useAsDelimiters=true) |
break into the SafeString into tokens using the char delimiter, the end of the SafeString is always a delimiter More... | |
int | stoken (SafeString &token, unsigned int fromIndex, const char *delimiters, bool returnEmptyFields=false, bool useAsDelimiters=true) |
break into the SafeString into tokens using the delimiters, the end of the SafeString is always a delimiter More... | |
int | stoken (SafeString &token, unsigned int fromIndex, SafeString &delimiters, bool returnEmptyFields=false, bool useAsDelimiters=true) |
break into the SafeString into tokens using the delimiters, the end of the SafeString is always a delimiter More... | |
unsigned char | firstToken (SafeString &token, char delimiter, bool returnLastNonDelimitedToken=true) |
returns true if a delimited token is found, removes the first delimited token from this SafeString and returns it in the token argument by default a leading delimiter is stepped over before scanning for a delimited token when nextToken() is called this firstToken() method overrides this and returns true and an empty token if the first char is a delimiter More... | |
unsigned char | nextToken (SafeString &token, char delimiter, bool returnEmptyFields=false, bool returnLastNonDelimitedToken=true, bool firstToken=false) |
returns true if a delimited token is found, removes the first delimited token from this SafeString and returns it in the token argument by default a leading delimiter is stepped over before scanning for a delimited token, the firstToken argument can override this setting the firstToken arguemnent = true, suppresses this so that an empty first token can be returned if the first char is a delimiter AND if returnEmptyFields is true More... | |
unsigned char | firstToken (SafeString &token, SafeString delimiters, bool returnLastNonDelimitedToken=true) |
returns true if a delimited token is found, removes the first delimited token from this SafeString and returns it in the token argument by default a leading delimiter is stepped over before scanning for a delimited token when nextToken() is called this firstToken() method overrides this and returns true and an empty token if the first char is a delimiter More... | |
unsigned char | nextToken (SafeString &token, SafeString &delimiters, bool returnEmptyFields=false, bool returnLastNonDelimitedToken=true, bool firstToken=false) |
returns true if a delimited token is found, removes the first delimited token from this SafeString and returns it in the token argument by default a leading delimiter is stepped over before scanning for a delimited token, the firstToken argument can override this setting the firstToken arguemnent = true, suppresses this so that an empty first token can be returned if the first char is a delimiter AND if returnEmptyFields is true More... | |
unsigned char | firstToken (SafeString &token, const char *delimiters, bool returnLastNonDelimitedToken=true) |
returns true if a delimited token is found, removes the first delimited token from this SafeString and returns it in the token argument by default a leading delimiter is stepped over before scanning for a delimited token when nextToken() is called this firstToken() method overrides this and returns true and an empty token if the first char is a delimiter More... | |
unsigned char | nextToken (SafeString &token, const char *delimiters, bool returnEmptyFields=false, bool returnLastNonDelimitedToken=true, bool firstToken=false) |
returns true if a delimited token is found, removes the first delimited token from this SafeString and returns it in the token argument by default a leading delimiter is stepped over before scanning for a delimited token, the firstToken argument can override this setting the firstToken arguemnent = true, suppresses this so that an empty first token can be returned if the first char is a delimiter AND if returnEmptyFields is true More... | |
unsigned int | readFrom (SafeString &sfInput, unsigned int startIdx=0) |
reads from the SafeString argument, starting at startIdx, into this SafeString. More... | |
unsigned int | readFrom (const char *strPtr, unsigned int maxCharsToRead=((unsigned int) -1)) |
reads from the const char* argument, starting at 0 and read up to maxCharToRead, into this SafeString. More... | |
unsigned int | writeTo (SafeString &output, unsigned int startIdx=0) |
writes from this SafeString, starting from startIdx, into the SafeString output arguement. More... | |
unsigned char | read (Stream &input) |
reads from the Stream (if chars available) into the SafeString. More... | |
unsigned char | readUntil (Stream &input, const char delimiter) |
reads chars into this SafeString until either it is full OR a delimiter is read OR there are no more chars available returns true if a delimiter found or SafeString is full, else false if a delimiter is found it is returned at the end of the SafeString Only at most one delimiter is added per call Multiple sucessive delimiters require multiple calls to read them More... | |
unsigned char | readUntil (Stream &input, const char *delimiters) |
reads chars into this SafeString until either it is full OR a delimiter is read OR there are no more chars available returns true if a delimiter found or SafeString is full, else false if a delimiter is found it is returned at the end of the SafeString Only at most one delimiter is added per call Multiple sucessive delimiters require multiple calls to read them More... | |
unsigned char | readUntil (Stream &input, SafeString &delimiters) |
reads chars into this SafeString until either it is full OR a delimiter is read OR there are no more chars available returns true if a delimiter found or SafeString is full, else false if a delimiter is found it is returned at the end of the SafeString Only at most one delimiter is added per call Multiple sucessive delimiters require multiple calls to read them More... | |
unsigned char | readUntilToken (Stream &input, SafeString &token, const char delimiter, bool &skipToDelimiter, uint8_t echoInput=false, unsigned long timeout_ms=0) |
returns true if a delimited token is found, else false ONLY delimited tokens of length less than this SafeString's capacity will return true with a non-empty token. More... | |
unsigned char | readUntilToken (Stream &input, SafeString &token, const char *delimiters, bool &skipToDelimiter, uint8_t echoInput=false, unsigned long timeout_ms=0) |
returns true if a delimited token is found, else false ONLY delimited tokens of length less than this SafeString's capacity will return true with a non-empty token. More... | |
unsigned char | readUntilToken (Stream &input, SafeString &token, SafeString &delimiters, bool &skipToDelimiter, uint8_t echoInput=false, unsigned long timeout_ms=0) |
returns true if a delimited token is found, else false ONLY delimited tokens of length less than this SafeString's capacity will return true with a non-empty token. More... | |
size_t | getLastReadCount () |
returns the number of chars read on previous calls to read, readUntil or readUntilToken (includes '\0' read if any). More... | |
Static Public Member Functions | |
static void | setOutput (Print &debugOut, bool verbose=true) |
Turns on Error msgs and debug( ) output for all SafeStrings. More... | |
static void | turnOutputOff (void) |
Turns off all debugging messages, both error messages AND debug() method output. More... | |
static void | setVerbose (bool verbose) |
Controls size of error messages, setOutput sets verbose to true. More... | |
static unsigned char | errorDetected () |
Returns non-zero if any SafeString has detected and error, each call clears the internal global static flag. More... | |
Static Public Attributes | |
static SafeString::DebugPrint | Output |
Protected Member Functions | |
SafeString & | concatln (const __FlashStringHelper *pstr) |
SafeString & | concatln (char c) |
SafeString & | concatln (const char *cstr, size_t length) |
void | outputName () const |
SafeString & | concatInternal (const char *cstr, size_t length, bool assignOp=false) |
SafeString & | concatInternal (const __FlashStringHelper *str, size_t length, bool assignOp=false) |
SafeString & | concatInternal (const char *cstr, bool assignOp=false) |
SafeString & | concatInternal (char c, bool assignOp=false) |
SafeString & | concatInternal (const __FlashStringHelper *str, bool assignOp=false) |
size_t | printInternal (long, int=DEC, bool assignOp=false) |
size_t | printInternal (unsigned long, int=DEC, bool assignOp=false) |
size_t | printInternal (double, int=2, bool assignOp=false) |
void | setError () |
void | printlnErr () const |
void | debugInternalMsg (bool _fullDebug) const |
size_t | limitedStrLen (const char *p, size_t limit) |
size_t | printInt (double d, int decs, int width, bool forceSign, bool addNL) |
Protected Attributes | |
char * | buffer |
size_t | _capacity |
size_t | len |
Static Protected Attributes | |
static Print * | debugPtr |
static bool | fullDebug |
static SafeString::noDebugPrint | emptyPrint |
static Print * | currentOutput |
To create SafeStrings use one of the four (4) macros createSafeString or cSF, createSafeStringFromCharArray or cSFA, createSafeStringFromCharPtr or cSFP, createSafeStringFromCharPtrWithSize or cSFPS see the detailed description.
There are four (4) macros used to create SafeStrings.
createSafeString(name, size); creates a char[size+1] for you and wraps it in a SafeString called name.
createSafeStringFromCharArray(name, char[]); wraps an existing char[] in a SafeString called name.
createSafeStringFromCharPtr(name, char*); wraps an existing char[], pointed to by char*, in a SafeString called name. The capacity of the SafeString is limited to the initial strlen(char*) and cannot be increased
createSafeStringFromCharPtrWithSize(name, char*, size); wraps an existing char[size], pointed to by char*, in a SafeString called name.
Each of thise macros has a short hand
cSF(name,size) for createSafeString(name, size);
cSFA(name,char[]) for createSafeStringFromCharArray(name, char[]);
cSFP(name,char*) for createSafeStringFromCharPtr(name, char*);
cSFPS(name,char*,size) for createSafeStringFromCharPtrWithSize(name, char*, size);
createSafeString(name, size) or cSF(name,size)
and
createSafeString(name, size, "initialText")
or cSF(name,size,"initialText")
are utility macros to create a SafeString of a given name and size and optionally, an initial value
createSafeString(str, 40); or cSF(str, 40); expands in the pre-processor to
char str_SAFEBUFFER[40+1];
SafeString str(sizeof(str_SAFEBUFFER),str_SAFEBUFFER,"","str");
createSafeString(str, 40, "test"); or cSF(str, 40, "test"); expands in the pre-processor to
char str_SAFEBUFFER[40+1];
SafeString str(sizeof(str_SAFEBUFFER),str_SAFEBUFFER,"test","str");
createSafeStringFromCharArray(name, char[]); or cSFA(name, char[]); wraps an existing char[] in a SafeString of the given name. e.g.
char charBuffer[15];
createSafeStringFromCharArray(str,charBuffer); or cSFA(str,charBuffer);
expands in the pre-processor to
SafeString str(sizeof(charBuffer),charBuffer, charBuffer, "str", true);
The capacity of the SafeString is set to 14, from the sizeof(charBuffer)-1 to allow for the terminating '\0'.
createSafeStringFromCharPtr(name, char*); or cSFP(name, char*); wraps an existing char[] pointed to by char* in a SafeString of the given name
The capacity of the SafeString is set to strlen(charBuffer)
and cannot be increased. e.g.
char charBuffer[15] = "1234567890";
char *bufPtr = charBuffer;
createSafeStringFromCharPtr(str,bufPtr); or cSFP(str,bufPtr);
expands in the pre-processor to
SafeString str((unsigned int)-1,charBuffer, charBuffer, "str", true);
The capacity of the SafeString is set to 10, from the strlen(bufPtr)
createSafeStringFromCharPtrWithSize(name, char*, unsigned int size); or cSFPS(name, char*, unsigned int size); wraps an existing char[], pointed to by char*, in a SafeString of the given name
and sets the capacity to the given unsigned int size e.g.
char charBuffer[15]="1234567890";
char *bufPtr = charBuffer;
createSafeStringFromCharPtrWithSize(str,bufPtr, 15); or cSFPS(str,bufPtr, 15);
expands in the pre-processor to
SafeString str(15,charBuffer, charBuffer, "str", true);
The capacity of the SafeString is set to 14 from size-1 to allow for the terminating '\0'.
See The SafeString alternative to Arduino Strings for Beginners for a tutorial.
Also see the example sketches included with the library
SafeString_ConstructorAndDebugging.ino, SafeStringFromCharArray.ino, SafeStringFromCharPtr.ino and SafeStringFromCharPtrWithSize.ino
Definition at line 307 of file SafeString.h.
|
explicit |
SafeString Constructor called from the four (4) macros createSafeString or cSF, createSafeStringFromCharArray or cSFA, createSafeStringFromCharPtr or cSFP, createSafeStringFromCharPtrWithSize or cSFPS.
This constructor is not designed to called directly by your code. See the detailed SafeString class description above.
maxLen | - the number of chars that can stored not including the terminating '\0' |
buf | - the fixed sized char buffer to hold the data |
cstr | - the initial data to be loaded into this SafeString |
_name | - the code variable name of this SafeString, default NULL |
_fromBuffer | - true if this SafeString is wrapping an existing char[] |
_fromPtr | - true if this SafeString's buf parameter was a char* rather then a char[], _fromPtr is not checked unless _fromBuffer is true |
int SafeString::availableForWrite | ( | void | ) |
Returns the number chars that can be added to this SafeString before it is full.
unsigned char SafeString::binToLong | ( | long & | l | ) |
convert the SafeString to a long assuming the SafeString in binary (0/1).
l | – long reference, where the result is stored. l is only updated if the conversion is successful |
unsigned char SafeString::binToUnsignedLong | ( | unsigned long & | l | ) |
convert the SafeString to an unsigned long assuming the SafeString in binary (0/1).
l | – unsigned long reference, where the result is stored. l is only updated if the conversion is successful |
const char* SafeString::c_str | ( | ) |
returns a const char* to the underlying char[ ] in this SafeString.
Do not make changes this char[ ]
unsigned int SafeString::capacity | ( | void | ) |
The maximum number of characters this SafeString can hold, excluding the terminating '\0'.
char SafeString::charAt | ( | unsigned int | index | ) |
returns the char at that location in this SafeString.
index | - the zero based index of the char to return. |
SafeString& SafeString::clear | ( | void | ) |
Empties this SafeString.
returns the current SafeString so you can cascade calls e.g.
sfStr.clear().concat("New output");
int SafeString::compareTo | ( | const char * | cstr | ) |
returns -1 if this SafeString is < cstr, 0 if this SafeString == cstr and +1 if this SafeString > cst
int SafeString::compareTo | ( | SafeString & | s | ) |
returns -1 if this SafeString is < s, 0 if this SafeString == s and +1 if this SafeString > s
SafeString& SafeString::concat | ( | char | c | ) |
SafeString& SafeString::concat | ( | const __FlashStringHelper * | str | ) |
SafeString& SafeString::concat | ( | const __FlashStringHelper * | str, |
size_t | length | ||
) |
SafeString& SafeString::concat | ( | const char * | cstr | ) |
SafeString& SafeString::concat | ( | const char * | cstr, |
size_t | length | ||
) |
SafeString& SafeString::concat | ( | double | num | ) |
SafeString& SafeString::concat | ( | float | num | ) |
SafeString& SafeString::concat | ( | int | num | ) |
SafeString& SafeString::concat | ( | long | num | ) |
SafeString& SafeString::concat | ( | SafeString & | str | ) |
concat methods add to the end of the current SafeString.
returns the current SafeString so you can cascade calls e.g.
sfStr.concat(1).concat("second");
If there's not enough memory for the concatenated value, the SafeString will be left unchanged.
If the argument is null or invalid, the concatenation is considered unsucessful.
SafeString& SafeString::concat | ( | unsigned char | c | ) |
SafeString& SafeString::concat | ( | unsigned int | num | ) |
SafeString& SafeString::concat | ( | unsigned long | num | ) |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
const char* SafeString::debug | ( | bool | verbose = true | ) |
Output the details about the this SafeString to the output specified by setOutput().
verbose | - true for detailed output including current contents |
const char* SafeString::debug | ( | const __FlashStringHelper * | title, |
bool | verbose = true |
||
) |
Output the details about the this SafeString to the output specified by setOutput().
title | - the title to preceed the debug output, a space between this and the debug output |
verbose | - true for detailed output including current contents |
const char* SafeString::debug | ( | const char * | title, |
bool | verbose = true |
||
) |
Output the details about the this SafeString to the output specified by setOutput().
title | - the title to preceed the debug output, a space between this and the debug output |
verbose | - true for detailed output including current contents |
const char* SafeString::debug | ( | SafeString & | stitle, |
bool | verbose = true |
||
) |
Output the details about the this SafeString to the output specified by setOutput().
title | - the title to preceed the debug output, a space between this and the debug output |
verbose | - true for detailed output including current contents |
|
protected |
unsigned char SafeString::endsWith | ( | const char * | suffix | ) |
returns non-zero of this SafeString ends with the argument
suffix | – string to check for |
unsigned char SafeString::endsWith | ( | const char | c | ) |
returns non-zero of this SafeString ends with the argument
c | – the char to check for |
unsigned char SafeString::endsWith | ( | SafeString & | suffix | ) |
returns non-zero of this SafeString ends with the argument
suffix | – SafeString to check for |
unsigned char SafeString::endsWithCharFrom | ( | const char * | suffix | ) |
returns non-zero of this SafeString ends any one of the chars in the argument
suffix | – the string containing the chars to check for |
unsigned char SafeString::endsWithCharFrom | ( | SafeString & | suffix | ) |
returns non-zero of this SafeString ends any one of the chars in the argument
suffix | – the SafeString containing the chars to check for |
unsigned char SafeString::equals | ( | const char * | cstr | ) |
unsigned char SafeString::equals | ( | const char | c | ) |
unsigned char SafeString::equals | ( | SafeString & | s | ) |
unsigned char SafeString::equalsConstantTime | ( | SafeString & | s | ) |
unsigned char SafeString::equalsIgnoreCase | ( | const char * | str2 | ) |
unsigned char SafeString::equalsIgnoreCase | ( | SafeString & | s | ) |
|
static |
Returns non-zero if any SafeString has detected and error, each call clears the internal global static flag.
|
inline |
returns true if a delimited token is found, removes the first delimited token from this SafeString and returns it in the token argument
by default a leading delimiter is stepped over before scanning for a delimited token when nextToken() is called
this firstToken() method overrides this and returns true and an empty token if the first char is a delimiter
The delimiter is not returned and remains in the SafeString so you can test which delimiter terminated the token, provided this SafeString is not empty!
The token argument is always cleared at the start of the nexttToken().
IMPORTANT!! Changed V4.0.4 Now by default un-delimited tokens at the end of the SafeString are returned
To leave partial un-delimited tokens on the end of the SafeString, set returnLastNonDelimitedToken = false.
Setting returnLastNonDelimitedToken = false allows the SafeString to hold partial tokens when reading from an input stream one char at a time.
token | - the SafeString to return the token in, it is always cleared first and will be empty if no delimited token is found or if there are errors The token's capacity should be >= this SafeString's capacity incase the entire SafeString needs to be returned. If the token's capacity is < the next token, then nextToken() returns true, but the returned token argument is empty and an error messages printed if debug is enabled. In this case to next token is still removed from the SafeString so that the program will not be stuck in an infinite loop calling nextToken() |
delimiter | - the char which can delimit a token |
returnLastNonDelimitedToken | – default true, will return last part of SafeString even if not delimited. If set false, will keep it for further input to be added to this SafeString NOTE: since the last delimiter is left in the SafeString, you should only use firstToken() for the first call. |
Definition at line 1528 of file SafeString.h.
|
inline |
returns true if a delimited token is found, removes the first delimited token from this SafeString and returns it in the token argument
by default a leading delimiter is stepped over before scanning for a delimited token when nextToken() is called
this firstToken() method overrides this and returns true and an empty token if the first char is a delimiter
The delimiter is not returned and remains in the SafeString so you can test which delimiter terminated the token, provided this SafeString is not empty!
The token argument is always cleared at the start of the nexttToken().
IMPORTANT!! Changed V4.0.4 Now by default un-delimited tokens at the end of the SafeString are returned
To leave partial un-delimited tokens on the end of the SafeString, set returnLastNonDelimitedToken = false.
Setting returnLastNonDelimitedToken = false allows the SafeString to hold partial tokens when reading from an input stream one char at a time.
token | - the SafeString to return the token in, it is always cleared first and will be empty if no delimited token is found or if there are errors The token's capacity should be >= this SafeString's capacity incase the entire SafeString needs to be returned. If the token's capacity is < the next token, then firstToken() returns true, but the returned token argument is empty and an error messages printed if debug is enabled. In this case to next token is still removed from the SafeString so that the program will not be stuck in an infinite loop calling nextToken() |
delimiters | - the string containing the delimiting characters, any one of which can delimit a token |
returnLastNonDelimitedToken | – default true, will return last part of SafeString even if not delimited. If set false, will keep it for further input to be added to this SafeString NOTE: since the last delimiter is left in the SafeString, you should only use firstToken() for the first call. |
Definition at line 1650 of file SafeString.h.
|
inline |
returns true if a delimited token is found, removes the first delimited token from this SafeString and returns it in the token argument
by default a leading delimiter is stepped over before scanning for a delimited token when nextToken() is called
this firstToken() method overrides this and returns true and an empty token if the first char is a delimiter
The delimiter is not returned and remains in the SafeString so you can test which delimiter terminated the token, provided this SafeString is not empty!
The token argument is always cleared at the start of the nexttToken().
IMPORTANT!! Changed V4.0.4 Now by default un-delimited tokens at the end of the SafeString are returned
To leave partial un-delimited tokens on the end of the SafeString, set returnLastNonDelimitedToken = false.
Setting returnLastNonDelimitedToken = false allows the SafeString to hold partial tokens when reading from an input stream one char at a time.
token | - the SafeString to return the token in, it is always cleared first and will be empty if no delimited token is found or if there are errors The token's capacity should be >= this SafeString's capacity incase the entire SafeString needs to be returned. If the token's capacity is < the next token, then nextToken() returns true, but the returned token argument is empty and an error messages printed if debug is enabled. In this case to next token is still removed from the SafeString so that the program will not be stuck in an infinite loop calling nextToken() |
delimiters | - the SafeString containing the delimiting characters, any one of which can delimit a token |
returnLastNonDelimitedToken | – default true, will return last part of SafeString even if not delimited. If set false, will keep it for further input to be added to this SafeString NOTE: since the last delimiter is left in the SafeString, you should only use firstToken() for the first call. |
Definition at line 1589 of file SafeString.h.
size_t SafeString::getLastReadCount | ( | ) |
returns the number of chars read on previous calls to read, readUntil or readUntilToken (includes '\0' read if any).
Each call read, readUntil, readUntilToken first clears this count
unsigned char SafeString::hasError | ( | ) |
Returns non-zero if any error detected for this SafeString, each call clears the internal flag.
unsigned char SafeString::hexToLong | ( | long & | l | ) |
convert the SafeString to a long assuming the SafeString in HEX (0 to f or 0 to F).
l | – long reference, where the result is stored. l is only updated if the conversion is successful |
unsigned char SafeString::hexToUnsignedLong | ( | unsigned long & | l | ) |
convert the SafeString to an unsigned long assuming the SafeString in HEX (0 to f or 0 to F).
l | – unsigned long reference, where the result is stored. l is only updated if the conversion is successful |
int SafeString::indexOf | ( | char | ch, |
unsigned int | fromIndex = 0 |
||
) |
returns the index of the char, searching from fromIndex.
ch | - the char to search for |
fromIndex | - where to start the search from, default 0, that is from begining if fromIndex > length() raise an error if fromIndex == -1 OR fromIndex == length(), return -1 without error |
int SafeString::indexOf | ( | const char * | str, |
unsigned int | fromIndex = 0 |
||
) |
returns the index of the string, searching from fromIndex.
str | - the string to search for |
fromIndex | - where to start the search from, default 0, that is from begining if fromIndex > length() raise an error if fromIndex == -1 OR fromIndex == length(), return -1 without error |
int SafeString::indexOf | ( | SafeString & | str, |
unsigned int | fromIndex = 0 |
||
) |
returns the index of the SafeString, searching from fromIndex.
str | - the SafeString to search for |
fromIndex | - where to start the search from, default 0, that is from begining if fromIndex > length() raise an error if fromIndex == -1 OR fromIndex == length(), return -1 without error |
int SafeString::indexOfCharFrom | ( | const char * | chars, |
unsigned int | fromIndex = 0 |
||
) |
returns the first index of any char from the argument
chars | - the string containing the chars to search for |
fromIndex | - where to start searching backwards from, if fromIndex > length() raise an error if fromIndex == -1 OR fromIndex == length(), return -1 without error |
int SafeString::indexOfCharFrom | ( | SafeString & | str, |
unsigned int | fromIndex = 0 |
||
) |
returns the first index of any char from the argument.
str | - the SafeString containing the chars to search for |
fromIndex | - where to start searching from, if fromIndex > length() raise an error if fromIndex == -1 OR fromIndex == length(), return -1 without error |
unsigned char SafeString::isEmpty | ( | void | ) |
Returns non-zero if the SafeString is empty.
unsigned char SafeString::isFull | ( | void | ) |
Returns non-zero if the SafeString is full.
void SafeString::keepLast | ( | unsigned int | count | ) |
keep the last count chars and remove the rest
count | - the number of chars to keep 0 to length() is valid for count count == 0 clears the SafeString count > length() raises and error and leaves the SafeString unchanged |
int SafeString::lastIndexOf | ( | char | ch | ) |
returns the last index of the char, searching backwards from fromIndex (inclusive).
c | - the char to search for |
int SafeString::lastIndexOf | ( | char | ch, |
unsigned int | fromIndex | ||
) |
returns the last index of the char, searching backwards from fromIndex (inclusive).
c | - the char to search for |
fromIndex | - where to start searching backwards from, if fromIndex > length() raise an error if fromIndex == -1 OR fromIndex == length(), return -1 without error |
int SafeString::lastIndexOf | ( | const char * | cstr | ) |
returns the last index of the arguement, searching backwards from fromIndex (inclusive).
cstr | - the string to search for |
int SafeString::lastIndexOf | ( | const char * | cstr, |
unsigned int | fromIndex | ||
) |
returns the last index of the char, searching backwards from fromIndex (inclusive).
cstr | - the string to search for |
fromIndex | - where to start searching backwards from, if fromIndex > length() raise an error if fromIndex == -1 OR fromIndex == length(), return -1 without error |
int SafeString::lastIndexOf | ( | SafeString & | str | ) |
returns the last index of the arguement, searching backwards from fromIndex (inclusive).
str | - the SafeString to search for |
int SafeString::lastIndexOf | ( | SafeString & | str, |
unsigned int | fromIndex | ||
) |
returns the last index of the char, searching backwards from fromIndex (inclusive).
str | - the SafeString to search for |
fromIndex | - where to start searching backwards from, if fromIndex > length() raise an error if fromIndex == -1 OR fromIndex == length(), return -1 without error |
unsigned int SafeString::length | ( | void | ) |
Number of characters current in the SafeString, excluding the terminating '\0'.
|
protected |
SafeString& SafeString::newline | ( | ) |
Adds \r\n to this SafeString.
returns the current SafeString so you can cascade calls e.g.
sfStr.newline().concat("next line");
unsigned char SafeString::nextToken | ( | SafeString & | token, |
char | delimiter, | ||
bool | returnEmptyFields = false , |
||
bool | returnLastNonDelimitedToken = true , |
||
bool | firstToken = false |
||
) |
returns true if a delimited token is found, removes the first delimited token from this SafeString and returns it in the token argument
by default a leading delimiter is stepped over before scanning for a delimited token, the firstToken argument can override this
setting the firstToken arguemnent = true, suppresses this so that an empty first token can be returned if the first char is a delimiter AND if returnEmptyFields is true
The delimiter is not returned and remains in the SafeString so you can test which delimiter terminated the token, provided this SafeString is not empty!
The token argument is always cleared at the start of the nexttToken().
IMPORTANT!! Changed V4.0.4 Now by default un-delimited tokens at the end of the SafeString are returned
To leave partial un-delimited tokens on the end of the SafeString, set returnLastNonDelimitedToken = false.
Setting returnLastNonDelimitedToken = false allows the SafeString to hold partial tokens when reading from an input stream one char at a time.
Setting firstToken = true suppressed skipping over a leading delimiter so that an empty first field can be returned if the first char is a delimiter
token | - the SafeString to return the token in, it is always cleared first and will be empty if no delimited token is found or if there are errors The token's capacity should be >= this SafeString's capacity incase the entire SafeString needs to be returned. If the token's capacity is < the next token, then firstToken() returns true, but the returned token argument is empty and an error messages printed if debug is enabled. In this case to next token is still removed from the SafeString so that the program will not be stuck in an infinite loop calling nextToken() |
delimiter | - the char which can delimit a token |
returnEmptyFields | – default false, if true, nextToken() will return true, and an empty token for each consecutive delimiters |
returnLastNonDelimitedToken | – default true, will return last part of SafeString even if not delimited. If set false, will keep it for further input to be added to this SafeString |
firstToken | – default false, a leading delimiter will be stepped over before looking for a delimited token if set to true, a leading delimiter will delimit an empty token which will be returned only if returnEmptyFields is true otherwise it is skipped over. NOTE: if returnEmptyFields == false this firstToken argument has no effect. NOTE: since the last delimiter is left in the SafeString, you must set firstToken to be false (or omit it) after the first call. |
unsigned char SafeString::nextToken | ( | SafeString & | token, |
const char * | delimiters, | ||
bool | returnEmptyFields = false , |
||
bool | returnLastNonDelimitedToken = true , |
||
bool | firstToken = false |
||
) |
returns true if a delimited token is found, removes the first delimited token from this SafeString and returns it in the token argument
by default a leading delimiter is stepped over before scanning for a delimited token, the firstToken argument can override this
setting the firstToken arguemnent = true, suppresses this so that an empty first token can be returned if the first char is a delimiter AND if returnEmptyFields is true
The delimiter is not returned and remains in the SafeString so you can test which delimiter terminated the token, provided this SafeString is not empty!
The token argument is always cleared at the start of the nexttToken().
IMPORTANT!! Changed V4.0.4 Now by default un-delimited tokens at the end of the SafeString are returned
To leave partial un-delimited tokens on the end of the SafeString, set returnLastNonDelimitedToken = false.
Setting returnLastNonDelimitedToken = false allows the SafeString to hold partial tokens when reading from an input stream one char at a time.
Setting firstToken = true suppressed skipping over a leading delimiter so that an empty first field can be returned if the first char is a delimiter
token | - the SafeString to return the token in, it is always cleared first and will be empty if no delimited token is found or if there are errors The token's capacity should be >= this SafeString's capacity incase the entire SafeString needs to be returned. If the token's capacity is < the next token, then nextToken() returns true, but the returned token argument is empty and an error messages printed if debug is enabled. In this case to next token is still removed from the SafeString so that the program will not be stuck in an infinite loop calling nextToken() |
delimiters | - the string containing the delimiting characters, any one of which can delimit a token |
returnEmptyFields | – default false, if true, nextToken() will return true, and an empty token for each consecutive delimiters |
returnLastNonDelimitedToken | – default true, will return last part of SafeString even if not delimited. If set false, will keep it for further input to be added to this SafeString |
firstToken | – default false, a leading delimiter will be stepped over before looking for a delimited token if set to true, a leading delimiter will delimit an empty token which will be returned only if returnEmptyFields is true otherwise it is skipped over. NOTE: if returnEmptyFields == false this firstToken argument has no effect. NOTE: since the last delimiter is left in the SafeString, you must set firstToken to be false (or omit it) after the first call. |
unsigned char SafeString::nextToken | ( | SafeString & | token, |
SafeString & | delimiters, | ||
bool | returnEmptyFields = false , |
||
bool | returnLastNonDelimitedToken = true , |
||
bool | firstToken = false |
||
) |
returns true if a delimited token is found, removes the first delimited token from this SafeString and returns it in the token argument
by default a leading delimiter is stepped over before scanning for a delimited token, the firstToken argument can override this
setting the firstToken arguemnent = true, suppresses this so that an empty first token can be returned if the first char is a delimiter AND if returnEmptyFields is true
The delimiter is not returned and remains in the SafeString so you can test which delimiter terminated the token, provided this SafeString is not empty!
The token argument is always cleared at the start of the nexttToken().
IMPORTANT!! Changed V4.0.4 Now by default un-delimited tokens at the end of the SafeString are returned
To leave partial un-delimited tokens on the end of the SafeString, set returnLastNonDelimitedToken = false.
Setting returnLastNonDelimitedToken = false allows the SafeString to hold partial tokens when reading from an input stream one char at a time.
Setting firstToken = true suppressed skipping over a leading delimiter so that an empty first field can be returned if the first char is a delimiter
token | - the SafeString to return the token in, it is always cleared first and will be empty if no delimited token is found or if there are errors The token's capacity should be >= this SafeString's capacity incase the entire SafeString needs to be returned. If the token's capacity is < the next token, then firstToken() returns true, but the returned token argument is empty and an error messages printed if debug is enabled. In this case to next token is still removed from the SafeString so that the program will not be stuck in an infinite loop calling nextToken() |
delimiters | - the SafeString containing the delimiting characters, any one of which can delimit a token |
returnEmptyFields | – default false, if true, nextToken() will return true, and an empty token for each consecutive delimiters |
returnLastNonDelimitedToken | – default true, will return last part of SafeString even if not delimited. If set false, will keep it for further input to be added to this SafeString |
firstToken | – default false, a leading delimiter will be stepped over before looking for a delimited token if set to true, a leading delimiter will delimit an empty token which will be returned only if returnEmptyFields is true otherwise it is skipped over. NOTE: if returnEmptyFields == false this firstToken argument has no effect. NOTE: since the last delimiter is left in the SafeString, you must set firstToken to be false (or omit it) after the first call. |
unsigned char SafeString::octToLong | ( | long & | l | ) |
convert the SafeString to a long assuming the SafeString in octal (0 to 7).
l | – long reference, where the result is stored. l is only updated if the conversion is successful |
unsigned char SafeString::octToUnsignedLong | ( | unsigned long & | l | ) |
convert the SafeString to an unsigned long assuming the SafeString in octal (0 to 7).
l | – unsigned long reference, where the result is stored. l is only updated if the conversion is successful |
|
inline |
Definition at line 828 of file SafeString.h.
|
inline |
Definition at line 831 of file SafeString.h.
|
inline |
Definition at line 825 of file SafeString.h.
|
inline |
Definition at line 771 of file SafeString.h.
|
inline |
Definition at line 795 of file SafeString.h.
|
inline |
Definition at line 768 of file SafeString.h.
|
inline |
Definition at line 792 of file SafeString.h.
|
inline |
Definition at line 789 of file SafeString.h.
|
inline |
Definition at line 777 of file SafeString.h.
|
inline |
Definition at line 783 of file SafeString.h.
|
inline |
+= operator concatinate to the SafeString.
e.g.
sfStr += "end";
gives the same SafeString as
sfStr.concat("end");
Definition at line 765 of file SafeString.h.
|
inline |
Definition at line 774 of file SafeString.h.
|
inline |
Definition at line 780 of file SafeString.h.
|
inline |
Definition at line 786 of file SafeString.h.
|
inline |
Definition at line 724 of file SafeString.h.
|
inline |
Definition at line 748 of file SafeString.h.
|
inline |
Definition at line 721 of file SafeString.h.
|
inline |
Definition at line 745 of file SafeString.h.
|
inline |
Definition at line 742 of file SafeString.h.
|
inline |
Definition at line 730 of file SafeString.h.
|
inline |
Definition at line 736 of file SafeString.h.
|
inline |
-= operator prefixes the SafeString.
e.g.
sfStr -= "top";
gives the same SafeString as
sfStr.prefix("top");
Definition at line 718 of file SafeString.h.
|
inline |
Definition at line 727 of file SafeString.h.
|
inline |
Definition at line 733 of file SafeString.h.
|
inline |
Definition at line 739 of file SafeString.h.
|
inline |
Definition at line 846 of file SafeString.h.
|
inline |
Definition at line 834 of file SafeString.h.
|
inline |
Definition at line 852 of file SafeString.h.
|
inline |
Definition at line 840 of file SafeString.h.
SafeString& SafeString::operator= | ( | char | c | ) |
Clears this SafeString and concatinates a single char.
If the value is null or invalid, or too large to be fit in the string's internal buffer the resulting SafeString will be empty
c | - the char |
SafeString& SafeString::operator= | ( | const __FlashStringHelper * | pstr | ) |
Clears this SafeString and copies and concatinates the contents of the argument.
If the value is null or invalid, or too large to be fit in the string's internal buffer the resulting SafeString will be empty
pstr | - the '\0' terminated F("..") string to assign |
SafeString& SafeString::operator= | ( | const char * | cstr | ) |
Clears this SafeString and copies and concatinates the contents of the argument.
If the value is null or invalid, or too large to be fit in the string's internal buffer the resulting SafeString will be empty
cstr | - the '\0' terminated char string to assign |
SafeString& SafeString::operator= | ( | double | num | ) |
Clears this SafeString and concatinates the text version of the argument.
If the value is null or invalid, or too large to be fit in the string's internal buffer the resulting SafeString will be empty
num | - the number to convert to text |
SafeString& SafeString::operator= | ( | float | num | ) |
Clears this SafeString and concatinates the text version of the argument.
If the value is null or invalid, or too large to be fit in the string's internal buffer the resulting SafeString will be empty
num | - the number to convert to text |
SafeString& SafeString::operator= | ( | int | num | ) |
Clears this SafeString and concatinates the text version of the argument.
If the value is null or invalid, or too large to be fit in the string's internal buffer the resulting SafeString will be empty
num | - the number to convert to text |
SafeString& SafeString::operator= | ( | long | num | ) |
Clears this SafeString and concatinates the text version of the argument.
If the value is null or invalid, or too large to be fit in the string's internal buffer the resulting SafeString will be empty
num | - the number to convert to text |
SafeString& SafeString::operator= | ( | SafeString & | sfStr | ) |
Clears this SafeString and copies and concatinates the contents of the argument.
If the value is null or invalid, or too large to be fit in the string's internal buffer the resulting SafeString will be empty
sfStr | - the SafeString to assign |
SafeString& SafeString::operator= | ( | unsigned char | num | ) |
Clears this SafeString and concatinates the text version of the argument.
If the value is null or invalid, or too large to be fit in the string's internal buffer the resulting SafeString will be empty
num | - the number to convert to text |
SafeString& SafeString::operator= | ( | unsigned int | num | ) |
Clears this SafeString and concatinates the text version of the argument.
If the value is null or invalid, or too large to be fit in the string's internal buffer the resulting SafeString will be empty
num | - the number to convert to text |
SafeString& SafeString::operator= | ( | unsigned long | num | ) |
Clears this SafeString and concatinates the text version of the argument.
If the value is null or invalid, or too large to be fit in the string's internal buffer the resulting SafeString will be empty
num | - the number to convert to text |
|
inline |
Definition at line 819 of file SafeString.h.
|
inline |
Definition at line 822 of file SafeString.h.
|
inline |
Definition at line 816 of file SafeString.h.
|
inline |
Definition at line 849 of file SafeString.h.
|
inline |
Definition at line 837 of file SafeString.h.
|
inline |
Definition at line 855 of file SafeString.h.
|
inline |
Definition at line 843 of file SafeString.h.
char SafeString::operator[] | ( | unsigned int | index | ) |
returns the char at that location in this SafeString.
index | - the zero based index of the char to return. |
|
protected |
SafeString& SafeString::prefix | ( | char | c | ) |
SafeString& SafeString::prefix | ( | const __FlashStringHelper * | str | ) |
SafeString& SafeString::prefix | ( | const __FlashStringHelper * | str, |
size_t | length | ||
) |
SafeString& SafeString::prefix | ( | const char * | cstr | ) |
SafeString& SafeString::prefix | ( | const char * | cstr, |
size_t | length | ||
) |
SafeString& SafeString::prefix | ( | double | num | ) |
SafeString& SafeString::prefix | ( | float | num | ) |
SafeString& SafeString::prefix | ( | int | num | ) |
SafeString& SafeString::prefix | ( | long | num | ) |
SafeString& SafeString::prefix | ( | SafeString & | s | ) |
prefix methods add to the front of the current SafeString.
returns the current SafeString so you can cascade calls, e.g.
sfStr.prefix(2).prefix("first");
If there's not enough memory for the to add prefix, the SafeString will be left unchanged
If the argument is null or invalid, the prefix is considered unsucessful.
SafeString& SafeString::prefix | ( | unsigned char | c | ) |
SafeString& SafeString::prefix | ( | unsigned int | num | ) |
SafeString& SafeString::prefix | ( | unsigned long | num | ) |
size_t SafeString::print | ( | char | ) |
size_t SafeString::print | ( | const __FlashStringHelper * | ) |
size_t SafeString::print | ( | const char * | ) |
size_t SafeString::print | ( | double | d, |
int | decs, | ||
int | width, | ||
bool | forceSign = false |
||
) |
Prints a double (or long/int) to this SafeString padded with spaces (left or right) and limited to the specified width.
This methods can also be used for ints and longs by passing 0 for the decs.
d | - the double to convert to text |
decs | - the preferred number of decimial places to output(limited to <7). This will be reduced automatically to fit the fixed width |
width | - fixed width the output is to padded/limited to |
forceSign | - optional, defaults to false, if true the + sign is added for +ve numbers |
size_t SafeString::print | ( | double | , |
int | = 2 |
||
) |
size_t SafeString::print | ( | int | , |
int | = DEC |
||
) |
size_t SafeString::print | ( | long | , |
int | = DEC |
||
) |
size_t SafeString::print | ( | SafeString & | str | ) |
size_t SafeString::print | ( | unsigned char | , |
int | = DEC |
||
) |
size_t SafeString::print | ( | unsigned int | , |
int | = DEC |
||
) |
size_t SafeString::print | ( | unsigned long | , |
int | = DEC |
||
) |
|
protected |
|
protected |
|
protected |
|
protected |
size_t SafeString::println | ( | char | ) |
size_t SafeString::println | ( | const __FlashStringHelper * | ) |
size_t SafeString::println | ( | const char * | ) |
size_t SafeString::println | ( | double | d, |
int | decs, | ||
int | width, | ||
bool | forceSign = false |
||
) |
Prints a double (or long/int) to this SafeString padded with spaces (left or right) and limited to the specified width and adds a trailing CR NL.
This methods can also be used for ints and longs by passing 0 for the decs.
d | - the double to convert to text |
decs | - the preferred number of decimial places to output (limited to <7). This will be reduced automatically to fit the fixed width |
width | - fixed width the output is to padded/limited to |
forceSign | - optional, defaults to false, if true the + sign is added for +ve numbers |
size_t SafeString::println | ( | double | , |
int | = 2 |
||
) |
size_t SafeString::println | ( | int | , |
int | = DEC |
||
) |
size_t SafeString::println | ( | long | , |
int | = DEC |
||
) |
size_t SafeString::println | ( | SafeString & | str | ) |
size_t SafeString::println | ( | unsigned char | , |
int | = DEC |
||
) |
size_t SafeString::println | ( | unsigned int | , |
int | = DEC |
||
) |
size_t SafeString::println | ( | unsigned long | , |
int | = DEC |
||
) |
size_t SafeString::println | ( | void | ) |
|
protected |
size_t SafeString::printTo | ( | Print & | p | ) | const |
Implements the Printable interface.
p | - where to print to |
void SafeString::processBackspaces | ( | void | ) |
recursively remove backspaces, '\b' and the preceeding char.
useful for processing inputs from terminal (Telent) connections
unsigned char SafeString::read | ( | Stream & | input | ) |
reads from the Stream (if chars available) into the SafeString.
The is NON-BLOCKING and returns immediately if nothing available to be read Note: if the SafeString is already full, then nothing will be read and false will be returned
- | the Stream reference to read from |
unsigned int SafeString::readFrom | ( | const char * | strPtr, |
unsigned int | maxCharsToRead = ((unsigned int) -1) |
||
) |
reads from the const char* argument, starting at 0 and read up to maxCharToRead, into this SafeString.
This lets you read from a char* into a SafeString without errors if the strlen(char*) or maxCharsToRead are larger than the SafeString capacity Use sfResult.clear(); to empty the SafeString first and then sfResult.readFrom(strPtr); to read a much as you can The read stops at first '\0' or the calling SafeString is full or when maxCharsToRead have been read. Note: if the SafeString is already full, then nothing will be read
strPtr | - pointer char array to read from |
maxCharsToRead | – the maximum chars to read into the SafeString, defaults to ((unsigned int)-1) i.e. max unsigned int. |
unsigned int SafeString::readFrom | ( | SafeString & | sfInput, |
unsigned int | startIdx = 0 |
||
) |
reads from the SafeString argument, starting at startIdx, into this SafeString.
The read stops when the end of the SafeString argument is reached or the calling SafeString is full Note: if the SafeString is already full, then nothing will be read and startIdx will be returned
Note: to limit the number of chars read in from sfInput (starting at 0), use
sfStr.readFrom(sfInput.c_str(),maxCharsToRead);
sfInput | - the SafeString to read from |
startIdx | - where to start reading from, defaults to 0, if startIdx >= sfInput.length(), nothing read and sfInput.length() returned |
unsigned char SafeString::readUntil | ( | Stream & | input, |
const char * | delimiters | ||
) |
reads chars into this SafeString until either it is full OR a delimiter is read OR there are no more chars available
returns true if a delimiter found or SafeString is full, else false
if a delimiter is found it is returned at the end of the SafeString
Only at most one delimiter is added per call
Multiple sucessive delimiters require multiple calls to read them
input | - the Stream reference to read from |
delimiters | - the string containing the characters any one of which can be a delimieter |
unsigned char SafeString::readUntil | ( | Stream & | input, |
const char | delimiter | ||
) |
reads chars into this SafeString until either it is full OR a delimiter is read OR there are no more chars available
returns true if a delimiter found or SafeString is full, else false
if a delimiter is found it is returned at the end of the SafeString
Only at most one delimiter is added per call
Multiple sucessive delimiters require multiple calls to read them
input | - the Stream reference to read from |
delimiter | - the char which is the delimieter |
unsigned char SafeString::readUntil | ( | Stream & | input, |
SafeString & | delimiters | ||
) |
reads chars into this SafeString until either it is full OR a delimiter is read OR there are no more chars available
returns true if a delimiter found or SafeString is full, else false
if a delimiter is found it is returned at the end of the SafeString
Only at most one delimiter is added per call
Multiple sucessive delimiters require multiple calls to read them
input | - the Stream reference to read from |
delimiters | - the SafeString containing the characters any one of which can be a delimieter |
unsigned char SafeString::readUntilToken | ( | Stream & | input, |
SafeString & | token, | ||
const char * | delimiters, | ||
bool & | skipToDelimiter, | ||
uint8_t | echoInput = false , |
||
unsigned long | timeout_ms = 0 |
||
) |
returns true if a delimited token is found, else false
ONLY delimited tokens of length less than this SafeString's capacity will return true with a non-empty token.
Streams of chars that overflow this SafeString's capacity are ignored and return an empty token on the next delimiter
A timeout can be specified to return the last un-delimited token after chars stop arriving.
The input read can be echoed back to the input Stream
You can force a skip to the next delimiter to discard partial tokens
That is this SafeString's capacity should be at least 1 more then the largest expected token.
If this SafeString OR the SafeString& token return argument is too small to hold the result, the token is returned empty and an error message output if debugging is enabled.
The delimiter is NOT included in the SafeString& token return. It will the first char of the this SafeString when readUntilToken returns true
It is recommended that the capacity of the SafeString& token argument be >= this SafeString's capacity
Each call to this method removes any leading delimiters so if you need to check the delimiter do it BEFORE the next call to readUntilToken()
input | - the Stream reference to read from |
token | - the SafeString to return the token found if any, this always cleared at the start of this method |
delimiters | - the string containing the characters any one of which can be a delimieter |
skipToDelimiter | - a bool reference variable to hold the skipToDelimiter state between calls If this is true all chars upto the next delimiter (or timeout) will be discarded and false returned with an empty token |
echoInput | - defaults to false, pass non-zero (true) to echo the chars read back to the input Stream |
timeout_ms | - defaults to never timeout, pass a non-zero ms to auto-terminate the last token if no new chars received for that time. |
unsigned char SafeString::readUntilToken | ( | Stream & | input, |
SafeString & | token, | ||
const char | delimiter, | ||
bool & | skipToDelimiter, | ||
uint8_t | echoInput = false , |
||
unsigned long | timeout_ms = 0 |
||
) |
returns true if a delimited token is found, else false
ONLY delimited tokens of length less than this SafeString's capacity will return true with a non-empty token.
Streams of chars that overflow this SafeString's capacity are ignored and return an empty token on the next delimiter
A timeout can be specified to return the last un-delimited token after chars stop arriving.
The input read can be echoed back to the input Stream
You can force a skip to the next delimiter to discard partial tokens
That is this SafeString's capacity should be at least 1 more then the largest expected token.
If this SafeString OR the SafeString& token return argument is too small to hold the result, the token is returned empty and an error message output if debugging is enabled.
The delimiter is NOT included in the SafeString& token return. It will the first char of the this SafeString when readUntilToken returns true
It is recommended that the capacity of the SafeString& token argument be >= this SafeString's capacity
Each call to this method removes any leading delimiters so if you need to check the delimiter do it BEFORE the next call to readUntilToken()
input | - the Stream reference to read from |
token | - the SafeString to return the token found if any, this always cleared at the start of this method |
delimiter | - the char which is the delimieter |
skipToDelimiter | - a bool reference variable to hold the skipToDelimiter state between calls If this is true all chars upto the next delimiter (or timeout) will be discarded and false returned with an empty token |
echoInput | - defaults to false, pass non-zero (true) to echo the chars read back to the input Stream |
timeout_ms | - defaults to never timeout, pass a non-zero ms to auto-terminate the last token if no new chars received for that time. |
unsigned char SafeString::readUntilToken | ( | Stream & | input, |
SafeString & | token, | ||
SafeString & | delimiters, | ||
bool & | skipToDelimiter, | ||
uint8_t | echoInput = false , |
||
unsigned long | timeout_ms = 0 |
||
) |
returns true if a delimited token is found, else false
ONLY delimited tokens of length less than this SafeString's capacity will return true with a non-empty token.
Streams of chars that overflow this SafeString's capacity are ignored and return an empty token on the next delimiter
A timeout can be specified to return the last un-delimited token after chars stop arriving.
The input read can be echoed back to the input Stream
You can force a skip to the next delimiter to discard partial tokens
That is this SafeString's capacity should be at least 1 more then the largest expected token.
If this SafeString OR the SafeString& token return argument is too small to hold the result, the token is returned empty and an error message output if debugging is enabled.
The delimiter is NOT included in the SafeString& token return. It will the first char of the this SafeString when readUntilToken returns true
It is recommended that the capacity of the SafeString& token argument be >= this SafeString's capacity
Each call to this method removes any leading delimiters so if you need to check the delimiter do it BEFORE the next call to readUntilToken()
input | - the Stream reference to read from |
token | - the SafeString to return the token found if any, this always cleared at the start of this method |
delimiters | - the SafeString containing the characters any one of which can be a delimieter |
skipToDelimiter | - a bool reference variable to hold the skipToDelimiter state between calls If this is true all chars upto the next delimiter (or timeout) will be discarded and false returned with an empty token |
echoInput | - defaults to false, pass non-zero (true) to echo the chars read back to the input Stream |
timeout_ms | - defaults to never timeout, pass a non-zero ms to auto-terminate the last token if no new chars received for that time. |
void SafeString::remove | ( | unsigned int | index | ) |
remove all chars from index to the end of the SafeString (inclusive)
void SafeString::remove | ( | unsigned int | index, |
unsigned int | count | ||
) |
remove count chars starting from index
void SafeString::removeBefore | ( | unsigned int | startIndex | ) |
void SafeString::removeFrom | ( | unsigned int | startIndex | ) |
remove all chars from startIndex to the end of the SafeString (inclusive)
void SafeString::removeLast | ( | unsigned int | count | ) |
remove the last count chars
count | - the number of chars to remove 0 to length() is valid for count count >= length() clears the SafeString count > length() raises and error |
void SafeString::replace | ( | char | findChar, |
char | replaceChar | ||
) |
replace the findChar with the replaceChar
findChar | - the char to be replaced |
replaceChar | - the char to replace it |
void SafeString::replace | ( | const char * | findStr, |
const char * | replaceStr | ||
) |
replace the findStr string with the replace string
findStr | - the string to be replaced |
replaceStr | - the string to replace it |
void SafeString::replace | ( | const char | findChar, |
const char * | replaceStr | ||
) |
replace the findChar with the replace string
findChar | - the char to be replaced |
replaceStr | - the string to replace it |
void SafeString::replace | ( | const char | findChar, |
SafeString & | sfReplace | ||
) |
replace the findChar with the sfReplace SafeString contents
findChar | - the char to be replaced |
sfReplace | - the SafeString whose contents will replace it |
void SafeString::replace | ( | SafeString & | sfFind, |
SafeString & | sfReplace | ||
) |
replace the occurances of the sfFind string, with the sfReplace SafeString contents
sfFind | - the SafeString containing the string of chars to be replaced |
sfReplace | - the SafeString whose contents will replace it |
unsigned char SafeString::reserve | ( | unsigned int | size | ) |
Checks there is enough free space in this SafeString for the current operation.
size | - total number of chars that will be in the SafeString if the operation completes |
void SafeString::setCharAt | ( | unsigned int | index, |
char | c | ||
) |
sets the char at that location in this SafeString.
index | - the zero based index of the char to return. |
c | - the char to set at that index. '\0' chars are ignored and an error raised. |
|
protected |
|
static |
Turns on Error msgs and debug( ) output for all SafeStrings.
This also sets output for the debug( ) method.
debugOut | - where to send the messages to, usually Serial, e.g. SafeString::setOutput(Serial); |
verbose | - optional, if missing defaults to true, use false for compact error messages or call setVerbose(false) |
|
static |
Controls size of error messages, setOutput sets verbose to true.
verbose | - true for detailed error messages, else short error messages. |
unsigned char SafeString::startsWith | ( | const char * | str2, |
unsigned int | fromIndex = 0 |
||
) |
returns non-zero of this SafeString starts this argument looking from fromIndex onwards.
str | – string to check for |
fromIndex | – where in the SafeString to start looking, default 0, that is start from beginning |
unsigned char SafeString::startsWith | ( | const char | c, |
unsigned int | fromIndex = 0 |
||
) |
returns non-zero of this SafeString starts this argument looking from fromIndex onwards.
c | – char to check for |
fromIndex | – where in the SafeString to start looking, default 0, that is start from beginning |
unsigned char SafeString::startsWith | ( | SafeString & | s2, |
unsigned int | fromIndex = 0 |
||
) |
returns non-zero of this SafeString starts this argument looking from fromIndex onwards.
s | – the SafeString to check for |
fromIndex | – where in the SafeString to start looking, default 0, that is start from beginning |
unsigned char SafeString::startsWithIgnoreCase | ( | const char * | str2, |
unsigned int | fromIndex = 0 |
||
) |
returns non-zero of this SafeString starts this argument, ignoring case, looking from fromIndex onwards.
str | – string to check for, ignoring case |
fromIndex | – where in the SafeString to start looking, default 0, that is start from beginning |
unsigned char SafeString::startsWithIgnoreCase | ( | const char | c, |
unsigned int | fromIndex = 0 |
||
) |
returns non-zero of this SafeString starts this argument, ignoring case, looking from fromIndex onwards.
c | – char to check for, ignoring case |
fromIndex | – where in the SafeString to start looking, default 0, that is start from beginning |
unsigned char SafeString::startsWithIgnoreCase | ( | SafeString & | s2, |
unsigned int | fromIndex = 0 |
||
) |
returns non-zero of this SafeString starts this argument, ignoring case, looking from fromIndex onwards.
s | – SafeString to check for, ignoring case |
fromIndex | – where in the SafeString to start looking, default 0, that is start from beginning |
int SafeString::stoken | ( | SafeString & | token, |
unsigned int | fromIndex, | ||
const char * | delimiters, | ||
bool | returnEmptyFields = false , |
||
bool | useAsDelimiters = true |
||
) |
break into the SafeString into tokens using the delimiters, the end of the SafeString is always a delimiter
Any leading delimiters are first stepped over and then the delimited token is return in the token argument (less the delimiter).
The token argument is always cleared at the start of the stoken().
if there are any argument errors or the token does not have the capacity to hold the substring, hasError() is set on both this SafeString and the token SafeString
token | - the SafeString to return the token in, it is cleared if no delimited token found or if there are errors The found delimited token (less the delimiter) is returned in the token SafeString argument if there is capacity. The token's capacity should be >= this SafeString's capacity incase the entire SafeString needs to be returned. If the token's capacity is < the next token, then token is returned empty and an error messages printed if debug is enabled. in this case the return (nextIndex) is still updated. |
fromIndex | - where to start the search from 0 to length() and -1 is valid for fromIndex, -1 => length() for processing |
delimiters | - the string containing the characters that any one of which can delimit a token. The end of the SafeString is always a delimiter. |
returnEmptyFields | - default false, if true only skip one leading delimiter after each call. If the fromIndex is 0 and there is a delimiter at the beginning of the SafeString, an empty token will be returned |
useAsDelimiters | - default true, if false then token will consists of only chars in the delimiters and any other char terminates the token |
int SafeString::stoken | ( | SafeString & | token, |
unsigned int | fromIndex, | ||
const char | delimiter, | ||
bool | returnEmptyFields = false , |
||
bool | useAsDelimiters = true |
||
) |
break into the SafeString into tokens using the char delimiter, the end of the SafeString is always a delimiter
Any leading delimiters are first stepped over and then the delimited token is return in the token argument (less the delimiter).
The token argument is always cleared at the start of the stoken().
if there are any argument errors or the token does not have the capacity to hold the substring, hasError() is set on both this SafeString and the token SafeString
token | - the SafeString to return the token in, it is cleared if no delimited token found or if there are errors The found delimited token (less the delimiter) is returned in the token SafeString argument if there is capacity. The token's capacity should be >= this SafeString's capacity incase the entire SafeString needs to be returned. If the token's capacity is < the next token, then token is returned empty and an error messages printed if debug is enabled. in this case the return (nextIndex) is still updated. |
fromIndex | - where to start the search from 0 to length() and -1 is valid for fromIndex, -1 => length() for processing |
delimiter | - the char that delimits a token. The end of the SafeString is always a delimiter. |
returnEmptyFields | - default false, if true only skip one leading delimiter after each call. If the fromIndex is 0 and there is a delimiter at the beginning of the SafeString, an empty token will be returned |
useAsDelimiters | - default true, if false then token will consists of only chars in the delimiters and any other char terminates the token |
int SafeString::stoken | ( | SafeString & | token, |
unsigned int | fromIndex, | ||
SafeString & | delimiters, | ||
bool | returnEmptyFields = false , |
||
bool | useAsDelimiters = true |
||
) |
break into the SafeString into tokens using the delimiters, the end of the SafeString is always a delimiter
Any leading delimiters are first stepped over and then the delimited token is return in the token argument (less the delimiter).
The token argument is always cleared at the start of the stoken().
if there are any argument errors or the token does not have the capacity to hold the substring, hasError() is set on both this SafeString and the token SafeString
token | - the SafeString to return the token in, it is cleared if no delimited token found or if there are errors The found delimited token (less the delimiter) is returned in the token SafeString argument if there is capacity. The token's capacity should be >= this SafeString's capacity incase the entire SafeString needs to be returned. If the token's capacity is < the next token, then token is returned empty and an error messages printed if debug is enabled. in this case the return (nextIndex) is still updated. |
fromIndex | - where to start the search from 0 to length() and -1 is valid for fromIndex, -1 => length() for processing |
delimiters | - the SafeString containing the characters that any one of which can delimit a token. The end of the SafeString is always a delimiter. |
returnEmptyFields | - default false, if true only skip one leading delimiter after each call. If the fromIndex is 0 and there is a delimiter at the beginning of the SafeString, an empty token will be returned |
useAsDelimiters | - default true, if false then token will consists of only chars in the delimiters and any other char terminates the token |
SafeString& SafeString::substring | ( | SafeString & | result, |
unsigned int | beginIdx | ||
) |
The result is the substring from the beginIdx to the end of the SafeString.
result | - the substring |
beginIdx | - the index of the start of the substring, if beginIdx == length(), the result is empty (no error) if beginIdx > length(), the result is empty and an error is raised. if beginIdx == (unsigned int)(-1),the result is empty (no error). |
The result SafeString is ALWAYS cleares to start with and so will be empty if there are any errors.
If the result SafeString does not have the capacity to hold the substring, an empty result is returned and an error raised on both this SafeString and the result.
You can take a substring of yourself e.g.
sfStr.substring(sfStr,3);
SafeString& SafeString::substring | ( | SafeString & | result, |
unsigned int | beginIdx, | ||
unsigned int | endIdx | ||
) |
The result is the substring from the beginIdx to endIdx (exclusive), that is the endIdx is NOT included.
result | - the substring |
beginIdx | - the index of the start of the substring, if beginIdx == length(), the result is empty (no error) if beginIdx > length(), the result is empty and an error is raised. if beginIdx == (unsigned int)(-1),the result is empty (no error). if beginIdx > endIdx, beginIdx and endIdx will be swapped so that beginIdx <= endIdx and the error flag is set on both this SafeString and the result SafeString |
endIdx | - the index after the end of the substring, that is endIdx is NOT included if endIdx > length(), endIdx is set to length(); and the error flag is set on both this SafeString and the result SafeString if endIdx == (unsigned int)(-1) is treated as endIdx == length() returns a result without an error |
The result SafeString is ALWAYS cleares to start with and so will be empty if there are any errors.
If the result SafeString does not have the capacity to hold the substring, an empty result is returned and an error raised on both this SafeString and the result.
You can take a substring of yourself e.g.
sfStr.substring(sfStr,3);
unsigned char SafeString::toDouble | ( | double & | d | ) |
convert the SafeString to a float assuming the SafeString in the decimal format (not scientific)
d | – double reference, where the result is stored. l is only updated if the conversion is successful |
unsigned char SafeString::toFloat | ( | float & | f | ) |
convert the SafeString to a float assuming the SafeString in the decimal format (not scientific)
f | – float reference, where the result is stored. l is only updated if the conversion is successful |
unsigned char SafeString::toInt | ( | int & | i | ) |
convert the SafeString to an int.
i | – int reference, where the result is stored. i is only updated if the conversion is successful |
unsigned char SafeString::toLong | ( | long & | l | ) |
convert the SafeString to a long.
l | – long reference, where the result is stored. l is only updated if the conversion is successful |
void SafeString::toLowerCase | ( | void | ) |
convert this SafeString to all lower case
unsigned char SafeString::toUnsignedLong | ( | unsigned long & | l | ) |
convert the SafeString to an unsigned long.
l | – long reference, where the result is stored. l is only updated if the conversion is successful |
void SafeString::toUpperCase | ( | void | ) |
convert this SafeString to all lower case
void SafeString::trim | ( | void | ) |
remove all white space from the front and back of this SafeString.
The C method isspace() is used. For the 'C' local the following are trimmed
' ' (0x20) space (SPC)
'\t' (0x09) horizontal tab (TAB)
'\n' (0x0a) newline (LF)
'\v' (0x0b) vertical tab (VT)
'\f' (0x0c) feed (FF)
'\r' (0x0d) carriage return (CR)
|
static |
Turns off all debugging messages, both error messages AND debug() method output.
Errors are still detected and flagged.
|
virtual |
Write (concatinate) bytes to this SafeString, from Print class.
'\0' bytes are not allowed and will be skipped over and will raise an error.
buffer | - bytes to concatinate to this SafeString |
length | - number of bytes to concatinate |
|
virtual |
Write (concatinate) a byte to this SafeString, from Print class.
'\0' bytes are not allowed and will not be added to the SafeString and will raise an error.
b | - the byte to concatinate to this SafeString |
unsigned int SafeString::writeTo | ( | SafeString & | output, |
unsigned int | startIdx = 0 |
||
) |
writes from this SafeString, starting from startIdx, into the SafeString output arguement.
The write stops when the end if the calling SafeString is reached or the output is full Note: if the output is already full, then nothing will be written and startIdx will be returned unchanged
output | - the SafeString to write to |
startIdx | - where to start writing from in the calling SafeString, defaults to 0, if startIdx >= length(), nothing written and length() returned |
|
protected |
Definition at line 1885 of file SafeString.h.
|
protected |
Definition at line 1884 of file SafeString.h.
|
staticprotected |
Definition at line 1904 of file SafeString.h.
|
staticprotected |
Definition at line 1882 of file SafeString.h.
|
staticprotected |
Definition at line 1902 of file SafeString.h.
|
staticprotected |
Definition at line 1883 of file SafeString.h.
|
protected |
Definition at line 1886 of file SafeString.h.
|
static |
Definition at line 1924 of file SafeString.h.