Skip to content

Fix for Issue #1962 #2007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 4 additions & 3 deletions hardware/arduino/cores/arduino/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ 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::skipUntilDigit(bool detectPointChar)
{
int c;
while (1) {
c = timedPeek();
if (c < 0) return c; // timeout
if (c == '-') return c;
if (c >= '0' && c <= '9') return c;
if (detectPointChar == true && c == '.') return c;
read(); // discard non-numeric
}
}
Expand Down Expand Up @@ -141,7 +142,7 @@ long Stream::parseInt(char skipChar)
long value = 0;
int c;

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

c = peekNextDigit();
c = skipUntilDigit(true);
// ignore non numeric leading characters
if(c < 0)
return 0; // zero returned if timeout
Expand Down