From aa6d63c8cb1e111e2e36d9f0ef06f9aa9f47fe26 Mon Sep 17 00:00:00 2001 From: "Michael T. Wells" Date: Wed, 5 May 2021 11:28:19 -0600 Subject: [PATCH 1/3] replace boost lexical cast with stl string Signed-off-by: Michael T. Wells --- include/boost/date_time/date_parsing.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/boost/date_time/date_parsing.hpp b/include/boost/date_time/date_parsing.hpp index 34e39bd9c..5b06ddc0c 100644 --- a/include/boost/date_time/date_parsing.hpp +++ b/include/boost/date_time/date_parsing.hpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -61,7 +60,7 @@ namespace date_time { inline unsigned short month_str_to_ushort(std::string const& s) { if((s.at(0) >= '0') && (s.at(0) <= '9')) { - return boost::lexical_cast(s); + return static_cast(std::stoul(s, nullptr, 10)); } else { std::string str = convert_to_lower(s); @@ -160,7 +159,7 @@ namespace date_time { switch(spec_str.at(pos)) { case 'y': { - year = boost::lexical_cast(*beg); + year = static_cast(std::stoul(*beg, nullptr, 10)); break; } case 'm': @@ -170,7 +169,7 @@ namespace date_time { } case 'd': { - day = boost::lexical_cast(*beg); + day = static_cast(std::stoul(*beg, nullptr, 10)); break; } default: break; @@ -200,7 +199,8 @@ namespace date_time { std::basic_string > tokenizer_type; tokenizer_type tok(s, osf); for(typename tokenizer_type::iterator ti=tok.begin(); ti!=tok.end();++ti) { - unsigned short i = boost::lexical_cast(*ti); + unsigned short i = static_cast(std::stoul(*ti, nullptr, 10)); + switch(pos) { case 0: y = i; break; case 1: m = i; break; From 9167e36d77e5bc670b71acb81a6b99a62c2ba685 Mon Sep 17 00:00:00 2001 From: "Michael T. Wells" Date: Thu, 6 May 2021 16:48:21 -0600 Subject: [PATCH 2/3] add macro for strinto ushort conversion - string when < c++11 - lexical_cast when >=c++11 Signed-off-by: Michael T. Wells --- include/boost/date_time/date_parsing.hpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/include/boost/date_time/date_parsing.hpp b/include/boost/date_time/date_parsing.hpp index 5b06ddc0c..e420c2ca1 100644 --- a/include/boost/date_time/date_parsing.hpp +++ b/include/boost/date_time/date_parsing.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,14 @@ namespace boost { namespace date_time { +inline unsigned short string_to_ushort(std::string const& s) +{ +#ifdef BOOST_NO_CXX11 + return boost::lexical_cast(s); +#else + return std::stoul(s); +#endif +} //! A function to replace the std::transform( , , ,tolower) construct /*! This function simply takes a string, and changes all the characters * in that string to lowercase (according to the default system locale). @@ -60,7 +69,7 @@ namespace date_time { inline unsigned short month_str_to_ushort(std::string const& s) { if((s.at(0) >= '0') && (s.at(0) <= '9')) { - return static_cast(std::stoul(s, nullptr, 10)); + return string_to_ushort(s); } else { std::string str = convert_to_lower(s); @@ -159,7 +168,7 @@ namespace date_time { switch(spec_str.at(pos)) { case 'y': { - year = static_cast(std::stoul(*beg, nullptr, 10)); + year = string_to_ushort(*beg); break; } case 'm': @@ -169,7 +178,7 @@ namespace date_time { } case 'd': { - day = static_cast(std::stoul(*beg, nullptr, 10)); + day = string_to_ushort(*beg); break; } default: break; @@ -184,6 +193,7 @@ namespace date_time { parse_undelimited_date(const std::string& s) { int offsets[] = {4,2,2}; int pos = 0; + //typename date_type::ymd_type ymd((year_type::min)(),1,1); unsigned short y = 0, m = 0, d = 0; @@ -199,7 +209,7 @@ namespace date_time { std::basic_string > tokenizer_type; tokenizer_type tok(s, osf); for(typename tokenizer_type::iterator ti=tok.begin(); ti!=tok.end();++ti) { - unsigned short i = static_cast(std::stoul(*ti, nullptr, 10)); + unsigned i = string_to_ushort(*ti); switch(pos) { case 0: y = i; break; From 19458343748fa541d3ced9f521d670435723d5e2 Mon Sep 17 00:00:00 2001 From: "Michael T. Wells" Date: Fri, 7 May 2021 15:39:40 -0600 Subject: [PATCH 3/3] add guard around boost lexical cast - TODO: lexical cast called because of unknown needed side effect for gregorian tests Signed-off-by: Michael T. Wells --- include/boost/date_time/date_parsing.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/boost/date_time/date_parsing.hpp b/include/boost/date_time/date_parsing.hpp index e420c2ca1..21f324963 100644 --- a/include/boost/date_time/date_parsing.hpp +++ b/include/boost/date_time/date_parsing.hpp @@ -15,7 +15,9 @@ #include #include #include -#include +#ifdef BOOST_NO_CXX11 + #include +#endif #include #include #include @@ -34,6 +36,8 @@ inline unsigned short string_to_ushort(std::string const& s) #ifdef BOOST_NO_CXX11 return boost::lexical_cast(s); #else + // TODO: lexical cast has some side effect on that makes the std::stoul work here + boost::lexical_cast(s); return std::stoul(s); #endif }