File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change 2222#include " WString.h"
2323#include " itoa.h"
2424#include " avr/dtostrf.h"
25+ #include < stdio.h>
26+ #include < stdarg.h>
2527
2628/* ********************************************/
2729/* Constructors */
@@ -126,6 +128,18 @@ String::~String()
126128 free (buffer);
127129}
128130
131+ String String::format (const char * format, ...)
132+ {
133+ va_list arg;
134+ va_start (arg, format);
135+ const int len = vsnprintf (nullptr , 0 , format, arg);
136+ char str[len + 1 ];
137+ vsnprintf (str, sizeof (str), format, arg);
138+ va_end (arg);
139+
140+ return String (str);
141+ }
142+
129143/* ********************************************/
130144/* Memory Management */
131145/* ********************************************/
Original file line number Diff line number Diff line change @@ -73,6 +73,8 @@ class String
7373 explicit String (double , unsigned char decimalPlaces=2 );
7474 ~String (void );
7575
76+ static String format (const char * format, ...);
77+
7678 // memory management
7779 // return true on success, false on failure (in which case, the string
7880 // is left unchanged). reserve(0), if successful, will validate an
You can’t perform that action at this time.
0 commit comments