@@ -44,6 +44,8 @@ enum LookaheadMode{
4444 SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped.
4545};
4646
47+ #define NO_IGNORE_CHAR ' \x01 ' // a char not found in a valid ASCII numeric field
48+
4749class Stream : public Print
4850{
4951 protected:
@@ -74,19 +76,22 @@ class Stream : public Print
7476 // returns true if target string is found, false if timed out
7577
7678 bool find (char target) { return find (&target, 1 ); }
77-
79+
7880 bool findUntil (char *target, char *terminator); // as find but search ends if the terminator string is found
7981 bool findUntil (uint8_t *target, char *terminator) { return findUntil ((char *)target, terminator); }
8082
8183 bool findUntil (char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
8284 bool findUntil (uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil ((char *)target, targetLen, terminate, termLen); }
8385
86+ long parseInt (LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
87+ // returns the first valid (long) integer value from the current position.
88+ // lookahead determines how parseInt looks ahead in the stream.
89+ // See LookaheadMode enumeration at the top of the file.
90+ // Lookahead is terminated by the first character that is not a valid part of an integer.
91+ // Once parsing commences, 'ignore' will be skipped in the stream.
8492
85- long parseInt (LookaheadMode lookahead = SKIP_ALL); // returns the first valid (long) integer value from the current position.
86- // initial characters that are not digits (or the minus sign) are skipped
87- // integer is terminated by the first character that is not a digit.
88-
89- float parseFloat (LookaheadMode lookahead = SKIP_ALL); // float version of parseInt
93+ float parseFloat (LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
94+ // float version of parseInt
9095
9196 size_t readBytes ( char *buffer, size_t length); // read chars from stream into buffer
9297 size_t readBytes ( uint8_t *buffer, size_t length) { return readBytes ((char *)buffer, length); }
@@ -104,12 +109,10 @@ class Stream : public Print
104109
105110 protected:
106111 long parseInt (char ignore) { return parseInt (SKIP_ALL, ignore); }
107- long parseInt (LookaheadMode lookahead, char ignore); // as above but the given ignore is ignored
108- // as above but 'ignore' is ignored
109- // this allows format characters (typically commas) in values to be ignored
110-
111- float parseFloat (char ignore) { return parseFloat (SKIP_ALL, ignore); }
112- float parseFloat (LookaheadMode lookahead, char ignore); // as above but the given ignore is ignored
112+ float parseFloat (char ignore) { return parseFloat (SKIP_ALL, ignore); }
113+ // These overload exists for compatibility with any class that has derived
114+ // Stream and used parseFloat/Int with a custom ignore character. To keep
115+ // the public API simple, these overload remains protected.
113116
114117 struct MultiTarget {
115118 const char *str; // string you're searching for
@@ -122,4 +125,5 @@ class Stream : public Print
122125 int findMulti (struct MultiTarget *targets, int tCount);
123126};
124127
128+ #undef NO_IGNORE_CHAR
125129#endif
0 commit comments