From 3f1ab1fd8187910a505f3d3308fb235a57ee9fe8 Mon Sep 17 00:00:00 2001 From: Pauline Middelink Date: Mon, 18 Jul 2016 13:31:34 +0200 Subject: [PATCH] Updated String library to use C++11 iterators. (#2267) This will allow using the String library in a ranged for loop: ```C++ String s("Hi, this is a test"); for (const char& ch : s) { Serial.print(ch); } ``` and even modify ```C++ String s("Hi, this is another test"); for (char& ch : s) { ch++; } Serial.println(s); ``` --- cores/esp8266/WString.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index 3f216cee4..a3bb40c13 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -207,9 +207,11 @@ 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* 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;