From: Maxim Mamontov Date: Tue, 9 Nov 2010 12:36:18 +0000 (+0200) Subject: Добавлена специализация функций str2x для long и unsigned long (на X-Git-Tag: 2.407-rc3~364 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/a5bb534ab656e9eaab163c22df0325d3baa3ce40?ds=inline Добавлена специализация функций str2x для long и unsigned long (на 64-битных системах long != int) --- diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index a5899dd2..eb39da6a 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -728,6 +728,26 @@ int str2x(const std::string & str, unsigned & x) { x = strtoul(str.c_str(), NULL, 10); +if (errno == ERANGE) + return -1; + +return 0; +} +//--------------------------------------------------------------------------- +int str2x(const std::string & str, long & x) +{ +x = strtol(str.c_str(), NULL, 10); + +if (errno == ERANGE) + return -1; + +return 0; +} +//--------------------------------------------------------------------------- +int str2x(const std::string & str, unsigned long & x) +{ +x = strtoul(str.c_str(), NULL, 10); + if (errno == ERANGE) return -1; diff --git a/stglibs/common.lib/common.h b/stglibs/common.lib/common.h index 971a2e72..904c6e47 100644 --- a/stglibs/common.lib/common.h +++ b/stglibs/common.lib/common.h @@ -215,6 +215,8 @@ const std::string & unsigned2str(varT x, std::string & s) //----------------------------------------------------------------------------- int str2x(const std::string & str, int & x); int str2x(const std::string & str, unsigned & x); +int str2x(const std::string & str, long & x); +int str2x(const std::string & str, unsigned long & x); int str2x(const std::string & str, long long & x); int str2x(const std::string & str, unsigned long long & x); //-----------------------------------------------------------------------------