File tree Expand file tree Collapse file tree 4 files changed +20
-14
lines changed Expand file tree Collapse file tree 4 files changed +20
-14
lines changed Original file line number Diff line number Diff line change @@ -54,14 +54,17 @@ int Stream::timedPeek()
5454
5555// returns peek of the next digit in the stream or -1 if timeout
5656// discards non-numeric characters
57- int Stream::peekNextDigit ()
57+ int Stream::peekNextDigit ( bool detectDecimal )
5858{
5959 int c;
6060 while (1 ) {
6161 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+
6568 read (); // discard non-numeric
6669 }
6770}
@@ -124,7 +127,7 @@ long Stream::parseInt(char skipChar)
124127 long value = 0 ;
125128 int c;
126129
127- c = peekNextDigit ();
130+ c = peekNextDigit (false );
128131 // ignore non numeric leading characters
129132 if (c < 0 )
130133 return 0 ; // zero returned if timeout
@@ -162,7 +165,7 @@ float Stream::parseFloat(char skipChar){
162165 char c;
163166 float fraction = 1.0 ;
164167
165- c = peekNextDigit ();
168+ c = peekNextDigit (true );
166169 // ignore non numeric leading characters
167170 if (c < 0 )
168171 return 0 ; // zero returned if timeout
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ class Stream : public Print
4242 unsigned long _startMillis; // used for timeout measurement
4343 int timedRead (); // private method to read stream with timeout
4444 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
4646
4747 public:
4848 virtual int available () = 0;
Original file line number Diff line number Diff line change @@ -54,14 +54,17 @@ int Stream::timedPeek()
5454
5555// returns peek of the next digit in the stream or -1 if timeout
5656// discards non-numeric characters
57- int Stream::peekNextDigit ()
57+ int Stream::peekNextDigit ( bool detectDecimal )
5858{
5959 int c;
6060 while (1 ) {
6161 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+
6568 read (); // discard non-numeric
6669 }
6770}
@@ -124,7 +127,7 @@ long Stream::parseInt(char skipChar)
124127 long value = 0 ;
125128 int c;
126129
127- c = peekNextDigit ();
130+ c = peekNextDigit (false );
128131 // ignore non numeric leading characters
129132 if (c < 0 )
130133 return 0 ; // zero returned if timeout
@@ -162,7 +165,7 @@ float Stream::parseFloat(char skipChar){
162165 char c;
163166 float fraction = 1.0 ;
164167
165- c = peekNextDigit ();
168+ c = peekNextDigit (true );
166169 // ignore non numeric leading characters
167170 if (c < 0 )
168171 return 0 ; // zero returned if timeout
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ class Stream : public Print
4242 unsigned long _startMillis; // used for timeout measurement
4343 int timedRead (); // private method to read stream with timeout
4444 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
4646
4747 public:
4848 virtual int available () = 0;
You can’t perform that action at this time.
0 commit comments