SafeString  4.1.27
SafeString is a safe, robust and debuggable replacement for string processing in Arduino
SafeStringReader Class Reference

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...
 
SafeStringReaderoperator= (char c)
 
SafeStringReaderoperator= (unsigned char c)
 
SafeStringReaderoperator= (int num)
 
SafeStringReaderoperator= (unsigned int num)
 
SafeStringReaderoperator= (long num)
 
SafeStringReaderoperator= (unsigned long num)
 
SafeStringReaderoperator= (float num)
 
SafeStringReaderoperator= (double num)
 
SafeStringReaderoperator= (SafeString &rhs)
 
SafeStringReaderoperator= (const char *cstr)
 
SafeStringReaderoperator= (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...
 
SafeStringclear (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...
 
SafeStringoperator= (char c)
 Clears this SafeString and concatinates a single char. More...
 
SafeStringoperator= (unsigned char num)
 Clears this SafeString and concatinates the text version of the argument. More...
 
SafeStringoperator= (int num)
 Clears this SafeString and concatinates the text version of the argument. More...
 
SafeStringoperator= (unsigned int num)
 Clears this SafeString and concatinates the text version of the argument. More...
 
SafeStringoperator= (long num)
 Clears this SafeString and concatinates the text version of the argument. More...
 
SafeStringoperator= (unsigned long num)
 Clears this SafeString and concatinates the text version of the argument. More...
 
SafeStringoperator= (float num)
 Clears this SafeString and concatinates the text version of the argument. More...
 
SafeStringoperator= (double num)
 Clears this SafeString and concatinates the text version of the argument. More...
 
SafeStringoperator= (SafeString &sfStr)
 Clears this SafeString and copies and concatinates the contents of the argument. More...
 
SafeStringoperator= (const char *cstr)
 Clears this SafeString and copies and concatinates the contents of the argument. More...
 
SafeStringoperator= (const __FlashStringHelper *pstr)
 Clears this SafeString and copies and concatinates the contents of the argument. More...
 
SafeStringprefix (SafeString &s)
 prefix methods add to the front of the current SafeString. More...
 
SafeStringprefix (const char *cstr)
 
SafeStringprefix (char c)
 
SafeStringprefix (unsigned char c)
 
SafeStringprefix (int num)
 
SafeStringprefix (unsigned int num)
 
SafeStringprefix (long num)
 
SafeStringprefix (unsigned long num)
 
SafeStringprefix (float num)
 
SafeStringprefix (double num)
 
SafeStringprefix (const __FlashStringHelper *str)
 
SafeStringprefix (const char *cstr, size_t length)
 
SafeStringprefix (const __FlashStringHelper *str, size_t length)
 
SafeStringconcat (SafeString &str)
 concat methods add to the end of the current SafeString. More...
 
SafeStringconcat (const char *cstr)
 
SafeStringconcat (char c)
 
SafeStringconcat (unsigned char c)
 
SafeStringconcat (int num)
 
SafeStringconcat (unsigned int num)
 
SafeStringconcat (long num)
 
SafeStringconcat (unsigned long num)
 
SafeStringconcat (float num)
 
SafeStringconcat (double num)
 
SafeStringconcat (const __FlashStringHelper *str)
 
SafeStringconcat (const char *cstr, size_t length)
 
SafeStringconcat (const __FlashStringHelper *str, size_t length)
 
SafeStringnewline ()
 Adds \r\n to this SafeString. More...
 
SafeStringoperator-= (SafeString &rhs)
 -= operator prefixes the SafeString. More...
 
SafeStringoperator-= (const char *cstr)
 
SafeStringoperator-= (char c)
 
SafeStringoperator-= (unsigned char num)
 
SafeStringoperator-= (int num)
 
SafeStringoperator-= (unsigned int num)
 
SafeStringoperator-= (long num)
 
SafeStringoperator-= (unsigned long num)
 
SafeStringoperator-= (float num)
 
SafeStringoperator-= (double num)
 
SafeStringoperator-= (const __FlashStringHelper *str)
 
SafeStringoperator+= (SafeString &rhs)
 += operator concatinate to the SafeString. More...
 
SafeStringoperator+= (const char *cstr)
 
SafeStringoperator+= (char c)
 
SafeStringoperator+= (unsigned char num)
 
SafeStringoperator+= (int num)
 
SafeStringoperator+= (unsigned int num)
 
SafeStringoperator+= (long num)
 
SafeStringoperator+= (unsigned long num)
 
SafeStringoperator+= (float num)
 
SafeStringoperator+= (double num)
 
SafeStringoperator+= (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...
 
SafeStringsubstring (SafeString &result, unsigned int beginIdx)
 The result is the substring from the beginIdx to the end of the SafeString. More...
 
SafeStringsubstring (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
SafeStringconcatln (const __FlashStringHelper *pstr)
 
SafeStringconcatln (char c)
 
SafeStringconcatln (const char *cstr, size_t length)
 
void outputName () const
 
SafeStringconcatInternal (const char *cstr, size_t length, bool assignOp=false)
 
SafeStringconcatInternal (const __FlashStringHelper *str, size_t length, bool assignOp=false)
 
SafeStringconcatInternal (const char *cstr, bool assignOp=false)
 
SafeStringconcatInternal (char c, bool assignOp=false)
 
SafeStringconcatInternal (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SafeStringReader() [1/2]

SafeStringReader::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 
)
explicit

◆ SafeStringReader() [2/2]

SafeStringReader::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 
)
explicit

Member Function Documentation

◆ connect()

void SafeStringReader::connect ( Stream &  stream)

connect(Stream& stream) specifies the Stream to read chars from params stream – the Stream to read from

◆ debugInputBuffer() [1/4]

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.

◆ debugInputBuffer() [2/4]

const char* SafeStringReader::debugInputBuffer ( const __FlashStringHelper *  title,
bool  verbose = true 
)

◆ debugInputBuffer() [3/4]

const char* SafeStringReader::debugInputBuffer ( const char *  title,
bool  verbose = true 
)

◆ debugInputBuffer() [4/4]

const char* SafeStringReader::debugInputBuffer ( SafeString stitle,
bool  verbose = true 
)

◆ echoOff()

void SafeStringReader::echoOff ( )

◆ echoOn()

void SafeStringReader::echoOn ( )

echoOn(), echoOff() control echoing back to the input Stream all chars read default if echoOff();

◆ end()

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()

◆ flushInput()

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

◆ getDelimiter()

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

◆ getReadCount()

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.

◆ isSkippingToDelimiter()

bool SafeStringReader::isSkippingToDelimiter ( )

isSkippingToDelimiter returns true if currently skipping to next delimiter

◆ operator=() [1/11]

SafeStringReader& SafeStringReader::operator= ( char  c)

◆ operator=() [2/11]

SafeStringReader& SafeStringReader::operator= ( const __FlashStringHelper *  str)

◆ operator=() [3/11]

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

◆ operator=() [4/11]

SafeStringReader& SafeStringReader::operator= ( double  num)

◆ operator=() [5/11]

SafeStringReader& SafeStringReader::operator= ( float  num)

◆ operator=() [6/11]

SafeStringReader& SafeStringReader::operator= ( int  num)

◆ operator=() [7/11]

SafeStringReader& SafeStringReader::operator= ( long  num)

◆ operator=() [8/11]

SafeStringReader& SafeStringReader::operator= ( SafeString rhs)

◆ operator=() [9/11]

SafeStringReader& SafeStringReader::operator= ( unsigned char  c)

◆ operator=() [10/11]

SafeStringReader& SafeStringReader::operator= ( unsigned int  num)

◆ operator=() [11/11]

SafeStringReader& SafeStringReader::operator= ( unsigned long  num)

◆ read()

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.

◆ returnEmptyTokens()

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

◆ setTimeout()

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

◆ skipToDelimiter()

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.