From f19fe76dde04cb4e37fc4bf07ccb441d5e76ad3b Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Wed, 12 Nov 2003 02:58:06 +0000 Subject: [PATCH] fixes for tolower issues [SVN r20789] --- include/boost/date_time/compiler_config.hpp | 4 --- include/boost/date_time/date_parsing.hpp | 36 +++++++++++++++++---- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/include/boost/date_time/compiler_config.hpp b/include/boost/date_time/compiler_config.hpp index 258851d..666e90a 100644 --- a/include/boost/date_time/compiler_config.hpp +++ b/include/boost/date_time/compiler_config.hpp @@ -31,10 +31,6 @@ #define INT64_C(value) int64_t(value) #endif -//Workaround for missing transform -#if (defined(__BORLANDC__) || (defined(BOOST_MSVC) && (_MSC_VER <= 1200))) -#define BOOST_DATE_TIME_NO_STD_TRANSFORM 1 -#endif /* Workaround for Borland iterator error. Error was "Cannot convert 'istream *' to 'wistream *' in function istream_iterator<>::istream_iterator() */ #if defined(__BORLANDC__) && (__BORLANDC__ <= 0x0551) diff --git a/include/boost/date_time/date_parsing.hpp b/include/boost/date_time/date_parsing.hpp index 9725f2d..e1c4ddd 100644 --- a/include/boost/date_time/date_parsing.hpp +++ b/include/boost/date_time/date_parsing.hpp @@ -14,10 +14,39 @@ #include #include +#if !defined(BOOST_NO_STD_LOCALE) +#include +#endif + namespace boost { namespace date_time { + //! 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). + * In the event that a compiler does not support locales, the old + * C style tolower() is used. + */ + inline + std::string convert_to_lower(const std::string& inp) + { + std::string tmp(""); + unsigned i = 0; +#if defined(BOOST_NO_STD_LOCALE) + while(i < inp.length()) + { + tmp += static_cast(tolower(inp.at(i++))); +#else + std::locale loc(""); + while(i < inp.length()) + { + tmp += std::tolower(inp.at(i++), loc); +#endif + } + return std::string(tmp); + } + //! Generic function to parse a delimited date (eg: 2002-02-10) /*! Accepted formats are: "2003-02-10" or " 2003-Feb-10" or * "2003-Feburary-10" @@ -52,12 +81,7 @@ namespace date_time { else { typename month_type::month_map_ptr_type ptr = month_type::get_month_map_ptr(); -#if defined(BOOST_DATE_TIME_NO_STD_TRANSFORM) -#else - std::transform(s.begin(), s.end(), - s.begin(), - tolower); -#endif + s = convert_to_lower(s); typename month_type::month_map_type::iterator iter = ptr->find(s); if(iter != ptr->end()) // required for STLport {