diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2011-03-11 18:54:58 -0500 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2011-03-11 18:54:58 -0500 |
commit | b4b32f60f1c156e76117dab69479c193a861be23 (patch) | |
tree | 60198d3bb0333bd427c0b16b7c91db99349e0afc /cores/arduino | |
parent | 99e0c131fc0bc286e42e848d56beceb3add66e93 (diff) |
Don't return the string when modifying its value.
Changing toLowerCase(), toUpperCase(), trim() and replace() to return void instead of a reference to the string that's just been changed. That way, it's clear that the functions modify the string they've been called on.
Diffstat (limited to 'cores/arduino')
-rw-r--r-- | cores/arduino/WString.cpp | 29 | ||||
-rw-r--r-- | cores/arduino/WString.h | 10 |
2 files changed, 17 insertions, 22 deletions
diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index 46efbf5..e9f71d1 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -550,18 +550,17 @@ String String::substring(unsigned int left, unsigned int right) const /* Modification */ /*********************************************/ -String & String::replace(char find, char replace) +void String::replace(char find, char replace) { - if (!buffer) return *this; + if (!buffer) return; for (char *p = buffer; *p; p++) { if (*p == find) *p = replace; } - return *this; } -String & String::replace(const String& find, const String& replace) +void String::replace(const String& find, const String& replace) { - if (len == 0 || find.len == 0) return *this; + if (len == 0 || find.len == 0) return; int diff = replace.len - find.len; char *readFrom = buffer; char *foundAt; @@ -588,8 +587,8 @@ String & String::replace(const String& find, const String& replace) readFrom = foundAt + find.len; size += diff; } - if (size == len) return *this; - if (size > capacity && !changeBuffer(size)) return *this; + if (size == len) return; + if (size > capacity && !changeBuffer(size)) return; // XXX: tell user! int index = len - 1; while ((index = lastIndexOf(find, index)) >= 0) { readFrom = buffer + index + find.len; @@ -600,30 +599,27 @@ String & String::replace(const String& find, const String& replace) index--; } } - return *this; } -String & String::toLowerCase(void) +void String::toLowerCase(void) { - if (!buffer) return *this; + if (!buffer) return; for (char *p = buffer; *p; p++) { *p = tolower(*p); } - return *this; } -String & String::toUpperCase(void) +void String::toUpperCase(void) { - if (!buffer) return *this; + if (!buffer) return; for (char *p = buffer; *p; p++) { *p = toupper(*p); } - return *this; } -String & String::trim(void) +void String::trim(void) { - if (!buffer || len == 0) return *this; + if (!buffer || len == 0) return; char *begin = buffer; while (isspace(*begin)) begin++; char *end = buffer + len - 1; @@ -631,7 +627,6 @@ String & String::trim(void) len = end + 1 - begin; if (begin > buffer) memcpy(buffer, begin, len); buffer[len] = 0; - return *this; } /*********************************************/ diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h index 4a680e2..164eeac 100644 --- a/cores/arduino/WString.h +++ b/cores/arduino/WString.h @@ -139,11 +139,11 @@ public: String substring( unsigned int beginIndex, unsigned int endIndex ) const; // modification - String & replace(char find, char replace); - String & replace(const String& find, const String& replace); - String & toLowerCase(void); - String & toUpperCase(void); - String & trim(void); + void replace(char find, char replace); + void replace(const String& find, const String& replace); + void toLowerCase(void); + void toUpperCase(void); + void trim(void); // parsing/conversion long toInt(void) const; |