File tree 2 files changed +10
-7
lines changed
2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -54,14 +54,17 @@ int Stream::timedPeek()
54
54
55
55
// returns peek of the next digit in the stream or -1 if timeout
56
56
// discards non-numeric characters
57
- int Stream::peekNextDigit ()
57
+ int Stream::peekNextDigit ( bool detectDecimal )
58
58
{
59
59
int c;
60
60
while (1 ) {
61
61
c = timedPeek ();
62
- if (c < 0 ) return c; // timeout
63
- if (c == ' -' ) return c;
64
- if (c >= ' 0' && c <= ' 9' ) return c;
62
+
63
+ if ( c < 0 ||
64
+ c == ' -' ||
65
+ c >= ' 0' && c <= ' 9' ||
66
+ detectDecimal && c == ' .' ) return c;
67
+
65
68
read (); // discard non-numeric
66
69
}
67
70
}
@@ -124,7 +127,7 @@ long Stream::parseInt(char skipChar)
124
127
long value = 0 ;
125
128
int c;
126
129
127
- c = peekNextDigit ();
130
+ c = peekNextDigit (false );
128
131
// ignore non numeric leading characters
129
132
if (c < 0 )
130
133
return 0 ; // zero returned if timeout
@@ -162,7 +165,7 @@ float Stream::parseFloat(char skipChar){
162
165
char c;
163
166
float fraction = 1.0 ;
164
167
165
- c = peekNextDigit ();
168
+ c = peekNextDigit (true );
166
169
// ignore non numeric leading characters
167
170
if (c < 0 )
168
171
return 0 ; // zero returned if timeout
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ class Stream : public Print
42
42
unsigned long _startMillis; // used for timeout measurement
43
43
int timedRead (); // private method to read stream with timeout
44
44
int timedPeek (); // private method to peek stream with timeout
45
- int peekNextDigit (); // returns the next numeric digit in the stream or -1 if timeout
45
+ int peekNextDigit ( bool detectDecimal ); // returns the next numeric digit in the stream or -1 if timeout
46
46
47
47
public:
48
48
virtual int available () = 0;
You can’t perform that action at this time.
0 commit comments