SafeString
4.1.27
SafeString is a safe, robust and debuggable replacement for string processing in Arduino
|
To create a SafeStringReader use the macro createSafeStringReader see the detailed description. More...
#include <SafeStringReader.h>
Inherits SafeString.
Public Member Functions | |
SafeStringReader (SafeString &_sfInput, size_t bufSize, char *tokenBuf, const char *_name, const char *delimiters, bool skipToDelimiterFlag=false, uint8_t echoInput=false, unsigned long timeout_ms=0) | |
SafeStringReader (SafeString &_sfInput, size_t bufSize, char *tokenBuf, const char *_name, const char delimiter, bool skipToDelimiterFlag=false, uint8_t echoInput=false, unsigned long timeout_ms=0) | |
void | connect (Stream &stream) |
connect(Stream& stream) specifies the Stream to read chars from params stream – the Stream to read from More... | |
void | setTimeout (unsigned long ms) |
setTimeout sets the timeout to wait for more chars. More... | |
bool | read () |
read() returns true if a delimited token has been read from the stream. More... | |
int | getDelimiter () |
getDelimiter() returns the delimiter that terminated the last token only valid when read() returns true will return -1 is there is none, e.g. More... | |
void | echoOn () |
echoOn(), echoOff() control echoing back to the input Stream all chars read default if echoOff(); More... | |
void | echoOff () |
void | flushInput () |
flushInput() clears any buffered input and Stream RX buffer then sets skipToDelimiterFlag true Once the next delimiter is read or if the timeout is set, the input times out, then the SafeStringReader goes back to normal input processing. More... | |
void | returnEmptyTokens (bool flag=true) |
returnEmptyTokens By default empty tokens are not returned, i.e. More... | |
bool | end () |
end() returns true if have another token, terminates last token if any, disconnect from stream, turn echo off, set timeout to 0 and clear skipToDelimiter, clears getReadCount() More... | |
size_t | getReadCount () |
getReadCount() The SafeStringReader counts the number of chars read since the last connect( ) call. More... | |
void | skipToDelimiter () |
skipToDelimiter() discards the next token read Once the next delimiter is read or if the timeout is set, the input times out, then the SafeStringReader goes back to normal input processing. More... | |
bool | isSkippingToDelimiter () |
isSkippingToDelimiter returns true if currently skipping to next delimiter More... | |
SafeStringReader & | operator= (char c) |
SafeStringReader & | operator= (unsigned char c) |
SafeStringReader & | operator= (int num) |
SafeStringReader & | operator= (unsigned int num) |
SafeStringReader & | operator= (long num) |
SafeStringReader & | operator= (unsigned long num) |
SafeStringReader & | operator= (float num) |
SafeStringReader & | operator= (double num) |
SafeStringReader & | operator= (SafeString &rhs) |
SafeStringReader & | operator= (const char *cstr) |
SafeStringReader & | operator= (const __FlashStringHelper *str) |
const char * | debugInputBuffer (bool verbose=true) |
debugInputBuffer These methods let you print out the current contents of the input buffer that the Stream is read into while waiting to read a delimiter to terminate the current token. More... | |
const char * | debugInputBuffer (const char *title, bool verbose=true) |
const char * | debugInputBuffer (const __FlashStringHelper *title, bool verbose=true) |
const char * | debugInputBuffer (SafeString &stitle, bool verbose=true) |
Public Member Functions inherited from SafeString | |
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... | |
Additional Inherited Members | |
Static Public Member Functions inherited from SafeString | |
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 inherited from SafeString | |
static SafeString::DebugPrint | Output |
Protected Member Functions inherited from SafeString | |
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 inherited from SafeString | |
char * | buffer |
size_t | _capacity |
size_t | len |
Static Protected Attributes inherited from SafeString | |
static Print * | debugPtr |
static bool | fullDebug |
static SafeString::noDebugPrint | emptyPrint |
static Print * | currentOutput |
To create a SafeStringReader use the macro createSafeStringReader see the detailed description.
The createSafeStringReader macro takes 3 or more arguments.
createSafeStringReader(name, size, delimiters); creates a SafeStringReader called name which can read tokens upto size chars and will return tokens delimited by delimiters.
e.g. to create a SafeStringReader called sfReader to handle tokens upto 80char long and return tokens delimited by comma or newline or carriageReturn use
createSafeStringReader(sfReader, 80, ",\n\r")
Other optional arguments for createSafeStringReader are better set via method calls. The examples below use the created SafeStringReader called, sfReader from above
To control echoing the input back to the input stream ( default echoOff() ) use
sfReader.echoOn();
and
sfReader.echoOff();
To set the read timeout, in ms, after which the current input will be returned as a token even if no delimiter has been found (default 0, never timeout) use
sfReader.setTimeout(ms);
To clear/flush all the pending input upto the next delimiter or timeout, use
sfReader.setTimeout(1000);
sfReader.flush();
sfReader.setTimeout(0);
While flushing, isSkipToDelimiter() will return true until a delimiter is found or the read times out, either of which terminated the flush().
See SafeStringReader for Text Input for examples
Definition at line 73 of file SafeStringReader.h.
|
explicit |
|
explicit |
void SafeStringReader::connect | ( | Stream & | stream | ) |
connect(Stream& stream) specifies the Stream to read chars from params stream – the Stream to read from
const char* SafeStringReader::debugInputBuffer | ( | bool | verbose = true | ) |
debugInputBuffer These methods let you print out the current contents of the input buffer that the Stream is read into while waiting to read a delimiter to terminate the current token.
const char* SafeStringReader::debugInputBuffer | ( | const __FlashStringHelper * | title, |
bool | verbose = true |
||
) |
const char* SafeStringReader::debugInputBuffer | ( | const char * | title, |
bool | verbose = true |
||
) |
const char* SafeStringReader::debugInputBuffer | ( | SafeString & | stitle, |
bool | verbose = true |
||
) |
void SafeStringReader::echoOff | ( | ) |
void SafeStringReader::echoOn | ( | ) |
bool SafeStringReader::end | ( | ) |
end() returns true if have another token, terminates last token if any, disconnect from stream, turn echo off, set timeout to 0 and clear skipToDelimiter, clears getReadCount()
void SafeStringReader::flushInput | ( | ) |
flushInput() clears any buffered input and Stream RX buffer then sets skipToDelimiterFlag true Once the next delimiter is read or if the timeout is set, the input times out, then the SafeStringReader goes back to normal input processing.
Note: This differs from skipToDelimiter in that is clears any buffered Stream RX first
int SafeStringReader::getDelimiter | ( | ) |
getDelimiter() returns the delimiter that terminated the last token only valid when read() returns true will return -1 is there is none, e.g.
timed out or argument error
size_t SafeStringReader::getReadCount | ( | ) |
getReadCount() The SafeStringReader counts the number of chars read since the last connect( ) call.
This can be used to terminate reading http response body when the response length is reached. end() clears the read count.
bool SafeStringReader::isSkippingToDelimiter | ( | ) |
isSkippingToDelimiter returns true if currently skipping to next delimiter
SafeStringReader& SafeStringReader::operator= | ( | char | c | ) |
SafeStringReader& SafeStringReader::operator= | ( | const __FlashStringHelper * | str | ) |
SafeStringReader& SafeStringReader::operator= | ( | const char * | cstr | ) |
SafeStringReader& SafeStringReader::operator= | ( | double | num | ) |
SafeStringReader& SafeStringReader::operator= | ( | float | num | ) |
SafeStringReader& SafeStringReader::operator= | ( | int | num | ) |
SafeStringReader& SafeStringReader::operator= | ( | long | num | ) |
SafeStringReader& SafeStringReader::operator= | ( | SafeString & | rhs | ) |
SafeStringReader& SafeStringReader::operator= | ( | unsigned char | c | ) |
SafeStringReader& SafeStringReader::operator= | ( | unsigned int | num | ) |
SafeStringReader& SafeStringReader::operator= | ( | unsigned long | num | ) |
bool SafeStringReader::read | ( | ) |
read() returns true if a delimited token has been read from the stream.
sets this SafeStringReader to that token's text. The delimiter is not returned as part of the token. Use getDelimiter() to check which char delimited this token. returnEmptyTokens() controls if empty tokens are returned. Default is to not return empty tokens, i.e. skip multiple consecutive delimiters. NOTE: this call always clears the SafeStringReader so no need to call clear() on sfReader at end of processing.
void SafeStringReader::returnEmptyTokens | ( | bool | flag = true | ) |
returnEmptyTokens By default empty tokens are not returned, i.e.
multiple consecutive delimiters are skipped calling returnEmptyTokens() or returnEmptyTokens(true) will return a token for every delimiter found (and every timeout) returnEmptyTokens(false) restores the default
void SafeStringReader::setTimeout | ( | unsigned long | ms | ) |
setTimeout sets the timeout to wait for more chars.
If no chars are received for the timeout_ms then a virtual delimiter (-1) is implied and the currently buffered text is returned as a token getDelimiter() will return -1 in this case and be used to detect a timeout.
default is 0, i.e. no timeout set. Only a delimiter will trigger the return of a token
void SafeStringReader::skipToDelimiter | ( | ) |
skipToDelimiter() discards the next token read Once the next delimiter is read or if the timeout is set, the input times out, then the SafeStringReader goes back to normal input processing.