diff --git a/CMakeLists.txt b/CMakeLists.txt index 592281c92..2ce954697 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -485,7 +485,6 @@ target_link_libraries(boost_log Boost::bind Boost::exception Boost::interprocess - Boost::lexical_cast Boost::optional Boost::random Boost::spirit @@ -544,7 +543,6 @@ set(boost_log_setup_public_deps Boost::config Boost::core Boost::iterator - Boost::lexical_cast Boost::move Boost::optional Boost::parameter diff --git a/example/doc/extension_filter_parser.cpp b/example/doc/extension_filter_parser.cpp index 016f40083..1b9721fa3 100644 --- a/example/doc/extension_filter_parser.cpp +++ b/example/doc/extension_filter_parser.cpp @@ -6,11 +6,11 @@ */ #include +#include #include #include #include #include -#include #include #include #include @@ -110,12 +110,23 @@ class point_filter_factory : logging::filter on_equality_relation(logging::attribute_name const& name, string_type const& arg) { - return expr::attr< point >(name) == boost::lexical_cast< point >(arg); + return expr::attr< point >(name) == parse_argument(arg); } logging::filter on_inequality_relation(logging::attribute_name const& name, string_type const& arg) { - return expr::attr< point >(name) != boost::lexical_cast< point >(arg); + return expr::attr< point >(name) != parse_argument(arg); + } + +private: + static point parse_argument(string_type const& arg) + { + std::istringstream strm(arg); + point val; + strm >> val; + if (strm.fail() || strm.bad()) + throw std::runtime_error("Failed to parse point from \"" + arg + "\""); + return val; } }; diff --git a/example/doc/extension_filter_parser_custom_rel.cpp b/example/doc/extension_filter_parser_custom_rel.cpp index 0498a0059..7390b9c65 100644 --- a/example/doc/extension_filter_parser_custom_rel.cpp +++ b/example/doc/extension_filter_parser_custom_rel.cpp @@ -6,11 +6,11 @@ */ #include +#include #include #include #include #include -#include #include #include #include @@ -142,22 +142,34 @@ class point_filter_factory : logging::filter on_equality_relation(logging::attribute_name const& name, string_type const& arg) { - return expr::attr< point >(name) == boost::lexical_cast< point >(arg); + return expr::attr< point >(name) == parse_argument< point >(arg); } logging::filter on_inequality_relation(logging::attribute_name const& name, string_type const& arg) { - return expr::attr< point >(name) != boost::lexical_cast< point >(arg); + return expr::attr< point >(name) != parse_argument< point >(arg); } logging::filter on_custom_relation(logging::attribute_name const& name, string_type const& rel, string_type const& arg) { if (rel == "is_in_rectangle") { - return boost::phoenix::bind(&is_in_rectangle, expr::attr< point >(name), boost::lexical_cast< rectangle >(arg)); + return boost::phoenix::bind(&is_in_rectangle, expr::attr< point >(name), parse_argument< rectangle >(arg)); } throw std::runtime_error("Unsupported filter relation: " + rel); } + +private: + template< typename ArgumentT > + static ArgumentT parse_argument(string_type const& arg) + { + std::istringstream strm(arg); + ArgumentT val; + strm >> val; + if (strm.fail() || strm.bad()) + throw std::runtime_error("Failed to parse argument from \"" + arg + "\""); + return val; + } }; void init_factories() diff --git a/example/doc/extension_stat_collector_settings.cpp b/example/doc/extension_stat_collector_settings.cpp index b333c4e1c..6d81cb24c 100644 --- a/example/doc/extension_stat_collector_settings.cpp +++ b/example/doc/extension_stat_collector_settings.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -169,7 +168,7 @@ class stat_collector_factory : boost::posix_time::time_duration write_interval = boost::posix_time::minutes(1); if (boost::optional< std::string > param = settings["WriteInterval"]) { - unsigned int sec = boost::lexical_cast< unsigned int >(param.get()); + unsigned long sec = std::stoul(param.get()); write_interval = boost::posix_time::seconds(sec); } diff --git a/include/boost/log/utility/setup/filter_parser.hpp b/include/boost/log/utility/setup/filter_parser.hpp index 9a6c9f6d2..16d2cc547 100644 --- a/include/boost/log/utility/setup/filter_parser.hpp +++ b/include/boost/log/utility/setup/filter_parser.hpp @@ -16,7 +16,7 @@ #define BOOST_LOG_UTILITY_SETUP_FILTER_PARSER_HPP_INCLUDED_ #include -#include +#include #include #include #include @@ -217,7 +217,12 @@ class basic_filter_factory : */ virtual value_type parse_argument(string_type const& arg) { - return boost::lexical_cast< value_type >(arg); + std::basic_istringstream< typename base_type::char_type > strm(arg); + value_type val{}; + strm >> val; + if (BOOST_UNLIKELY((strm.rdstate() & (std::ios_base::badbit | std::ios_base::failbit)) != 0)) + BOOST_LOG_THROW_DESCR(parse_error, "Failed to parse argument value from \"" + boost::log::aux::to_narrow(arg) + "\""); + return val; } }; diff --git a/src/process_name.cpp b/src/process_name.cpp index 864defaca..b44d00c10 100644 --- a/src/process_name.cpp +++ b/src/process_name.cpp @@ -113,7 +113,7 @@ BOOST_LOG_CLOSE_NAMESPACE // namespace log #include #include #include -#include +#include #include #include @@ -137,7 +137,7 @@ BOOST_LOG_API std::string get_process_name() if (filesystem::exists("/proc/curproc/file")) return filesystem::read_symlink("/proc/curproc/file").filename().string(); - return boost::lexical_cast< std::string >(getpid()); + return std::to_string(getpid()); } } // namespace aux @@ -151,7 +151,7 @@ BOOST_LOG_CLOSE_NAMESPACE // namespace log #else #include -#include +#include #include #include @@ -173,7 +173,7 @@ BOOST_LOG_API std::string get_process_name() if (filesystem::exists("/proc/curproc/exe")) return filesystem::read_symlink("/proc/curproc/exe").filename().string(); - return boost::lexical_cast< std::string >(getpid()); + return std::to_string(getpid()); } } // namespace aux