13#include "DebugServer2/Utils/CompilerSupport.h"
24#define STR_HELPER(S) #S
25#define STR(S) STR_HELPER(S)
31template <
typename T>
static inline std::string ToString(T val) {
32 std::ostringstream os;
39static inline int VSNPrintf(
char *str,
size_t size,
char const *format,
40 va_list ap) DS2_ATTRIBUTE_PRINTF(3, 0);
41static inline int SNPrintf(
char *str,
size_t size,
char const *format, ...)
42 DS2_ATTRIBUTE_PRINTF(3, 4);
44#if defined(OS_WIN32) && !defined(PLATFORM_MINGW)
48static inline int VSNPrintf(
char *str,
size_t size,
char const *format,
52 res = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
55 res = _vscprintf(format, ap);
59#elif defined(OS_POSIX) || (defined(OS_WIN32) && defined(PLATFORM_MINGW))
62static inline int VSNPrintf(
char *str,
size_t size,
char const *format,
64 return ::vsnprintf(str, size, format, ap);
68static inline int SNPrintf(
char *str,
size_t size,
char const *format, ...) {
71 int res = VSNPrintf(str, size, format, ap);
77static inline std::wstring NarrowToWideString(std::string
const &s) {
78 std::vector<wchar_t> res;
81 size = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1,
nullptr, 0);
84 MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, res.data(), size);
88static inline std::string WideToNarrowString(std::wstring
const &s) {
89 std::vector<char> res;
92 size = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1,
nullptr, 0,
nullptr,
96 WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, res.data(), size,
nullptr,
102#if defined(COMPILER_MSVC)
103#pragma deprecated(sprintf, snprintf, vsnprintf)
104#elif defined(COMPILER_CLANG) || defined(COMPILER_GCC)
105#pragma GCC poison sprintf snprintf vsnprintf