-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace boost lexical cast with stl string #195
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ | |
#include <iterator> | ||
#include <algorithm> | ||
#include <boost/tokenizer.hpp> | ||
#include <boost/lexical_cast.hpp> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So here we should ifdef the include so that if we're supporting pre-11 c++ we will just keep using lexical cast probably the cleanest solution is to move it to the compiler_config.hpp to do the macro check. I looked and can't specific feature macro for these functions so I think I'd go with BOOST_NO_CXX11 boost.config is already included so you should have direct access to this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine sticking with lexical_cast for 03 compiles and just modernizing for 11 and beyond. It seems likely I'll eventually drop 03 support. |
||
#ifdef BOOST_NO_CXX11 | ||
#include <boost/lexical_cast.hpp> | ||
#endif | ||
#include <boost/date_time/compiler_config.hpp> | ||
#include <boost/date_time/parse_format_base.hpp> | ||
#include <boost/date_time/period.hpp> | ||
|
@@ -29,6 +31,16 @@ | |
namespace boost { | ||
namespace date_time { | ||
|
||
inline unsigned short string_to_ushort(std::string const& s) | ||
{ | ||
#ifdef BOOST_NO_CXX11 | ||
return boost::lexical_cast<unsigned short>(s); | ||
#else | ||
// TODO: lexical cast has some side effect on <s> that makes the std::stoul work here | ||
boost::lexical_cast<unsigned short>(s); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JeffGarland This line should be removed, but i was curious how it would run in CI. In my local environment, the tests pass when the |
||
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). | ||
|
@@ -61,7 +73,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<unsigned short>(s); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so my suggestion is we write the function
This can live here or if it's used elsewhere I'd move it to compiler_config.hpp since its a work around |
||
return string_to_ushort(s); | ||
} | ||
else { | ||
std::string str = convert_to_lower(s); | ||
|
@@ -160,7 +172,7 @@ namespace date_time { | |
switch(spec_str.at(pos)) { | ||
case 'y': | ||
{ | ||
year = boost::lexical_cast<unsigned short>(*beg); | ||
year = string_to_ushort(*beg); | ||
break; | ||
} | ||
case 'm': | ||
|
@@ -170,7 +182,7 @@ namespace date_time { | |
} | ||
case 'd': | ||
{ | ||
day = boost::lexical_cast<unsigned short>(*beg); | ||
day = string_to_ushort(*beg); | ||
break; | ||
} | ||
default: break; | ||
|
@@ -185,6 +197,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; | ||
|
||
|
@@ -200,7 +213,8 @@ namespace date_time { | |
std::basic_string<char> > 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<unsigned short>(*ti); | ||
unsigned i = string_to_ushort(*ti); | ||
|
||
switch(pos) { | ||
case 0: y = i; break; | ||
case 1: m = i; break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot about this one as well -- probably this will be next on my radar.