diff options
author | Chris--A <chris@genx.biz> | 2015-07-09 18:32:40 +1000 |
---|---|---|
committer | Sandeep Mistry <s.mistry@arduino.cc> | 2015-11-23 15:46:24 -0500 |
commit | 507f2ee84a04edb8b96cdb15e2a4ab23f450fa2c (patch) | |
tree | 6e3733107614c843e481e6179505fb2d43a63fe3 /cores/arduino/Stream.cpp | |
parent | db295bda6a74fddbf44520a0bb1af3ef2af3a5de (diff) |
Make protected Stream::parseInt/Float overloads public.
Stream::parseInt & Stream::parseFloat previously had protected
overloads which allowed skipping a custom character. This commit
brings this feature to the public interface.
To keep the public API simpler, the single paramter overload remains
protected. However its functionality is available in the public
interface using the two parameter overload.
Diffstat (limited to 'cores/arduino/Stream.cpp')
-rw-r--r-- | cores/arduino/Stream.cpp | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/cores/arduino/Stream.cpp b/cores/arduino/Stream.cpp index 61ad678..758b9d2 100644 --- a/cores/arduino/Stream.cpp +++ b/cores/arduino/Stream.cpp @@ -26,7 +26,6 @@ #include "Stream.h" #define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait -#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field // private method to read stream with timeout int Stream::timedRead() @@ -121,17 +120,11 @@ bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t } } - // returns the first valid (long) integer value from the current position. -// initial characters that are not digits (or the minus sign) are skipped -// function is terminated by the first character that is not a digit. -long Stream::parseInt(LookaheadMode lookahead) -{ - return parseInt(lookahead, NO_SKIP_CHAR); // terminate on first non-digit character (or timeout) -} - -// as above but 'ignore' is ignored -// this allows format characters (typically commas) in values to be ignored +// lookahead determines how parseInt looks ahead in the stream. +// See LookaheadMode enumeration at the top of the file. +// Lookahead is terminated by the first character that is not a valid part of an integer. +// Once parsing commences, 'ignore' will be skipped in the stream. long Stream::parseInt(LookaheadMode lookahead, char ignore) { bool isNegative = false; @@ -160,16 +153,9 @@ long Stream::parseInt(LookaheadMode lookahead, char ignore) return value; } - // as parseInt but returns a floating point value -float Stream::parseFloat(LookaheadMode lookahead) +float Stream::parseFloat(LookaheadMode lookahead, char ignore) { - return parseFloat(lookahead, NO_SKIP_CHAR); -} - -// as above but the given ignore is ignored -// this allows format characters (typically commas) in values to be ignored -float Stream::parseFloat(LookaheadMode lookahead, char ignore){ bool isNegative = false; bool isFraction = false; long value = 0; |