Skip to content

Commit 3f1ab1f

Browse files
middelinkigrr
authored andcommitted
Updated String library to use C++11 iterators. (esp8266#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); ```
1 parent 98fe561 commit 3f1ab1f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

cores/esp8266/WString.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ class String {
207207
void toCharArray(char *buf, unsigned int bufsize, unsigned int index = 0) const {
208208
getBytes((unsigned char *) buf, bufsize, index);
209209
}
210-
const char * c_str() const {
211-
return buffer;
212-
}
210+
const char* c_str() const { return buffer; }
211+
char* begin() { return buffer; }
212+
char* end() { return buffer + length(); }
213+
const char* begin() const { return c_str(); }
214+
const char* end() const { return c_str() + length(); }
213215

214216
// search
215217
int indexOf(char ch) const;

0 commit comments

Comments
 (0)