@@ -44,6 +44,8 @@ enum StreamParseOpt{
44
44
SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped.
45
45
};
46
46
47
+ #define NO_IGNORE_CHAR ' \x01 ' // a char not found in a valid ASCII numeric field
48
+
47
49
class Stream : public Print
48
50
{
49
51
protected:
@@ -74,19 +76,22 @@ class Stream : public Print
74
76
// returns true if target string is found, false if timed out
75
77
76
78
bool find (char target) { return find (&target, 1 ); }
77
-
79
+
78
80
bool findUntil (char *target, char *terminator); // as find but search ends if the terminator string is found
79
81
bool findUntil (uint8_t *target, char *terminator) { return findUntil ((char *)target, terminator); }
80
82
81
83
bool findUntil (char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
82
84
bool findUntil (uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil ((char *)target, targetLen, terminate, termLen); }
83
85
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.
84
92
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
90
95
91
96
size_t readBytes ( char *buffer, size_t length); // read chars from stream into buffer
92
97
size_t readBytes ( uint8_t *buffer, size_t length) { return readBytes ((char *)buffer, length); }
@@ -104,12 +109,10 @@ class Stream : public Print
104
109
105
110
protected:
106
111
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.
113
116
114
117
struct MultiTarget {
115
118
const char *str; // string you're searching for
@@ -122,4 +125,5 @@ class Stream : public Print
122
125
int findMulti (struct MultiTarget *targets, int tCount);
123
126
};
124
127
128
+ #undef NO_IGNORE_CHAR
125
129
#endif
0 commit comments