Move string_printf to maxbase
Can be used in tests.
This commit is contained in:
@ -1229,34 +1229,6 @@ uint8_t* set_byteN(uint8_t* ptr, uint64_t value, int bytes)
|
||||
return ptr + bytes;
|
||||
}
|
||||
|
||||
std::string string_printf(const char* format, ...)
|
||||
{
|
||||
/* Use 'vsnprintf' for the formatted printing. It outputs the optimal buffer length - 1. */
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int characters = vsnprintf(NULL, 0, format, args);
|
||||
va_end(args);
|
||||
std::string rval;
|
||||
if (characters < 0)
|
||||
{
|
||||
// Encoding (programmer) error.
|
||||
mxb_assert(!true);
|
||||
MXS_ERROR("Could not format the string %s.", format);
|
||||
}
|
||||
else if (characters > 0)
|
||||
{
|
||||
// 'characters' does not include the \0-byte.
|
||||
int total_size = characters + 1;
|
||||
rval.reserve(total_size);
|
||||
rval.resize(characters); // The final "length" of the string
|
||||
va_start(args, format);
|
||||
// Write directly to the string internal array, avoiding any temporary arrays.
|
||||
vsnprintf(&rval[0], total_size, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
|
@ -12,16 +12,16 @@
|
||||
*/
|
||||
|
||||
#include "mariadbmon.hh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <queue>
|
||||
#include <maxbase/format.hh>
|
||||
#include <maxscale/modutil.h>
|
||||
#include <maxscale/mysql_utils.h>
|
||||
#include <maxscale/utils.hh>
|
||||
|
||||
using std::string;
|
||||
using maxscale::string_printf;
|
||||
using maxbase::string_printf;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -12,18 +12,18 @@
|
||||
*/
|
||||
|
||||
#include "mariadbmon.hh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <inttypes.h>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <maxbase/stopwatch.hh>
|
||||
#include <maxbase/format.hh>
|
||||
#include <maxscale/clock.h>
|
||||
#include <maxscale/mysql_utils.h>
|
||||
#include <maxscale/utils.hh>
|
||||
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
using maxscale::string_printf;
|
||||
using maxbase::string_printf;
|
||||
using maxbase::StopWatch;
|
||||
using maxbase::Duration;
|
||||
|
||||
|
@ -19,18 +19,19 @@
|
||||
#include <inttypes.h>
|
||||
#include <sstream>
|
||||
#include <maxbase/assert.h>
|
||||
#include <maxbase/format.hh>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/dcb.h>
|
||||
#include <maxscale/modulecmd.h>
|
||||
#include <maxscale/mysql_utils.h>
|
||||
#include <maxscale/routingworker.h>
|
||||
#include <maxscale/secrets.h>
|
||||
#include <maxscale/utils.hh>
|
||||
#include <maxscale/utils.h>
|
||||
// TODO: For monitor_add_parameters
|
||||
#include "../../../core/internal/monitor.h"
|
||||
|
||||
using std::string;
|
||||
using maxscale::string_printf;
|
||||
using maxbase::string_printf;
|
||||
|
||||
// Config parameter names
|
||||
const char* const CN_AUTO_FAILOVER = "auto_failover";
|
||||
@ -278,7 +279,6 @@ void MariaDBMonitor::diagnostics(DCB* dcb) const
|
||||
|
||||
string MariaDBMonitor::diagnostics_to_string() const
|
||||
{
|
||||
using maxscale::string_printf;
|
||||
string rval;
|
||||
rval += string_printf("Automatic failover: %s\n", m_auto_failover ? "Enabled" : "Disabled");
|
||||
rval += string_printf("Failcount: %d\n", m_failcount);
|
||||
|
@ -17,12 +17,13 @@
|
||||
#include <inttypes.h>
|
||||
#include <iomanip>
|
||||
#include <thread>
|
||||
#include <maxscale/mysql_utils.h>
|
||||
#include <maxscale/utils.hh>
|
||||
#include <set>
|
||||
#include <maxbase/format.hh>
|
||||
#include <maxscale/mysql_utils.h>
|
||||
|
||||
|
||||
using std::string;
|
||||
using maxscale::string_printf;
|
||||
using maxbase::string_printf;
|
||||
using maxbase::Duration;
|
||||
using maxbase::StopWatch;
|
||||
|
||||
|
@ -14,11 +14,12 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <inttypes.h>
|
||||
#include <maxbase/format.hh>
|
||||
#include <maxbase/assert.h>
|
||||
#include <maxscale/utils.hh>
|
||||
|
||||
|
||||
using std::string;
|
||||
using maxscale::string_printf;
|
||||
using maxbase::string_printf;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
Reference in New Issue
Block a user