-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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: unify numeric conversion and fix assignments #8526
Conversation
Restore the pre-3.0.0 behaviour when we could assign numeric values to the string object. After introducing `operator =(char)`, everything was converted to `char` instead of the expected 'stringification' of the number (built-in int, long, unsigned int, unsigned long, long long, unsigned long long, float and double)
|
… decimalPlaces branch via if (base == 10) { sprintf(...) } else { ... } instead of separate funcs reuse the constructor for numeric types where it's possible
nonstd arduino funcs expect this usage pattern
also -1 line
explicit String(unsigned char, unsigned char base = 10); | ||
explicit String(int, unsigned char base = 10); | ||
explicit String(unsigned int, unsigned char base = 10); | ||
explicit String(long, unsigned char base = 10); | ||
explicit String(unsigned long, unsigned char base = 10); | ||
explicit String(long long /* base 10 */); | ||
explicit String(long long, unsigned char base); | ||
explicit String(unsigned long long /* base 10 */); | ||
explicit String(unsigned long long, unsigned char base); | ||
explicit String(float, unsigned char decimalPlaces = 2); | ||
explicit String(double, unsigned char decimalPlaces = 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is mostly for verbosity. Due to the amount of magic ctors we have... we can't really have std::initializer_list<char>
ctor as well, since everything would be converted into it
e.g.
String(std::initializer_list<char> data) {
concat(data.begin(), data.size());
}
So only purpose of the below is to allow to omit String{...}
in front of the arguments list. Where we suppose to have explicit
for String(int, base)
overload
core/test_string.cpp:620:51: error: converting to ‘String’ from initializer list would use explicit constructor ‘String::String(int, unsigned char)’
620 | String strings[] {{62, 10}, {63, 10}, {64, 10}};
| ^
Could be reverted though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are nice and seem to cover most of the cases, if not all.
Thanks to restore the API and factorize code
Restore the pre-3.0.0 behaviour when we could assign numeric values to
the string object. After introducing
operator =(char)
, everything wasconverted to
char
instead of the expected 'stringification' of thenumber (built-in int, long, unsigned int, unsigned long, long long,
unsigned long long, float and double)
Add
toString()
that handles conversions, re-use it through out the classFix #8430