Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cores/esp8266/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ int Stream::timedPeek() {

// returns peek of the next digit in the stream or -1 if timeout
// discards non-numeric characters
int Stream::peekNextDigit() {
int Stream::peekNextDigit(bool detectDecimal) {
int c;
while(1) {
c = timedPeek();
if(c < 0)
return c; // timeout
if(c == '-')
return c;
if(c >= '0' && c <= '9')
if( c < 0 || // timeout
c == '-' ||
( c >= '0' && c <= '9' ) ||
( detectDecimal && c == '.' ) ) {
return c;
}
read(); // discard non-numeric
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ long Stream::parseInt(char skipChar) {
long value = 0;
int c;

c = peekNextDigit();
c = peekNextDigit(false);
// ignore non numeric leading characters
if(c < 0)
return 0; // zero returned if timeout
Expand Down Expand Up @@ -176,7 +176,7 @@ float Stream::parseFloat(char skipChar) {
int c;
float fraction = 1.0f;

c = peekNextDigit();
c = peekNextDigit(true);
// ignore non numeric leading characters
if(c < 0)
return 0; // zero returned if timeout
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Stream: public Print {
unsigned long _startMillis; // used for timeout measurement
int timedRead(); // private method to read stream with timeout
int timedPeek(); // private method to peek stream with timeout
int peekNextDigit(); // returns the next numeric digit in the stream or -1 if timeout
int peekNextDigit(bool detectDecimal = false); // returns the next numeric digit in the stream or -1 if timeout

public:
virtual int available() = 0;
Expand Down