@@ -70,6 +70,9 @@ extern void SERIAL_CHAR(char c);
|
|||||||
#define SNPRINTF_P(V...) snprintf_P(V)
|
#define SNPRINTF_P(V...) snprintf_P(V)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MString class template
|
* @brief MString class template
|
||||||
* @details A class template providing convenient string operators,
|
* @details A class template providing convenient string operators,
|
||||||
@@ -112,6 +115,7 @@ public:
|
|||||||
MString& set(const MString &s) { strncpy(str, s.str, SIZE); debug(F("MString")); return *this; }
|
MString& set(const MString &s) { strncpy(str, s.str, SIZE); debug(F("MString")); return *this; }
|
||||||
MString& set(const bool &b) { return set(b ? F("true") : F("false")); }
|
MString& set(const bool &b) { return set(b ? F("true") : F("false")); }
|
||||||
MString& set(const char c) { str[0] = c; if (1 < SIZE) str[1] = '\0'; debug(F("char")); return *this; }
|
MString& set(const char c) { str[0] = c; if (1 < SIZE) str[1] = '\0'; debug(F("char")); return *this; }
|
||||||
|
MString& set(const int8_t &i) { SNPRINTF_P(str, SIZE, PSTR("%d"), i); debug(F("int8_t")); return *this; }
|
||||||
MString& set(const short &i) { SNPRINTF_P(str, SIZE, PSTR("%d"), i); debug(F("short")); return *this; }
|
MString& set(const short &i) { SNPRINTF_P(str, SIZE, PSTR("%d"), i); debug(F("short")); return *this; }
|
||||||
MString& set(const int &i) { SNPRINTF_P(str, SIZE, PSTR("%d"), i); debug(F("int")); return *this; }
|
MString& set(const int &i) { SNPRINTF_P(str, SIZE, PSTR("%d"), i); debug(F("int")); return *this; }
|
||||||
MString& set(const long &l) { SNPRINTF_P(str, SIZE, PSTR("%ld"), l); debug(F("long")); return *this; }
|
MString& set(const long &l) { SNPRINTF_P(str, SIZE, PSTR("%ld"), l); debug(F("long")); return *this; }
|
||||||
@@ -157,6 +161,7 @@ public:
|
|||||||
MString& append(const bool &b) { return append(b ? F("true") : F("false")); }
|
MString& append(const bool &b) { return append(b ? F("true") : F("false")); }
|
||||||
MString& append(const char c) { int sz = length(); if (sz < SIZE) { str[sz] = c; if (sz < SIZE - 1) str[sz + 1] = '\0'; } return *this; }
|
MString& append(const char c) { int sz = length(); if (sz < SIZE) { str[sz] = c; if (sz < SIZE - 1) str[sz + 1] = '\0'; } return *this; }
|
||||||
#if ENABLED(FASTER_APPEND)
|
#if ENABLED(FASTER_APPEND)
|
||||||
|
MString& append(const int8_t &i) { int sz = length(); SNPRINTF(&str[sz], SIZE - sz, "%d", i); return *this; }
|
||||||
MString& append(const short &i) { int sz = length(); SNPRINTF(&str[sz], SIZE - sz, "%d", i); return *this; }
|
MString& append(const short &i) { int sz = length(); SNPRINTF(&str[sz], SIZE - sz, "%d", i); return *this; }
|
||||||
MString& append(const int &i) { int sz = length(); SNPRINTF(&str[sz], SIZE - sz, "%d", i); return *this; }
|
MString& append(const int &i) { int sz = length(); SNPRINTF(&str[sz], SIZE - sz, "%d", i); return *this; }
|
||||||
MString& append(const long &l) { int sz = length(); SNPRINTF(&str[sz], SIZE - sz, "%ld", l); return *this; }
|
MString& append(const long &l) { int sz = length(); SNPRINTF(&str[sz], SIZE - sz, "%ld", l); return *this; }
|
||||||
@@ -165,13 +170,14 @@ public:
|
|||||||
MString& append(const unsigned int &i) { int sz = length(); SNPRINTF(&str[sz], SIZE - sz, "%u", i); return *this; }
|
MString& append(const unsigned int &i) { int sz = length(); SNPRINTF(&str[sz], SIZE - sz, "%u", i); return *this; }
|
||||||
MString& append(const unsigned long &l) { int sz = length(); SNPRINTF(&str[sz], SIZE - sz, "%lu", l); return *this; }
|
MString& append(const unsigned long &l) { int sz = length(); SNPRINTF(&str[sz], SIZE - sz, "%lu", l); return *this; }
|
||||||
#else
|
#else
|
||||||
MString& append(const short &i) { char buf[20]; sprintf(buf, "%d", i); return append(buf); }
|
MString& append(const int8_t &i) { char buf[ 5]; sprintf(buf, "%d", i); return append(buf); }
|
||||||
MString& append(const int &i) { char buf[20]; sprintf(buf, "%d", i); return append(buf); }
|
MString& append(const short &i) { char buf[12]; sprintf(buf, "%d", i); return append(buf); }
|
||||||
MString& append(const long &l) { char buf[20]; sprintf(buf, "%ld", l); return append(buf); }
|
MString& append(const int &i) { char buf[12]; sprintf(buf, "%d", i); return append(buf); }
|
||||||
MString& append(const unsigned char &i) { char buf[20]; sprintf(buf, "%u", i); return append(buf); }
|
MString& append(const long &l) { char buf[12]; sprintf(buf, "%ld", l); return append(buf); }
|
||||||
MString& append(const unsigned short &i) { char buf[20]; sprintf(buf, "%u", i); return append(buf); }
|
MString& append(const unsigned char &i) { char buf[ 5]; sprintf(buf, "%u", i); return append(buf); }
|
||||||
MString& append(const unsigned int &i) { char buf[20]; sprintf(buf, "%u", i); return append(buf); }
|
MString& append(const unsigned short &i) { char buf[11]; sprintf(buf, "%u", i); return append(buf); }
|
||||||
MString& append(const unsigned long &l) { char buf[20]; sprintf(buf, "%lu", l); return append(buf); }
|
MString& append(const unsigned int &i) { char buf[11]; sprintf(buf, "%u", i); return append(buf); }
|
||||||
|
MString& append(const unsigned long &l) { char buf[11]; sprintf(buf, "%lu", l); return append(buf); }
|
||||||
#endif
|
#endif
|
||||||
MString& append(const float &f) { return append(p_float_t(f, SERIAL_FLOAT_PRECISION)); }
|
MString& append(const float &f) { return append(p_float_t(f, SERIAL_FLOAT_PRECISION)); }
|
||||||
MString& append(const p_float_t &pf) { return append(w_float_t(pf.value, 1, pf.prec)); }
|
MString& append(const p_float_t &pf) { return append(w_float_t(pf.value, 1, pf.prec)); }
|
||||||
@@ -220,6 +226,9 @@ public:
|
|||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
MString(T arg1, Args... more) { set(arg1); append(more...); }
|
MString(T arg1, Args... more) { set(arg1); append(more...); }
|
||||||
|
|
||||||
|
// Catch unhandled types to prevent infinite recursion
|
||||||
|
template<typename T> MString& append(T) { return append('?'); }
|
||||||
|
|
||||||
// Take a list of any number of arguments and append them to the string
|
// Take a list of any number of arguments and append them to the string
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
MString& append(T arg1, Args... more) { return append(arg1).append(more...); }
|
MString& append(T arg1, Args... more) { return append(arg1).append(more...); }
|
||||||
@@ -299,6 +308,8 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
#ifndef TS_SIZE
|
#ifndef TS_SIZE
|
||||||
#define TS_SIZE 63
|
#define TS_SIZE 63
|
||||||
#endif
|
#endif
|
||||||
|
@@ -52,16 +52,17 @@ void runStartupTests() {
|
|||||||
// 100 dashes, but chopped down to DEFAULT_MSTRING_SIZE (20)
|
// 100 dashes, but chopped down to DEFAULT_MSTRING_SIZE (20)
|
||||||
TSS(repchr_t('-', 100)).echoln();
|
TSS(repchr_t('-', 100)).echoln();
|
||||||
|
|
||||||
// Hello World!-123456------ <spaces!
|
// Hello World!-123456------ <spaces!33
|
||||||
// ^ eol! ... 1234.50*2345.602 = 2895645.67
|
// ^ eol! ... 1234.50*2345.602 = 2895645.67
|
||||||
SString<100> str(F("Hello"));
|
SString<100> str(F("Hello"));
|
||||||
str.append(F(" World!"));
|
str.append(F(" World!"));
|
||||||
str += '-';
|
str += '-';
|
||||||
str += "123";
|
str += uint8_t(123);
|
||||||
str += F("456");
|
str += F("456");
|
||||||
str += repchr_t('-', 6);
|
str += repchr_t('-', 6);
|
||||||
str += Spaces(3);
|
str += Spaces(3);
|
||||||
str += "< spaces!";
|
str += "< spaces!";
|
||||||
|
str += int8_t(33);
|
||||||
str.eol();
|
str.eol();
|
||||||
str += "^ eol!";
|
str += "^ eol!";
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user