Improve formatted strings sending
- Use BString.SetToFormat for formatting, removes the limit of 1024
characters per log
- Add a vararg version of SendFormat (named SendFormatV) to use in
loging frameworks which want to pass a format string to the logger
diff --git a/BeDC.h b/BeDC.h
index 76d32cd..baae0ee 100644
--- a/BeDC.h
+++ b/BeDC.h
@@ -1,4 +1,4 @@
-//////////////////////////////////////////////////////////////////////////
+
// BeDC.h //
// The header file to use with BeDC //
// //
@@ -75,17 +75,27 @@
//---------------
//Send a format string - parameters
- void SendFormat(const char *text, ...){
- char buffer[1024];
- va_list args;
-
- va_start(args, text);
- vsprintf(buffer, text, args);
- va_end(args);
- SendMessage(buffer, DC_MESSAGE);
- }
-
- void SendFormatT(const char *text, int8 type, ...){
+ void SendFormat(const char *text, ...) __attribute__((format(printf, 2, 3))) {
+ BString str;
+
+ va_list args;
+ va_start(args, text);
+ str.SetToFormatVarArgs(text, args);
+ va_end(args);
+
+ SendMessage(str.String(), DC_MESSAGE);
+ }
+
+ void SendFormatV(const char *text, va_list args) __attribute__((format(printf, 2, 0))) {
+ BString str;
+ va_list copyOfArgs;
+ va_copy(copyOfArgs, args);
+ str.SetToFormatVarArgs(text, args);
+ va_end(copyOfArgs);
+ SendMessage(str.String(), DC_MESSAGE);
+ }
+
+ void SendFormatT(const char *text, int8 type, ...) __attribute__((format(printf, 2, 4))) {
char buffer[1024];
va_list args;