1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-07 16:23:38 +03:00

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);
```
This commit is contained in:
Pauline Middelink 2016-07-18 13:31:34 +02:00 committed by Ivan Grokhotkov
parent 98fe5617eb
commit 3f1ab1fd81

View File

@ -207,9 +207,11 @@ class String {
void toCharArray(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 { const char* c_str() const { return buffer; }
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 // search
int indexOf(char ch) const; int indexOf(char ch) const;