Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WString: direct operator overloads instead of StringSumHelper #7781

Merged
merged 23 commits into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9c47a1c
wip
mcspr Dec 19, 2020
d1d584e
huh, turns out String = 'c' did some weird stuff
mcspr Dec 19, 2020
c9a55f7
style
mcspr Dec 22, 2020
7a9cf16
Merge remote-tracking branch 'origin/master' into string/no-sum-helper
mcspr Dec 22, 2020
14e1e7c
allow "blah" + String, 'c' + String and F("...") + String
mcspr Dec 22, 2020
559a5db
shuffle things into .cpp
mcspr Dec 22, 2020
6dbcfa9
trying to fix arduinojson
mcspr Dec 22, 2020
4683923
fix accidental realloc, add test for operator+
mcspr Dec 23, 2020
6a3fc86
fixup! fix accidental realloc, add test for operator+
mcspr Dec 23, 2020
52c8b37
don't need another branch
mcspr Dec 23, 2020
5c35ae3
template +=(String / char* / numbers) and +(String, numbers / char*)
mcspr Dec 23, 2020
c908321
Merge remote-tracking branch 'origin/master' into string/no-sum-helper
mcspr Dec 23, 2020
425b366
Merge remote-tracking branch 'origin/master' into string/no-sum-helper
mcspr Jan 5, 2021
e553e26
nul after moving (isnt mem always zeroed tho?)
mcspr Jan 6, 2021
73a28d0
check if lhs cant keep before switching to rhs
mcspr Jan 6, 2021
fa00fba
fix String used to store struct data
mcspr Jan 6, 2021
8af5a00
style once more
mcspr Jan 6, 2021
c57ae69
typo
mcspr Jan 6, 2021
ed60441
Merge branch 'master' into string/no-sum-helper
earlephilhower Jan 8, 2021
4b70ead
Merge branch 'master' into string/no-sum-helper
earlephilhower Jan 9, 2021
b4ec910
Merge remote-tracking branch 'origin/master' into string/no-sum-helper
mcspr Jan 27, 2021
95ebd47
Merge remote-tracking branch 'origin/master' into string/no-sum-helper
mcspr Mar 21, 2021
3299833
recover 444002180bca8e36b3014eaf5ecf5e690837b440
mcspr Mar 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions cores/esp8266/StreamString.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ class StreamString: public String, public S2Stream
StreamString(const String& string): String(string), S2Stream(this) { }
StreamString(const __FlashStringHelper *str): String(str), S2Stream(this) { }
StreamString(String&& string): String(string), S2Stream(this) { }
StreamString(StringSumHelper&& sum): String(sum), S2Stream(this) { }

explicit StreamString(char c): String(c), S2Stream(this) { }
explicit StreamString(unsigned char c, unsigned char base = 10): String(c, base), S2Stream(this) { }
Expand Down Expand Up @@ -281,13 +280,6 @@ class StreamString: public String, public S2Stream
resetpp();
return *this;
}

StreamString& operator= (StringSumHelper&& rval)
{
String::operator=(rval);
resetpp();
return *this;
}
};

#endif // __STREAMSTRING_H
141 changes: 65 additions & 76 deletions cores/esp8266/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <Arduino.h>
#include "Arduino.h"
#include "WString.h"
#include "stdlib_noniso.h"

Expand Down Expand Up @@ -56,11 +56,6 @@ String::String(String &&rval) noexcept {
move(rval);
}

String::String(StringSumHelper &&rval) noexcept {
init();
move(rval);
}

String::String(unsigned char value, unsigned char base) {
init();
char buf[1 + 8 * sizeof(unsigned char)];
Expand Down Expand Up @@ -390,98 +385,92 @@ unsigned char String::concat(const __FlashStringHelper *str) {
}

/*********************************************/
/* Concatenate */
/* Insert */
/*********************************************/

StringSumHelper &operator +(const StringSumHelper &lhs, const String &rhs) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!a.concat(rhs.buffer(), rhs.len()))
a.invalidate();
return a;
}
String &String::insert(size_t position, const char *other, size_t other_length) {
if (position > length())
return *this;

StringSumHelper &operator +(const StringSumHelper &lhs, const char *cstr) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!cstr || !a.concat(cstr, strlen(cstr)))
a.invalidate();
return a;
}
auto len = length();
auto total = len + other_length;
if (!reserve(total))
return *this;

StringSumHelper &operator +(const StringSumHelper &lhs, char c) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!a.concat(c))
a.invalidate();
return a;
}
auto left = len - position;
setLen(total);

StringSumHelper &operator +(const StringSumHelper &lhs, unsigned char num) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!a.concat(num))
a.invalidate();
return a;
}
auto *start = wbuffer() + position;
memmove(start + other_length, start, left);
memmove_P(start, other, other_length);
wbuffer()[total] = '\0';

StringSumHelper &operator +(const StringSumHelper &lhs, int num) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!a.concat(num))
a.invalidate();
return a;
return *this;
}

StringSumHelper &operator +(const StringSumHelper &lhs, unsigned int num) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!a.concat(num))
a.invalidate();
return a;
String &String::insert(size_t position, const __FlashStringHelper *other) {
auto *p = reinterpret_cast<const char*>(other);
return insert(position, p, strlen_P(p));
}

StringSumHelper &operator +(const StringSumHelper &lhs, long num) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!a.concat(num))
a.invalidate();
return a;
String &String::insert(size_t position, char other) {
char tmp[2] { other, '\0' };
return insert(position, tmp, 1);
}

StringSumHelper &operator +(const StringSumHelper &lhs, unsigned long num) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!a.concat(num))
a.invalidate();
return a;
String &String::insert(size_t position, const char *other) {
return insert(position, other, strlen(other));
}

StringSumHelper &operator +(const StringSumHelper &lhs, long long num) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!a.concat(num))
a.invalidate();
return a;
String &String::insert(size_t position, const String &other) {
return insert(position, other.c_str(), other.length());
}

StringSumHelper &operator +(const StringSumHelper &lhs, unsigned long long num) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!a.concat(num))
a.invalidate();
return a;
String operator +(const String &lhs, String &&rhs) {
String res;
auto total = lhs.length() + rhs.length();
if (rhs.capacity() > total) {
rhs.insert(0, lhs);
res = std::move(rhs);
} else {
res.reserve(total);
res += lhs;
res += rhs;
rhs.invalidate();
}

return res;
}

StringSumHelper &operator +(const StringSumHelper &lhs, float num) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!a.concat(num))
a.invalidate();
return a;
String operator +(String &&lhs, String &&rhs) {
String res;
auto total = lhs.length() + rhs.length();
if ((total > lhs.capacity()) && (total < rhs.capacity())) {
rhs.insert(0, lhs);
res = std::move(rhs);
} else {
lhs += rhs;
rhs.invalidate();
res = std::move(lhs);
}

return res;
}

StringSumHelper &operator +(const StringSumHelper &lhs, double num) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!a.concat(num))
a.invalidate();
return a;
String operator +(char lhs, const String &rhs) {
String res;
res.reserve(rhs.length() + 1);
res += lhs;
res += rhs;
return res;
}

StringSumHelper &operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs) {
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
if (!a.concat(rhs))
a.invalidate();
return a;
String operator +(const char *lhs, const String &rhs) {
String res;
res.reserve(strlen_P(lhs) + rhs.length());
res += lhs;
res += rhs;
return res;
}

/*********************************************/
Expand Down
Loading