Skip to content

Commit

Permalink
Updated String library to use C++11 iterators. (esp8266#2267)
Browse files Browse the repository at this point in the history
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);
```
  • Loading branch information
middelink authored and igrr committed Jul 18, 2016
1 parent 98fe561 commit 3f1ab1f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cores/esp8266/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3f1ab1f

Please sign in to comment.