X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/a8689998a9b2cfc17dc260b423cce8ff2e407adb..669bf62b01b121a3c9fc5092cd9d2ab3392fd92c:/stglibs/common.lib/common.cpp diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index c02f675c..622f64f7 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -347,6 +347,20 @@ for (size_t i = 0; i < src.length() / 2; i++) } } //--------------------------------------------------------------------------- +std::string Encode12str(const std::string & src) +{ +std::string res; +Encode12str(res, src); +return res; +} +//--------------------------------------------------------------------------- +std::string Decode21str(const std::string & src) +{ +std::string res; +Decode21str(res, src); +return res; +} +//--------------------------------------------------------------------------- void Encode12(char * dst, const char * src, size_t srcLen) { for (size_t i = 0; i <= srcLen; i++) @@ -517,6 +531,22 @@ uint32_t inet_strington(const std::string & value) return result; } //----------------------------------------------------------------------------- +std::string TimeToString(time_t time) +{ +struct tm brokenTime; + +brokenTime.tm_wday = 0; +brokenTime.tm_yday = 0; +brokenTime.tm_isdst = 0; + +gmtime_r(&time, &brokenTime); + +char buf[32]; +strftime(buf, 32, "%Y-%m-%d %H:%M:%S", &brokenTime); + +return buf; +} +//----------------------------------------------------------------------------- int ParseTariffTimeStr(const char * str, int &h1, int &m1, int &h2, int &m2) { char hs1[10], ms1[10], hs2[10], ms2[10]; @@ -790,6 +820,13 @@ const std::string & x2str(uint64_t x, std::string & s) return unsigned2str(x, s); } //--------------------------------------------------------------------------- +const std::string & x2str(double x, std::string & s) +{ +char buf[256]; +s = snprintf(buf, sizeof(buf), "%f", x); +return s; +} +//--------------------------------------------------------------------------- std::string & TrimL(std::string & val) { size_t pos = val.find_first_not_of(" \t"); @@ -819,12 +856,18 @@ std::string & Trim(std::string & val) return TrimR(TrimL(val)); } //--------------------------------------------------------------------------- +std::string Trim(const std::string & val) +{ +std::string res(val); +return TrimR(TrimL(res)); +} +//--------------------------------------------------------------------------- std::string ToLower(const std::string & value) { std::string res; for (std::string::size_type pos = 0; pos < value.length(); ++pos) res += tolower(value[pos]); - return value; + return res; } //--------------------------------------------------------------------------- std::string ToUpper(const std::string & value) @@ -832,7 +875,7 @@ std::string ToUpper(const std::string & value) std::string res; for (std::string::size_type pos = 0; pos < value.length(); ++pos) res += toupper(value[pos]); - return value; + return res; } //--------------------------------------------------------------------------- #ifdef WIN32