Subject: Re: [Boost-bugs] [Boost C++ Libraries] #287: wrong usage of ios_base::narrow
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-05-29 18:27:52
#287: wrong usage of ios_base::narrow
---------------------------+------------------------------------------------
Reporter: vandrejev | Owner: az_sw_dude
Type: Bugs | Status: assigned
Milestone: Boost 1.40.0 | Component: date_time
Version: None | Severity: Problem
Resolution: None | Keywords:
---------------------------+------------------------------------------------
Changes (by marshall):
* severity: => Problem
* milestone: => Boost 1.40.0
Old description:
> {{{
> /cvsroot/boost/boost/boost/date_time/date_parsing.hpp
> revision 1.18, lines 207, 214
>
> std::stringstream has char_type typedef evidently equal
> to char, not wchar_t, so in std::stringstream::narrow
> function the first argument has type char and in the call
>
> ss << ss.narrow(*beg++, 'X');
>
> *beg will be converted from wchar_t to char before call
> to narrow will be made.
>
> I suggest the following patch:
>
> diff -c -r1.18 date_parsing.hpp
> ***************
> *** 207,214 ****
> wchar_t)
> {
> std::stringstream ss("");
> while(beg != end) {
> ! ss << ss.narrow(*beg++, 'X'); // 'X' will cause
> exception to be thrown
> }
> return parse_date<date_type>(ss.str());
> }
> --- 207,215 ----
> wchar_t)
> {
> std::stringstream ss("");
> + std::locale loc;
> while(beg != end) {
> ! ss << std::use_facet<std::ctype<wchar_t> >
> (loc).narrow(*beg++, 'X');
> }
> return parse_date<date_type>(ss.str());
> }
>
> }}}
New description:
{{{
/cvsroot/boost/boost/boost/date_time/date_parsing.hpp
revision 1.18, lines 207, 214
std::stringstream has char_type typedef evidently equal
to char, not wchar_t, so in std::stringstream::narrow
function the first argument has type char and in the call
ss << ss.narrow(*beg++, 'X');
*beg will be converted from wchar_t to char before call
to narrow will be made.
I suggest the following patch:
diff -c -r1.18 date_parsing.hpp
***************
*** 207,214 ****
wchar_t)
{
std::stringstream ss("");
while(beg != end) {
! ss << ss.narrow(*beg++, 'X'); // 'X' will cause
exception to be thrown
}
return parse_date<date_type>(ss.str());
}
--- 207,215 ----
wchar_t)
{
std::stringstream ss("");
+ std::locale loc;
while(beg != end) {
! ss << std::use_facet<std::ctype<wchar_t> >
(loc).narrow(*beg++, 'X');
}
return parse_date<date_type>(ss.str());
}
}}}
-- Comment: Marshall sez: looking at the code in trunk, it appears that this patch has been (more or less) applied. I'm not sure about the constructor call to std:locale() for each character, though. {{ while(beg != end) { #if !defined(BOOST_DATE_TIME_NO_LOCALE) ss << std::use_facet<std::ctype<wchar_t> >(std::locale()).narrow(*beg++, 'X'); // 'X' will cause exception to be thrown #else ss << ss.narrow(*beg++, 'X'); #endif } }} -- Ticket URL: <https://svn.boost.org/trac/boost/ticket/287#comment:1> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:00 UTC