@@ -70,6 +70,9 @@ extern void SERIAL_CHAR(char c);
70
70
#define SNPRINTF_P (V... ) snprintf_P(V)
71
71
#endif
72
72
73
+ #pragma GCC diagnostic push
74
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
75
+
73
76
/* *
74
77
* @brief MString class template
75
78
* @details A class template providing convenient string operators,
@@ -112,6 +115,7 @@ class MString {
112
115
MString& set (const MString &s) { strncpy (str, s.str , SIZE); debug (F (" MString" )); return *this ; }
113
116
MString& set (const bool &b) { return set (b ? F (" true" ) : F (" false" )); }
114
117
MString& set (const char c) { str[0 ] = c; if (1 < SIZE) str[1 ] = ' \0 ' ; debug (F (" char" )); return *this ; }
118
+ MString& set (const int8_t &i) { SNPRINTF_P (str, SIZE, PSTR (" %d" ), i); debug (F (" int8_t" )); return *this ; }
115
119
MString& set (const short &i) { SNPRINTF_P (str, SIZE, PSTR (" %d" ), i); debug (F (" short" )); return *this ; }
116
120
MString& set (const int &i) { SNPRINTF_P (str, SIZE, PSTR (" %d" ), i); debug (F (" int" )); return *this ; }
117
121
MString& set (const long &l) { SNPRINTF_P (str, SIZE, PSTR (" %ld" ), l); debug (F (" long" )); return *this ; }
@@ -157,6 +161,7 @@ class MString {
157
161
MString& append (const bool &b) { return append (b ? F (" true" ) : F (" false" )); }
158
162
MString& append (const char c) { int sz = length (); if (sz < SIZE) { str[sz] = c; if (sz < SIZE - 1 ) str[sz + 1 ] = ' \0 ' ; } return *this ; }
159
163
#if ENABLED(FASTER_APPEND)
164
+ MString& append (const int8_t &i) { int sz = length (); SNPRINTF (&str[sz], SIZE - sz, " %d" , i); return *this ; }
160
165
MString& append (const short &i) { int sz = length (); SNPRINTF (&str[sz], SIZE - sz, " %d" , i); return *this ; }
161
166
MString& append (const int &i) { int sz = length (); SNPRINTF (&str[sz], SIZE - sz, " %d" , i); return *this ; }
162
167
MString& append (const long &l) { int sz = length (); SNPRINTF (&str[sz], SIZE - sz, " %ld" , l); return *this ; }
@@ -165,13 +170,14 @@ class MString {
165
170
MString& append (const unsigned int &i) { int sz = length (); SNPRINTF (&str[sz], SIZE - sz, " %u" , i); return *this ; }
166
171
MString& append (const unsigned long &l) { int sz = length (); SNPRINTF (&str[sz], SIZE - sz, " %lu" , l); return *this ; }
167
172
#else
168
- MString& append (const short &i) { char buf[20 ]; sprintf (buf, " %d" , i); return append (buf); }
169
- MString& append (const int &i) { char buf[20 ]; sprintf (buf, " %d" , i); return append (buf); }
170
- MString& append (const long &l) { char buf[20 ]; sprintf (buf, " %ld" , l); return append (buf); }
171
- MString& append (const unsigned char &i) { char buf[20 ]; sprintf (buf, " %u" , i); return append (buf); }
172
- MString& append (const unsigned short &i) { char buf[20 ]; sprintf (buf, " %u" , i); return append (buf); }
173
- MString& append (const unsigned int &i) { char buf[20 ]; sprintf (buf, " %u" , i); return append (buf); }
174
- MString& append (const unsigned long &l) { char buf[20 ]; sprintf (buf, " %lu" , l); return append (buf); }
173
+ MString& append (const int8_t &i) { char buf[ 5 ]; sprintf (buf, " %d" , i); return append (buf); }
174
+ MString& append (const short &i) { char buf[12 ]; sprintf (buf, " %d" , i); return append (buf); }
175
+ MString& append (const int &i) { char buf[12 ]; sprintf (buf, " %d" , i); return append (buf); }
176
+ MString& append (const long &l) { char buf[12 ]; sprintf (buf, " %ld" , l); return append (buf); }
177
+ MString& append (const unsigned char &i) { char buf[ 5 ]; sprintf (buf, " %u" , i); return append (buf); }
178
+ MString& append (const unsigned short &i) { char buf[11 ]; sprintf (buf, " %u" , i); return append (buf); }
179
+ MString& append (const unsigned int &i) { char buf[11 ]; sprintf (buf, " %u" , i); return append (buf); }
180
+ MString& append (const unsigned long &l) { char buf[11 ]; sprintf (buf, " %lu" , l); return append (buf); }
175
181
#endif
176
182
MString& append (const float &f) { return append (p_float_t (f, SERIAL_FLOAT_PRECISION)); }
177
183
MString& append (const p_float_t &pf) { return append (w_float_t (pf.value , 1 , pf.prec )); }
@@ -220,6 +226,9 @@ class MString {
220
226
template <typename T, typename ... Args>
221
227
MString (T arg1, Args... more) { set (arg1); append (more...); }
222
228
229
+ // Catch unhandled types to prevent infinite recursion
230
+ template <typename T> MString& append (T) { return append (' ?' ); }
231
+
223
232
// Take a list of any number of arguments and append them to the string
224
233
template <typename T, typename ... Args>
225
234
MString& append (T arg1, Args... more) { return append (arg1).append (more...); }
@@ -299,6 +308,8 @@ class MString {
299
308
300
309
};
301
310
311
+ #pragma GCC diagnostic pop
312
+
302
313
#ifndef TS_SIZE
303
314
#define TS_SIZE 63
304
315
#endif
0 commit comments