From: Maksym Mamontov Date: Mon, 27 Jan 2020 20:53:35 +0000 (+0200) Subject: Remove x2str/unsigned2str in favor of std::to_string. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/af9452155f0892e1d2862efad4a87861ca60867d?ds=sidebyside Remove x2str/unsigned2str in favor of std::to_string. --- diff --git a/libs/common/common.cpp b/libs/common/common.cpp index 8cfcf402..954fc381 100644 --- a/libs/common/common.cpp +++ b/libs/common/common.cpp @@ -824,24 +824,6 @@ return 0; } #endif //--------------------------------------------------------------------------- -const std::string & x2str(uint32_t x, std::string & s) -{ -return unsigned2str(x, s); -} -//--------------------------------------------------------------------------- -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]; -snprintf(buf, sizeof(buf), "%f", x); -s = buf; -return s; -} -//--------------------------------------------------------------------------- std::string & TrimL(std::string & val) { size_t pos = val.find_first_not_of(" \t"); @@ -1125,7 +1107,7 @@ std::string ToPrintable(const std::string & src) if (std::isprint(src[i])) dest += src[i]; else - dest += "\\" + x2str(src[i]); + dest += "\\" + std::to_string(src[i]); return dest; } diff --git a/libs/common/include/stg/common.h b/libs/common/include/stg/common.h index 94cf9f06..ca8c3b45 100644 --- a/libs/common/include/stg/common.h +++ b/libs/common/include/stg/common.h @@ -171,22 +171,9 @@ int str2x(const std::string & str, int64_t & x); int str2x(const std::string & str, uint64_t & x); #endif //----------------------------------------------------------------------------- -const std::string & x2str(uint32_t x, std::string & s); -const std::string & x2str(uint64_t x, std::string & s); -//----------------------------------------------------------------------------- -const std::string & x2str(double x, std::string & s); -//----------------------------------------------------------------------------- template int str2x(const std::string & str, varT & x); -template -const std::string & x2str(varT x, std::string & s); -template -std::string x2str(varT x) { std::string s; return x2str(x, s); } -template -const std::string & unsigned2str(varT x, std::string & s); -template -std::string unsigned2str(varT x) { std::string s; return unsigned2str(x, s); } //----------------------------------------------------------------------------- template @@ -227,89 +214,6 @@ int str2x(const std::string & str, varT & x) return 0; } //----------------------------------------------------------------------------- -template -inline -const std::string & x2str(varT x, std::string & s) -{ - varT xx = x; - int pos = 1; - - x /= 10; - while (x != 0) - { - x /= 10; - pos++; - } - - if (xx < 0) - { - pos++; - s.resize(pos, 0); - s[0] = '-'; - } - else if (xx > 0) - { - s.resize(pos, 0); - } - else - { - s.resize(1, 0); - s[0] = '0'; - return s; - } - - x = xx; - - while (x != 0) - { - if (x < 0) - s[--pos] = -(x % 10) + '0'; - else - s[--pos] = x % 10 + '0'; - - x /= 10; - } - - return s; -} -//----------------------------------------------------------------------------- -template -inline -const std::string & unsigned2str(varT x, std::string & s) -{ - varT xx = x; - int pos = 1; - - x /= 10; - while (x != 0) - { - x /= 10; - pos++; - } - - if (xx > 0) - { - s.resize(pos, 0); - } - else - { - s.resize(1, 0); - s[0] = '0'; - return s; - } - - x = xx; - - while (x != 0) - { - s[--pos] = x % 10 + '0'; - - x /= 10; - } - - return s; -} -//----------------------------------------------------------------------------- char * stg_strptime(const char *, const char *, struct tm *); time_t stg_timegm(struct tm *); diff --git a/libs/json/include/stg/json_generator.h b/libs/json/include/stg/json_generator.h index 4f1523fc..831b0e05 100644 --- a/libs/json/include/stg/json_generator.h +++ b/libs/json/include/stg/json_generator.h @@ -69,7 +69,7 @@ class NumberGen : public Gen public: explicit NumberGen(const std::string& value) : m_value(value) {} template - explicit NumberGen(const T& value) : m_value(x2str(value)) {} + explicit NumberGen(const T& value) : m_value(std::to_string(value)) {} virtual void run(yajl_gen_t* handle) const; private: std::string m_value; diff --git a/libs/pinger/pinger.cpp b/libs/pinger/pinger.cpp index 1689e294..07415812 100644 --- a/libs/pinger/pinger.cpp +++ b/libs/pinger/pinger.cpp @@ -174,8 +174,7 @@ while (iter != pingIP.end()) { uint32_t ip = iter->first; time_t t = iter->second; - std::string s; - x2str(t, s); + std::string s = std::to_string(t); printf("ip = %s, time = %9s\n", inet_ntostring(ip).c_str(), s.c_str()); ++iter; } diff --git a/libs/srvconf/parsers/chg_admin.cpp b/libs/srvconf/parsers/chg_admin.cpp index 14679dff..ca2d8003 100644 --- a/libs/srvconf/parsers/chg_admin.cpp +++ b/libs/srvconf/parsers/chg_admin.cpp @@ -35,6 +35,6 @@ if (!conf.login.empty()) if (!conf.password.empty()) params += " password=\"" + conf.password.data() + "\""; if (!conf.priv.empty()) - params += " priv=\"" + unsigned2str(conf.priv.data().ToInt()) + "\""; + params += " priv=\"" + std::to_string(conf.priv.data().ToInt()) + "\""; return params; } diff --git a/libs/srvconf/parsers/chg_tariff.cpp b/libs/srvconf/parsers/chg_tariff.cpp index 16c4b198..d0fc13a7 100644 --- a/libs/srvconf/parsers/chg_tariff.cpp +++ b/libs/srvconf/parsers/chg_tariff.cpp @@ -44,7 +44,7 @@ for (typename A::size_type i = 0; i < array.size(); ++i) return; if (!res.empty()) res += "/"; - res += x2str((array[i].*field).data()); + res += std::to_string((array[i].*field).data()); } stream << "<" << name << " value=\"" << res << "\"/>"; } diff --git a/libs/srvconf/parsers/get_tariff.cpp b/libs/srvconf/parsers/get_tariff.cpp index 7a6f9053..b7acafa5 100644 --- a/libs/srvconf/parsers/get_tariff.cpp +++ b/libs/srvconf/parsers/get_tariff.cpp @@ -153,7 +153,7 @@ GET_TARIFF::PARSER::PARSER(CALLBACK f, void * d, const std::string & e) AddParser(propertyParsers, "changePolicy", info.tariffConf.changePolicy, GetChangePolicy); AddParser(propertyParsers, "changePolicyTimeout", info.tariffConf.changePolicyTimeout); for (size_t i = 0; i < DIR_NUM; ++i) - AddParser(propertyParsers, "time" + unsigned2str(i), info.dirPrice[i], GetTimeSpan); + AddParser(propertyParsers, "time" + std::to_string(i), info.dirPrice[i], GetTimeSpan); AddAOSParser(propertyParsers, "priceDayA", info.dirPrice, &DIRPRICE_DATA::priceDayA, GetSlashedValue); AddAOSParser(propertyParsers, "priceDayB", info.dirPrice, &DIRPRICE_DATA::priceDayB, GetSlashedValue); AddAOSParser(propertyParsers, "priceNightA", info.dirPrice, &DIRPRICE_DATA::priceNightA, GetSlashedValue); diff --git a/libs/srvconf/parsers/get_user.cpp b/libs/srvconf/parsers/get_user.cpp index 03327c4d..30005626 100644 --- a/libs/srvconf/parsers/get_user.cpp +++ b/libs/srvconf/parsers/get_user.cpp @@ -41,10 +41,10 @@ if (!attr) std::map props; for (size_t i = 0; i < DIR_NUM; ++i) { - props.insert(std::pair("su" + unsigned2str(i), &value.su[i])); - props.insert(std::pair("sd" + unsigned2str(i), &value.sd[i])); - props.insert(std::pair("mu" + unsigned2str(i), &value.mu[i])); - props.insert(std::pair("md" + unsigned2str(i), &value.md[i])); + props.insert(std::pair("su" + std::to_string(i), &value.su[i])); + props.insert(std::pair("sd" + std::to_string(i), &value.sd[i])); + props.insert(std::pair("mu" + std::to_string(i), &value.mu[i])); + props.insert(std::pair("md" + std::to_string(i), &value.md[i])); } size_t pos = 0; while (attr[pos]) @@ -95,7 +95,7 @@ GET_USER::PARSER::PARSER(CALLBACK f, void * d, const std::string & e) AddParser(propertyParsers, "lastActivityTime", info.lastActivityTime); for (size_t i = 0; i < USERDATA_NUM; ++i) - AddParser(propertyParsers, "userData" + unsigned2str(i), info.userData[i], "koi8-ru", GetEncodedValue); + AddParser(propertyParsers, "userData" + std::to_string(i), info.userData[i], "koi8-ru", GetEncodedValue); } //----------------------------------------------------------------------------- GET_USER::PARSER::~PARSER() diff --git a/libs/srvconf/parsers/server_info.cpp b/libs/srvconf/parsers/server_info.cpp index f0033611..86211971 100644 --- a/libs/srvconf/parsers/server_info.cpp +++ b/libs/srvconf/parsers/server_info.cpp @@ -44,7 +44,7 @@ SERVER_INFO::PARSER::PARSER(CALLBACK f, void * d, const std::string & e) AddParser(propertyParsers, "tariff_num", info.tariffNum); for (size_t i = 0; i < DIR_NUM; i++) - AddParser(propertyParsers, "dir_name_" + unsigned2str(i), info.dirName[i], GetEncodedValue); + AddParser(propertyParsers, "dir_name_" + std::to_string(i), info.dirName[i], GetEncodedValue); } //----------------------------------------------------------------------------- int SERVER_INFO::PARSER::ParseStart(const char *el, const char **attr) diff --git a/sgconf/actions.h b/sgconf/actions.h index 08dc177e..69407de2 100644 --- a/sgconf/actions.h +++ b/sgconf/actions.h @@ -109,7 +109,7 @@ template inline std::string PARAM_ACTION::DefaultDescription() const { -return m_hasDefault ? " (default: '" + x2str(m_defaltValue) + "')" +return m_hasDefault ? " (default: '" + std::to_string(m_defaltValue) + "')" : ""; } diff --git a/sgconf/config.h b/sgconf/config.h index 271837cc..bb4f360a 100644 --- a/sgconf/config.h +++ b/sgconf/config.h @@ -70,11 +70,11 @@ struct CONFIG if (!server.empty()) res += "server: '" + server.data() + "'\n"; if (!port.empty()) - res += "port: " + x2str(port.data()) + "\n"; + res += "port: " + std::to_string(port.data()) + "\n"; if (!localAddress.empty()) res += "local address: '" + localAddress.data() + "'\n"; if (!localPort.empty()) - res += "local port: " + x2str(localPort.data()) + "\n"; + res += "local port: " + std::to_string(localPort.data()) + "\n"; if (!userName.empty()) res += "userName: '" + userName.data() + "'\n"; if (!userPass.empty()) diff --git a/sgconf/users.cpp b/sgconf/users.cpp index 018556df..4fcd3559 100644 --- a/sgconf/users.cpp +++ b/sgconf/users.cpp @@ -189,7 +189,7 @@ void ConvSessionTraff(std::string value, USER_STAT_RES & res) value.erase(std::remove(value.begin(), value.end(), ' '), value.end()); std::vector traff(Split >(value, ',', ConvTraff)); if (traff.size() != DIR_NUM) - throw SGCONF::ACTION::ERROR("There should be prcisely " + x2str(DIR_NUM) + " records of session traffic."); + throw SGCONF::ACTION::ERROR("There should be prcisely " + std::to_string(DIR_NUM) + " records of session traffic."); for (size_t i = 0; i < DIR_NUM; ++i) { res.sessionUp[i] = traff[i].up; @@ -202,7 +202,7 @@ void ConvMonthTraff(std::string value, USER_STAT_RES & res) value.erase(std::remove(value.begin(), value.end(), ' '), value.end()); std::vector traff(Split >(value, ',', ConvTraff)); if (traff.size() != DIR_NUM) - throw SGCONF::ACTION::ERROR("There should be prcisely " + x2str(DIR_NUM) + " records of month traffic."); + throw SGCONF::ACTION::ERROR("There should be prcisely " + std::to_string(DIR_NUM) + " records of month traffic."); for (size_t i = 0; i < DIR_NUM; ++i) { res.monthUp[i] = traff[i].up; diff --git a/stargazer/plugins/capture/nfqueue/nfqueue.cpp b/stargazer/plugins/capture/nfqueue/nfqueue.cpp index 0c14c10f..e0248df6 100644 --- a/stargazer/plugins/capture/nfqueue/nfqueue.cpp +++ b/stargazer/plugins/capture/nfqueue/nfqueue.cpp @@ -146,14 +146,14 @@ if (nfq_bind_pf(nfqHandle, AF_INET) < 0) queueHandle = nfq_create_queue(nfqHandle, queueNumber, &Callback, this); if (queueHandle == NULL) { - errorStr = "Failed to create queue " + x2str(queueNumber) + "."; + errorStr = "Failed to create queue " + std::to_string(queueNumber) + "."; logger(errorStr); return -1; } if (nfq_set_mode(queueHandle, NFQNL_COPY_PACKET, 0xffFF) < 0) { - errorStr = "Failed to set queue " + x2str(queueNumber) + " mode."; + errorStr = "Failed to set queue " + std::to_string(queueNumber) + " mode."; logger(errorStr); return -1; } diff --git a/stargazer/plugins/configuration/rpcconfig/user_helper.cpp b/stargazer/plugins/configuration/rpcconfig/user_helper.cpp index ac6e7261..d101e297 100644 --- a/stargazer/plugins/configuration/rpcconfig/user_helper.cpp +++ b/stargazer/plugins/configuration/rpcconfig/user_helper.cpp @@ -94,15 +94,10 @@ supload = ptr->GetSessionDownload(); for (int j = 0; j < DIR_NUM; j++) { - std::string value; - x2str(upload[j], value); - mu[j] = xmlrpc_c::value_string(value); - x2str(download[j], value); - md[j] = xmlrpc_c::value_string(value); - x2str(supload[j], value); - su[j] = xmlrpc_c::value_string(value); - x2str(sdownload[j], value); - sd[j] = xmlrpc_c::value_string(value); + mu[j] = xmlrpc_c::value_string(std::to_string(upload[j])); + md[j] = xmlrpc_c::value_string(std::to_string(download[j])); + su[j] = xmlrpc_c::value_string(std::to_string(supload[j])); + sd[j] = xmlrpc_c::value_string(std::to_string(sdownload[j])); } traffInfo["mu"] = xmlrpc_c::value_array(mu); diff --git a/stargazer/plugins/configuration/sgconfig/conn.h b/stargazer/plugins/configuration/sgconfig/conn.h index 9f56c4df..e3858811 100644 --- a/stargazer/plugins/configuration/sgconfig/conn.h +++ b/stargazer/plugins/configuration/sgconfig/conn.h @@ -65,7 +65,7 @@ class Conn uint32_t IP() const { return *(uint32_t *)(&m_addr.sin_addr); } uint16_t Port() const { return ntohs(m_addr.sin_port); } - std::string endpoint() const { return inet_ntostring(IP()) + ":" + x2str(Port()); } + std::string endpoint() const { return inet_ntostring(IP()) + ":" + std::to_string(Port()); } bool Read(); diff --git a/stargazer/plugins/configuration/sgconfig/dumphelpers.h b/stargazer/plugins/configuration/sgconfig/dumphelpers.h index cc02d14d..86bf197e 100644 --- a/stargazer/plugins/configuration/sgconfig/dumphelpers.h +++ b/stargazer/plugins/configuration/sgconfig/dumphelpers.h @@ -73,13 +73,13 @@ class Dumper std::string twoDigit(int value) const { - std::string res = x2str(value); + std::string res = std::to_string(value); if (res.length() < 2) res = "0" + res; return res; } }; -} // namespace Caster +} // namespace STG #endif diff --git a/stargazer/plugins/configuration/sgconfig/parser_admins.cpp b/stargazer/plugins/configuration/sgconfig/parser_admins.cpp index 0db867bb..f3a9aa31 100644 --- a/stargazer/plugins/configuration/sgconfig/parser_admins.cpp +++ b/stargazer/plugins/configuration/sgconfig/parser_admins.cpp @@ -57,7 +57,7 @@ void GET_ADMINS::CreateAnswer() (ac.priv.userAddDel << 8) + (ac.priv.adminChg << 10) + (ac.priv.tariffChg << 12); - m_answer += ""; + m_answer += ""; } m_admins.CloseSearch(h); m_answer += ""; diff --git a/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp b/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp index 75be7537..1b47d571 100644 --- a/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp +++ b/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp @@ -47,15 +47,15 @@ void GET_SERVER_INFO::CreateAnswer() utsn.nodename; m_answer = std::string("" + - "" + + "" + "" + - "" + + "" + "" + - "" + - ""; + "" + + ""; for (size_t i = 0; i< DIR_NUM; i++) - m_answer += ""; + m_answer += ""; m_answer += ""; } diff --git a/stargazer/plugins/configuration/sgconfig/parser_services.cpp b/stargazer/plugins/configuration/sgconfig/parser_services.cpp index a9599d54..b8a09775 100644 --- a/stargazer/plugins/configuration/sgconfig/parser_services.cpp +++ b/stargazer/plugins/configuration/sgconfig/parser_services.cpp @@ -53,8 +53,8 @@ void GET_SERVICES::CreateAnswer() { m_answer += ""; + "\" cost=\"" + std::to_string(conf.cost) + + "\" payDay=\"" + std::to_string(conf.payDay) + "\"/>"; } m_services.CloseSearch(h); m_answer += ""; @@ -86,8 +86,8 @@ void GET_SERVICE::CreateAnswer() else m_answer += "<" + m_tag + " name=\"" + conf.name + "\" comment=\"" + Encode12str(conf.comment) + - "\" cost=\"" + x2str(conf.cost) + - "\" payDay=\"" + x2str(conf.payDay) + "\"/>"; + "\" cost=\"" + std::to_string(conf.cost) + + "\" payDay=\"" + std::to_string(conf.payDay) + "\"/>"; } int ADD_SERVICE::Start(void *, const char * el, const char ** attr) diff --git a/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp b/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp index 9c752674..dfe6b552 100644 --- a/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp +++ b/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp @@ -51,7 +51,7 @@ std::string AOS2String(const A & array, size_t size, const F C::* field, F multi { if (!res.empty()) res += "/"; - res += x2str((array[i].*field) * multiplier); + res += std::to_string((array[i].*field) * multiplier); } return res; } @@ -98,9 +98,9 @@ void GET_TARIFFS::CreateAnswer() m_answer += "tariffConf.name + "\">"; for (size_t i = 0; i < DIR_NUM; i++) - m_answer += "dirPrice[i].hDay) + ":" + x2str(it->dirPrice[i].mDay) + "-" + - x2str(it->dirPrice[i].hNight) + ":" + x2str(it->dirPrice[i].mNight) + "\"/>"; + m_answer += "dirPrice[i].hDay) + ":" + std::to_string(it->dirPrice[i].mDay) + "-" + + std::to_string(it->dirPrice[i].hNight) + ":" + std::to_string(it->dirPrice[i].mNight) + "\"/>"; m_answer += "dirPrice, DIR_NUM, &DIRPRICE_DATA::priceDayA, pt_mega) + "\"/>" + "dirPrice, DIR_NUM, &DIRPRICE_DATA::priceDayB, pt_mega) + "\"/>" + @@ -109,13 +109,13 @@ void GET_TARIFFS::CreateAnswer() "dirPrice, DIR_NUM, &DIRPRICE_DATA::threshold, 1) + "\"/>" + "dirPrice, DIR_NUM, &DIRPRICE_DATA::singlePrice, 1) + "\"/>" + "dirPrice, DIR_NUM, &DIRPRICE_DATA::noDiscount, 1) + "\"/>" + - "tariffConf.fee) + "\"/>" + - "tariffConf.passiveCost) + "\"/>" + - "tariffConf.free) + "\"/>" + + "tariffConf.fee) + "\"/>" + + "tariffConf.passiveCost) + "\"/>" + + "tariffConf.free) + "\"/>" + "tariffConf.traffType) + "\"/>" + "tariffConf.period) + "\"/>" + "tariffConf.changePolicy) + "\"/>" + - "tariffConf.changePolicyTimeout) + "\"/>" + + "tariffConf.changePolicyTimeout) + "\"/>" + ""; } diff --git a/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp b/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp index 89dd3883..91de27ac 100644 --- a/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp +++ b/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp @@ -50,8 +50,8 @@ void USER_INFO::CreateAnswer() return; } - m_answer = "GetAuthorizedModificationTime()) + "\"" + - " lastDisconnectTime=\"" + x2str(u->GetConnectedModificationTime()) + "\"" + + m_answer = "GetAuthorizedModificationTime()) + "\"" + + " lastDisconnectTime=\"" + std::to_string(u->GetConnectedModificationTime()) + "\"" + " connected=\"" + (u->GetConnected() ? "true" : "false") + "\"" + " lastDisconnectReason=\"" + u->GetLastDisconnectReason() + "\">"; std::vector list(u->GetAuthorizers()); diff --git a/stargazer/plugins/configuration/sgconfig/parser_users.cpp b/stargazer/plugins/configuration/sgconfig/parser_users.cpp index 5707b726..4f9d3021 100644 --- a/stargazer/plugins/configuration/sgconfig/parser_users.cpp +++ b/stargazer/plugins/configuration/sgconfig/parser_users.cpp @@ -67,11 +67,11 @@ std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_ } if (user.GetProperty().cash.ModificationTime() > lastTime) - answer += ""; + answer += ""; if (user.GetProperty().freeMb.ModificationTime() > lastTime) - answer += ""; + answer += ""; if (user.GetProperty().credit.ModificationTime() > lastTime) - answer += ""; + answer += ""; if (user.GetProperty().nextTariff.Get() != "") { @@ -108,7 +108,7 @@ std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_ for (size_t i = 0; i < userdata.size(); i++) if (userdata[i]->ModificationTime() > lastTime) - answer += "Get()) + "\" />"; + answer += "Get()) + "\" />"; if (user.GetProperty().realName.ModificationTime() > lastTime) answer += ""; @@ -121,7 +121,7 @@ std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_ if (user.GetCurrIPModificationTime() > lastTime) answer += ""; if (user.GetPingTime() > lastTime) - answer += ""; + answer += ""; if (user.GetProperty().ips.ModificationTime() > lastTime) answer += ""; @@ -130,16 +130,16 @@ std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_ const DIR_TRAFF & download(user.GetProperty().down.Get()); if (user.GetProperty().up.ModificationTime() > lastTime) for (size_t j = 0; j < DIR_NUM; j++) - answer += " MU" + x2str(j) + "=\"" + x2str(upload[j]) + "\""; + answer += " MU" + std::to_string(j) + "=\"" + std::to_string(upload[j]) + "\""; if (user.GetProperty().down.ModificationTime() > lastTime) for (size_t j = 0; j < DIR_NUM; j++) - answer += " MD" + x2str(j) + "=\"" + x2str(download[j]) + "\""; + answer += " MD" + std::to_string(j) + "=\"" + std::to_string(download[j]) + "\""; if (user.GetSessionUploadModificationTime() > lastTime) for (size_t j = 0; j < DIR_NUM; j++) - answer += " SU" + x2str(j) + "=\"" + x2str(user.GetSessionUpload()[j]) + "\""; + answer += " SU" + std::to_string(j) + "=\"" + std::to_string(user.GetSessionUpload()[j]) + "\""; if (user.GetSessionDownloadModificationTime() > lastTime) for (size_t j = 0; j < DIR_NUM; j++) - answer += " SD" + x2str(j) + "=\"" + x2str(user.GetSessionDownload()[j]) + "\""; + answer += " SD" + std::to_string(j) + "=\"" + std::to_string(user.GetSessionDownload()[j]) + "\""; answer += "/>"; if (user.GetProperty().disabled.ModificationTime() > lastTime) @@ -149,13 +149,13 @@ std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_ if (user.GetProperty().passive.ModificationTime() > lastTime) answer += std::string(""; if (user.GetProperty().lastCashAdd.ModificationTime() > lastTime) - answer += ""; + answer += ""; if (user.GetProperty().lastCashAddTime.ModificationTime() > lastTime) - answer += ""; + answer += ""; if (user.GetProperty().lastActivityTime.ModificationTime() > lastTime) - answer += ""; + answer += ""; if (user.GetProperty().creditExpire.ModificationTime() > lastTime) - answer += ""; + answer += ""; if (lastTime == 0) { @@ -197,7 +197,7 @@ void GET_USERS::CreateAnswer() assert(h); if (m_lastUserUpdateTime > 0) - m_answer = ""; + m_answer = ""; else m_answer = ""; diff --git a/stargazer/plugins/other/radius/config.cpp b/stargazer/plugins/other/radius/config.cpp index 79822852..0b486b34 100644 --- a/stargazer/plugins/other/radius/config.cpp +++ b/stargazer/plugins/other/radius/config.cpp @@ -41,7 +41,7 @@ struct ParserError : public std::runtime_error error(message) {} ParserError(size_t pos, const std::string& message) - : runtime_error("Parsing error at position " + x2str(pos) + ". " + message), + : runtime_error("Parsing error at position " + std::to_string(pos) + ". " + message), position(pos), error(message) {} diff --git a/stargazer/plugins/other/radius/radius.cpp b/stargazer/plugins/other/radius/radius.cpp index 45a9d0e1..ad9135a5 100644 --- a/stargazer/plugins/other/radius/radius.cpp +++ b/stargazer/plugins/other/radius/radius.cpp @@ -362,7 +362,7 @@ void RADIUS::acceptTCP() m_logger(m_error); return; } - std::string remote = inet_ntostring(addr.sin_addr.s_addr) + ":" + x2str(ntohs(addr.sin_port)); + std::string remote = inet_ntostring(addr.sin_addr.s_addr) + ":" + std::to_string(ntohs(addr.sin_port)); printfd(__FILE__, "New TCP connection: '%s'\n", remote.c_str()); m_conns.push_back(new Conn(*m_users, m_logger, *this, m_config, res, remote)); } diff --git a/stargazer/plugins/other/smux/sensors.cpp b/stargazer/plugins/other/smux/sensors.cpp index f52a413b..21e48ddc 100644 --- a/stargazer/plugins/other/smux/sensors.cpp +++ b/stargazer/plugins/other/smux/sensors.cpp @@ -41,9 +41,7 @@ while (!users.SearchNext(handle, &user)) users.CloseSearch(handle); -std::string res; -x2str(count, res); -return res; +return std::to_string(count); } #endif diff --git a/stargazer/plugins/other/smux/sensors.h b/stargazer/plugins/other/smux/sensors.h index 35de996c..4cecfe07 100644 --- a/stargazer/plugins/other/smux/sensors.h +++ b/stargazer/plugins/other/smux/sensors.h @@ -40,7 +40,7 @@ class TotalUsersSensor : public Sensor { #ifdef DEBUG std::string ToString() const - { std::string res; x2str(users.Count(), res); return res; } + { std::string res; std::to_string(users.Count(), res); return res; } #endif private: @@ -185,7 +185,7 @@ class TotalTariffsSensor : public Sensor { #ifdef DEBUG std::string ToString() const - { std::string res; x2str(tariffs.Count(), res); return res; } + { std::string res; std::to_string(tariffs.Count(), res); return res; } #endif private: @@ -205,7 +205,7 @@ class TotalAdminsSensor : public Sensor { #ifdef DEBUG std::string ToString() const - { std::string res; x2str(admins.Count(), res); return res; } + { std::string res; std::to_string(admins.Count(), res); return res; } #endif private: @@ -225,7 +225,7 @@ class TotalServicesSensor : public Sensor { #ifdef DEBUG std::string ToString() const - { std::string res; x2str(services.Count(), res); return res; } + { std::string res; std::to_string(services.Count(), res); return res; } #endif private: @@ -245,7 +245,7 @@ class TotalCorporationsSensor : public Sensor { #ifdef DEBUG std::string ToString() const - { std::string res; x2str(corporations.Count(), res); return res; } + { std::string res; std::to_string(corporations.Count(), res); return res; } #endif private: @@ -265,7 +265,7 @@ class TotalRulesSensor : public Sensor { #ifdef DEBUG std::string ToString() const - { std::string res; x2str(traffcounter.RulesCount(), res); return res; } + { std::string res; std::to_string(traffcounter.RulesCount(), res); return res; } #endif private: @@ -283,7 +283,7 @@ class ConstSensor : public Sensor { #ifdef DEBUG std::string ToString() const - { std::string res; x2str(value, res); return res; } + { std::string res; std::to_string(value, res); return res; } #endif private: diff --git a/stargazer/plugins/store/files/file_store.cpp b/stargazer/plugins/store/files/file_store.cpp index 4c95aa31..39a05f4e 100644 --- a/stargazer/plugins/store/files/file_store.cpp +++ b/stargazer/plugins/store/files/file_store.cpp @@ -1840,9 +1840,8 @@ stIter = statTree.begin(); while (stIter != statTree.end()) { - std::string u, d; - x2str(stIter->second.up, u); - x2str(stIter->second.down, d); + const auto u = std::to_string(stIter->second.up); + const auto d = std::to_string(stIter->second.down); #ifdef TRAFF_STAT_WITH_PORTS if (fprintf(statFile, "%17s:%hu\t%15d\t%15s\t%15s\t%f\n", inet_ntostring(stIter->first.ip).c_str(), @@ -1944,12 +1943,10 @@ strprintf(&fileName, "%s/%s/messages/%lld", storeSettings.GetUsersDir().c_str(), if (access(fileName.c_str(), F_OK) != 0) { - std::string idstr; - x2str(msg.header.id, idstr); STG_LOCKER lock(&mutex); errorStr = "Message for user \'"; errorStr += login + "\' with ID \'"; - errorStr += idstr + "\' does not exist."; + errorStr += std::to_string(msg.header.id) + "\' does not exist."; printfd(__FILE__, "FILES_STORE::EditMessage - %s\n", errorStr.c_str()); return -1; } diff --git a/stargazer/plugins/store/mysql/mysql_store.cpp b/stargazer/plugins/store/mysql/mysql_store.cpp index adb3b895..a1723efd 100644 --- a/stargazer/plugins/store/mysql/mysql_store.cpp +++ b/stargazer/plugins/store/mysql/mysql_store.cpp @@ -701,7 +701,7 @@ int MYSQL_STORE::AddUser(const std::string & login) const std::string query = "INSERT INTO users SET login='" + login + "',Note='',NAS=''"; for (int i = 0; i < USERDATA_NUM; i++) - query += ",Userdata" + x2str(i) + "=''"; + query += ",Userdata" + std::to_string(i) + "=''"; if(MysqlSetQuery(query.c_str())) {