finish refactor, add docs and CI
This commit is contained in:
+25
-28
@@ -26,8 +26,7 @@
|
||||
|
||||
#include <nxst/domain/common.hpp>
|
||||
|
||||
std::string DateTime::timeStr(void)
|
||||
{
|
||||
std::string DateTime::timeStr(void) {
|
||||
time_t unixTime;
|
||||
struct tm timeStruct;
|
||||
time(&unixTime);
|
||||
@@ -35,35 +34,32 @@ std::string DateTime::timeStr(void)
|
||||
return StringUtils::format("%02i:%02i:%02i", timeStruct.tm_hour, timeStruct.tm_min, timeStruct.tm_sec);
|
||||
}
|
||||
|
||||
std::string DateTime::dateTimeStr(void)
|
||||
{
|
||||
std::string DateTime::dateTimeStr(void) {
|
||||
time_t unixTime;
|
||||
struct tm timeStruct;
|
||||
time(&unixTime);
|
||||
localtime_r(&unixTime, &timeStruct);
|
||||
return StringUtils::format("%04i%02i%02i-%02i%02i%02i", timeStruct.tm_year + 1900, timeStruct.tm_mon + 1, timeStruct.tm_mday, timeStruct.tm_hour,
|
||||
timeStruct.tm_min, timeStruct.tm_sec);
|
||||
return StringUtils::format("%04i%02i%02i-%02i%02i%02i", timeStruct.tm_year + 1900, timeStruct.tm_mon + 1,
|
||||
timeStruct.tm_mday, timeStruct.tm_hour, timeStruct.tm_min, timeStruct.tm_sec);
|
||||
}
|
||||
|
||||
std::string DateTime::logDateTime(void)
|
||||
{
|
||||
std::string DateTime::logDateTime(void) {
|
||||
time_t unixTime;
|
||||
struct tm timeStruct;
|
||||
time(&unixTime);
|
||||
localtime_r(&unixTime, &timeStruct);
|
||||
return StringUtils::format("%04i-%02i-%02i %02i:%02i:%02i", timeStruct.tm_year + 1900, timeStruct.tm_mon + 1, timeStruct.tm_mday,
|
||||
timeStruct.tm_hour, timeStruct.tm_min, timeStruct.tm_sec);
|
||||
return StringUtils::format("%04i-%02i-%02i %02i:%02i:%02i", timeStruct.tm_year + 1900,
|
||||
timeStruct.tm_mon + 1, timeStruct.tm_mday, timeStruct.tm_hour,
|
||||
timeStruct.tm_min, timeStruct.tm_sec);
|
||||
}
|
||||
|
||||
std::string StringUtils::UTF16toUTF8(const std::u16string& src)
|
||||
{
|
||||
std::string StringUtils::UTF16toUTF8(const std::u16string& src) {
|
||||
static std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
|
||||
std::string dst = convert.to_bytes(src);
|
||||
return dst;
|
||||
}
|
||||
|
||||
std::string StringUtils::removeForbiddenCharacters(std::string src)
|
||||
{
|
||||
std::string StringUtils::removeForbiddenCharacters(std::string src) {
|
||||
static const std::string illegalChars = ".,!\\/:?*\"<>|";
|
||||
for (size_t i = 0, sz = src.length(); i < sz; i++) {
|
||||
if (illegalChars.find(src[i]) != std::string::npos) {
|
||||
@@ -79,8 +75,7 @@ std::string StringUtils::removeForbiddenCharacters(std::string src)
|
||||
return src;
|
||||
}
|
||||
|
||||
std::string StringUtils::format(const std::string fmt_str, ...)
|
||||
{
|
||||
std::string StringUtils::format(const std::string fmt_str, ...) {
|
||||
va_list ap;
|
||||
char* fp = NULL;
|
||||
va_start(ap, fmt_str);
|
||||
@@ -90,8 +85,7 @@ std::string StringUtils::format(const std::string fmt_str, ...)
|
||||
return std::string(formatted.get());
|
||||
}
|
||||
|
||||
bool StringUtils::containsInvalidChar(const std::string& str)
|
||||
{
|
||||
bool StringUtils::containsInvalidChar(const std::string& str) {
|
||||
for (size_t i = 0, sz = str.length(); i < sz; i++) {
|
||||
if (!isascii(str[i])) {
|
||||
return true;
|
||||
@@ -100,24 +94,27 @@ bool StringUtils::containsInvalidChar(const std::string& str)
|
||||
return false;
|
||||
}
|
||||
|
||||
void StringUtils::ltrim(std::string& s)
|
||||
{
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) { return !std::isspace(ch); }));
|
||||
void StringUtils::ltrim(std::string& s) {
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
|
||||
return !std::isspace(ch);
|
||||
}));
|
||||
}
|
||||
|
||||
void StringUtils::rtrim(std::string& s)
|
||||
{
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch); }).base(), s.end());
|
||||
void StringUtils::rtrim(std::string& s) {
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(),
|
||||
[](int ch) {
|
||||
return !std::isspace(ch);
|
||||
})
|
||||
.base(),
|
||||
s.end());
|
||||
}
|
||||
|
||||
void StringUtils::trim(std::string& s)
|
||||
{
|
||||
void StringUtils::trim(std::string& s) {
|
||||
ltrim(s);
|
||||
rtrim(s);
|
||||
}
|
||||
|
||||
char* getConsoleIP(void)
|
||||
{
|
||||
char* getConsoleIP(void) {
|
||||
struct in_addr in;
|
||||
in.s_addr = gethostid();
|
||||
return inet_ntoa(in);
|
||||
|
||||
Reference in New Issue
Block a user