| | |
| | | #include <ctime> |
| | | #include <iomanip> |
| | | #include <sstream> |
| | | #include <vector> |
| | | #include <cstdarg> |
| | | |
| | | CToolUnits::CToolUnits() |
| | | { |
| | |
| | | |
| | | return str; |
| | | } |
| | | std::string CToolUnits::formatString(const char* fmt, ...) |
| | | { |
| | | if (fmt == nullptr) return std::string(); |
| | | |
| | | char buf[512] = {0}; |
| | | va_list args; |
| | | va_start(args, fmt); |
| | | int n = _vsnprintf_s(buf, sizeof(buf), _TRUNCATE, fmt, args); |
| | | va_end(args); |
| | | |
| | | if (n >= 0 && n < (int)sizeof(buf)) { |
| | | return std::string(buf); |
| | | } |
| | | |
| | | // ????????????????? |
| | | std::vector<char> tmp((n > 0 ? n + 2 : 1024), 0); |
| | | va_start(args, fmt); |
| | | _vsnprintf_s(tmp.data(), tmp.size(), _TRUNCATE, fmt, args); |
| | | va_end(args); |
| | | return std::string(tmp.data()); |
| | | } |