mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
This commit improves the parsing capability by allowing decimals only
prefixed by an '.' character. Previously the preceeding zero must be present: '0.'
This commit is contained in:
parent
7d4787bcff
commit
24a994019f
@ -54,14 +54,17 @@ 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') return c;
|
||||
|
||||
if( c < 0 ||
|
||||
c == '-' ||
|
||||
c >= '0' && c <= '9' ||
|
||||
detectDecimal && c == '.') return c;
|
||||
|
||||
read(); // discard non-numeric
|
||||
}
|
||||
}
|
||||
@ -124,7 +127,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
|
||||
@ -162,7 +165,7 @@ float Stream::parseFloat(char skipChar){
|
||||
char c;
|
||||
float fraction = 1.0;
|
||||
|
||||
c = peekNextDigit();
|
||||
c = peekNextDigit(true);
|
||||
// ignore non numeric leading characters
|
||||
if(c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
|
@ -42,7 +42,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 ); // returns the next numeric digit in the stream or -1 if timeout
|
||||
|
||||
public:
|
||||
virtual int available() = 0;
|
||||
|
@ -54,14 +54,17 @@ 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') return c;
|
||||
|
||||
if( c < 0 ||
|
||||
c == '-' ||
|
||||
c >= '0' && c <= '9' ||
|
||||
detectDecimal && c == '.') return c;
|
||||
|
||||
read(); // discard non-numeric
|
||||
}
|
||||
}
|
||||
@ -124,7 +127,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
|
||||
@ -162,7 +165,7 @@ float Stream::parseFloat(char skipChar){
|
||||
char c;
|
||||
float fraction = 1.0;
|
||||
|
||||
c = peekNextDigit();
|
||||
c = peekNextDigit(true);
|
||||
// ignore non numeric leading characters
|
||||
if(c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
|
@ -42,7 +42,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 ); // returns the next numeric digit in the stream or -1 if timeout
|
||||
|
||||
public:
|
||||
virtual int available() = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user