From d64f8eb570177966eea89e1993348f105ec05c21 Mon Sep 17 00:00:00 2001 From: Ivan-Perez Date: Thu, 12 May 2016 10:57:14 +0200 Subject: [PATCH 1/3] WString.h: Add const qualifier to `begin` and `end` functions --- hardware/arduino/avr/cores/arduino/WString.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/WString.h b/hardware/arduino/avr/cores/arduino/WString.h index b7d3852ba82..89fcaa5e5b3 100644 --- a/hardware/arduino/avr/cores/arduino/WString.h +++ b/hardware/arduino/avr/cores/arduino/WString.h @@ -160,9 +160,9 @@ class String void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; 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; } - const char* begin() { return c_str(); } - const char* end() { return c_str() + length(); } + const char* c_str() const { return buffer; } + const char* begin() const { return c_str(); } + const char* end() const { return c_str() + length(); } // search int indexOf( char ch ) const; From ed4b19c8f2eb3196c9fea878e2522012614a2beb Mon Sep 17 00:00:00 2001 From: Ivan-Perez Date: Thu, 12 May 2016 13:27:56 +0200 Subject: [PATCH 2/3] WString.h: allow modifying the string while iterating --- hardware/arduino/avr/cores/arduino/WString.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hardware/arduino/avr/cores/arduino/WString.h b/hardware/arduino/avr/cores/arduino/WString.h index 89fcaa5e5b3..de5632c12c1 100644 --- a/hardware/arduino/avr/cores/arduino/WString.h +++ b/hardware/arduino/avr/cores/arduino/WString.h @@ -159,8 +159,10 @@ class String char& operator [] (unsigned int index); void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const - {getBytes((unsigned char *)buf, bufsize, index);} + { 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(); } From ce5d5717aa3f77c18041719fc92b3f03db588295 Mon Sep 17 00:00:00 2001 From: Christopher Andrews Date: Thu, 12 May 2016 21:43:53 +1000 Subject: [PATCH 3/3] Modified begin() & end() for read/write begin() and end() only allowed read access, these changes now allow both. --- hardware/arduino/sam/cores/arduino/WString.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/WString.h b/hardware/arduino/sam/cores/arduino/WString.h index b7d3852ba82..86cd4c64ad5 100644 --- a/hardware/arduino/sam/cores/arduino/WString.h +++ b/hardware/arduino/sam/cores/arduino/WString.h @@ -161,8 +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; } - const char* begin() { return c_str(); } - const char* end() { return c_str() + length(); } + 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;