refactor(xod-arduino, workspace): replace platform-dependent dtostrf with dtoa and move shared formatters.cpp into cpplib directory and rename it

This commit is contained in:
Kirill Shumilov
2018-11-14 13:39:57 +03:00
parent 3bad189261
commit 602777c43e
23 changed files with 1101 additions and 462 deletions

View File

@@ -0,0 +1,43 @@
/**
* This file makes Catch2 show failed tests properly for the XString type.
* E.G.
* "some" == "something"
* instead of
* {?} == {?}
*
* Catch2 string conversion docs:
* https://github.com/catchorg/Catch2/blob/master/docs/tostring.md
*/
template <typename T>
struct XodStringMaker {
static std::string convert(T value) {
size_t len = length(value) + 2;
std::string str(len, '\0');
size_t strPos = 1;
str[0] = '"';
str[len - 1] = '"';
for (auto it = value.iterate(); it; ++it) {
str[strPos++] = *it;
}
return str;
}
};
namespace Catch {
template <>
struct StringMaker<xod::XString> {
static std::string convert(xod::XString value) {
return XodStringMaker<xod::XString>::convert(value);
}
};
template <>
struct StringMaker<xod::XStringCString> {
static std::string convert(xod::XStringCString value) {
return XodStringMaker<xod::XStringCString>::convert(value);
}
};
}