Change vernum_to_verstr() to take in a std::uint32_t instead of a long and return a std::string instead of a const char* to a static variable

This commit is contained in:
relesgoe 2020-09-26 13:28:53 -07:00
parent 4df13c278a
commit ef5f2c7503
2 changed files with 10 additions and 7 deletions

View file

@ -22,6 +22,10 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <fmt/format.h>
#include "common/setup_after.h"
@ -82,16 +86,13 @@ namespace pvpgn
}
extern char const * vernum_to_verstr(unsigned long vernum)
extern std::string vernum_to_verstr(std::uint32_t vernum)
{
static char verstr[16];
std::sprintf(verstr, "%lu.%lu.%lu.%lu",
return fmt::format("{}.{}.{}.{}",
(vernum >> 24),
(vernum >> 16) & 0xff,
(vernum >> 8) & 0xff,
(vernum)& 0xff);
return verstr;
(vernum) & 0xff);
}
}

View file

@ -19,12 +19,14 @@
#ifndef INCLUDED_PROGINFO_PROTOS
#define INCLUDED_PROGINFO_PROTOS
#include <string>
namespace pvpgn
{
extern int verparts_to_vernum(unsigned short v1, unsigned short v2, unsigned short v3, unsigned short v4, unsigned long * vernum);
extern int verstr_to_vernum(char const * verstr, unsigned long * vernum);
extern char const * vernum_to_verstr(unsigned long vernum);
extern std::string vernum_to_verstr(std::uint32_t vernum);
}