From 69a2a52ac4d88725e62df34705154ff8b52a341b Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Tue, 4 Sep 2018 11:57:53 +0200 Subject: [PATCH 1/2] WString: add `toDouble` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `toFloat` internally converts into double and then truncates into a float, so why not add a method to return the double? Signed-off-by: Iván Pérez --- cores/arduino/WString.cpp | 7 ++++++- cores/arduino/WString.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index 380a8e5033..6c341f89c5 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -742,6 +742,11 @@ long String::toInt(void) const float String::toFloat(void) const { - if (buffer) return float(atof(buffer)); + return float(toDouble()); +} + +double String::toDouble(void) const +{ + if (buffer) return atof(buffer); return 0; } diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h index 5618c0c574..140e59656b 100644 --- a/cores/arduino/WString.h +++ b/cores/arduino/WString.h @@ -186,6 +186,7 @@ class String // parsing/conversion long toInt(void) const; float toFloat(void) const; + double toDouble(void) const; protected: char *buffer; // the actual char array From acbeffbbf7df9e3acb42daa74add999576ef2c07 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Tue, 4 Sep 2018 12:00:53 +0200 Subject: [PATCH 2/2] WString: Align with Arduino Add String iterators Signed-off-by: Frederic.Pillon --- cores/arduino/WString.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h index 140e59656b..3dd590d129 100644 --- a/cores/arduino/WString.h +++ b/cores/arduino/WString.h @@ -161,6 +161,10 @@ class String void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const {getBytes((unsigned char *)buf, bufsize, index);} const char * c_str() const { return buffer; } + char* begin() { return buffer; } + char* end() { return buffer + length(); } + const char* begin() const { return c_str(); } + const char* end() const { return c_str() + length(); } // search int indexOf( char ch ) const;