locale_facets.tcc (time_put::put): Correct output iterator positions.
2002-01-14 Benjamin Kosnik <bkoz@redhat.com> * include/bits/locale_facets.tcc (time_put::put): Correct output iterator positions. * testsuite/22_locale/time_put_members_char.cc (test02): Add. * testsuite/22_locale/time_put_members_wchar_t.cc (test02): Add. * testsuite/22_locale/time_get_members_wchar_t.cc (test06): Add. * testsuite/22_locale/time_get_members_char.cc (test06): Add. From-SVN: r48861
This commit is contained in:
parent
749d98f055
commit
8f88da406b
@ -1,3 +1,12 @@
|
||||
2002-01-14 Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
* include/bits/locale_facets.tcc (time_put::put): Correct output
|
||||
iterator positions.
|
||||
* testsuite/22_locale/time_put_members_char.cc (test02): Add.
|
||||
* testsuite/22_locale/time_put_members_wchar_t.cc (test02): Add.
|
||||
* testsuite/22_locale/time_get_members_wchar_t.cc (test06): Add.
|
||||
* testsuite/22_locale/time_get_members_char.cc (test06): Add.
|
||||
|
||||
2002-01-14 Craig Rodrigues <rodrigc@gcc.gnu.org>
|
||||
|
||||
* docs/html/17_intro/porting-howto.xml: Update filebuf section.
|
||||
|
@ -1521,8 +1521,8 @@ namespace std
|
||||
break;
|
||||
case 'm':
|
||||
// Month [01, 12]. [tm_mon]
|
||||
_M_extract_num(__beg, __end, __mem, 1, 12, 2,
|
||||
__ctype, __err);
|
||||
_M_extract_num(__beg, __end, __mem, 1, 12, 2, __ctype,
|
||||
__err);
|
||||
if (!__err)
|
||||
__tm->tm_mon = __mem - 1;
|
||||
break;
|
||||
@ -1905,10 +1905,14 @@ namespace std
|
||||
}
|
||||
else
|
||||
__format = __c;
|
||||
this->do_put(__s, __io, char_type(), __tm, __format, __mod);
|
||||
__s = this->do_put(__s, __io, char_type(), __tm, __format,
|
||||
__mod);
|
||||
}
|
||||
else
|
||||
__s = __c;
|
||||
{
|
||||
*__s = __c;
|
||||
++__s;
|
||||
}
|
||||
}
|
||||
return __s;
|
||||
}
|
||||
@ -1951,8 +1955,8 @@ namespace std
|
||||
|
||||
// Write resulting, fully-formatted string to output iterator.
|
||||
size_t __len = char_traits<char_type>::length(__res);
|
||||
for (size_t __i = 0; __i < __len; ++__i)
|
||||
__s = __res[__i];
|
||||
for (size_t __i = 0; __i < __len; ++__i, ++__s)
|
||||
*__s = __res[__i];
|
||||
return __s;
|
||||
}
|
||||
|
||||
|
@ -290,4 +290,3 @@ int main()
|
||||
test03();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// 2001-09-21 Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
// Copyright (C) 2001 Free Software Foundation
|
||||
// Copyright (C) 2001-2002 Free Software Foundation
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
@ -585,6 +585,93 @@ void test05()
|
||||
VERIFY( errorstate == ios_base::eofbit );
|
||||
}
|
||||
|
||||
void test06()
|
||||
{
|
||||
using namespace std;
|
||||
bool test = true;
|
||||
|
||||
// Check time_get works with other iterators besides streambuf
|
||||
// input iterators.
|
||||
typedef string::const_iterator iter_type;
|
||||
typedef time_get<char, iter_type> time_get_type;
|
||||
const ios_base::iostate goodbit = ios_base::goodbit;
|
||||
const ios_base::iostate eofbit = ios_base::eofbit;
|
||||
ios_base::iostate err = goodbit;
|
||||
const locale loc_c = locale::classic();
|
||||
// Cindy Sherman's Untitled Film Stills
|
||||
// June 26-September 2, 1997
|
||||
const string str = "12:00:00 06/26/97 Tuesday September 1997 Cindy Sherman";
|
||||
|
||||
// Create "C" time objects
|
||||
const tm time_sanity = { 0, 0, 12, 26, 5, 97, 2 };
|
||||
tm tm1;
|
||||
|
||||
istringstream iss;
|
||||
iss.imbue(locale(loc_c, new time_get_type));
|
||||
|
||||
// Iterator advanced, state, output.
|
||||
const time_get_type& tg = use_facet<time_get_type>(iss.getloc());
|
||||
|
||||
// 01 get_time
|
||||
// 02 get_date
|
||||
// 03 get_weekday
|
||||
// 04 get_monthname
|
||||
// 05 get_year
|
||||
|
||||
// 01 get_time
|
||||
string res1;
|
||||
err = goodbit;
|
||||
iter_type end1 = tg.get_time(str.begin(), str.end(), iss, err, &tm1);
|
||||
string rem1(end1, str.end());
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( tm1.tm_sec == time_sanity.tm_sec );
|
||||
VERIFY( tm1.tm_min == time_sanity.tm_min );
|
||||
VERIFY( tm1.tm_hour == time_sanity.tm_hour );
|
||||
VERIFY( rem1 == " 06/26/97 Tuesday September 1997 Cindy Sherman" );
|
||||
|
||||
// 02 get_date
|
||||
string res2;
|
||||
err = goodbit;
|
||||
// White space is not eaten, so manually increment past it.
|
||||
iter_type end2 = tg.get_date(++end1, str.end(), iss, err, &tm1);
|
||||
string rem2(end2, str.end());
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( tm1.tm_year == time_sanity.tm_year );
|
||||
VERIFY( tm1.tm_mon == time_sanity.tm_mon );
|
||||
VERIFY( tm1.tm_mday == time_sanity.tm_mday );
|
||||
VERIFY( rem2 == " Tuesday September 1997 Cindy Sherman" );
|
||||
|
||||
// 03 get_weekday
|
||||
string res3;
|
||||
err = goodbit;
|
||||
// White space is not eaten, so manually increment past it.
|
||||
iter_type end3 = tg.get_weekday(++end2, str.end(), iss, err, &tm1);
|
||||
string rem3(end3, str.end());
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( tm1.tm_wday == time_sanity.tm_wday );
|
||||
VERIFY( rem3 == " September 1997 Cindy Sherman" );
|
||||
|
||||
// 04 get_monthname
|
||||
string res4;
|
||||
err = goodbit;
|
||||
// White space is not eaten, so manually increment past it.
|
||||
iter_type end4 = tg.get_monthname(++end3, str.end(), iss, err, &tm1);
|
||||
string rem4(end4, str.end());
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( tm1.tm_mon == 8 );
|
||||
VERIFY( rem4 == " 1997 Cindy Sherman" );
|
||||
|
||||
// 05 get_year
|
||||
string res5;
|
||||
err = goodbit;
|
||||
// White space is not eaten, so manually increment past it.
|
||||
iter_type end5 = tg.get_year(++end4, str.end(), iss, err, &tm1);
|
||||
string rem5(end5, str.end());
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( tm1.tm_year == time_sanity.tm_year );
|
||||
VERIFY( rem5 == " Cindy Sherman" );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
@ -592,5 +679,7 @@ int main()
|
||||
test03();
|
||||
test04();
|
||||
test05();
|
||||
|
||||
test06();
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// 2001-10-02 Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
// Copyright (C) 2001 Free Software Foundation
|
||||
// Copyright (C) 2001-2002 Free Software Foundation
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
@ -584,6 +584,93 @@ void test05()
|
||||
VERIFY( time20.tm_year == time_bday.tm_year );
|
||||
VERIFY( errorstate == ios_base::eofbit );
|
||||
}
|
||||
|
||||
void test06()
|
||||
{
|
||||
using namespace std;
|
||||
bool test = true;
|
||||
|
||||
// Check time_get works with other iterators besides streambuf
|
||||
// input iterators.
|
||||
typedef wstring::const_iterator iter_type;
|
||||
typedef time_get<wchar_t, iter_type> time_get_type;
|
||||
const ios_base::iostate goodbit = ios_base::goodbit;
|
||||
const ios_base::iostate eofbit = ios_base::eofbit;
|
||||
ios_base::iostate err = goodbit;
|
||||
const locale loc_c = locale::classic();
|
||||
// Cindy Sherman's Untitled Film Stills
|
||||
// June 26-September 2, 1997
|
||||
const wstring str = L"12:00:00 06/26/97 Tuesday September 1997 Cindy Sherman";
|
||||
|
||||
// Create "C" time objects
|
||||
const tm time_sanity = { 0, 0, 12, 26, 5, 97, 2 };
|
||||
tm tm1;
|
||||
|
||||
wistringstream iss;
|
||||
iss.imbue(locale(loc_c, new time_get_type));
|
||||
|
||||
// Iterator advanced, state, output.
|
||||
const time_get_type& tg = use_facet<time_get_type>(iss.getloc());
|
||||
|
||||
// 01 get_time
|
||||
// 02 get_date
|
||||
// 03 get_weekday
|
||||
// 04 get_monthname
|
||||
// 05 get_year
|
||||
|
||||
// 01 get_time
|
||||
wstring res1;
|
||||
err = goodbit;
|
||||
iter_type end1 = tg.get_time(str.begin(), str.end(), iss, err, &tm1);
|
||||
wstring rem1(end1, str.end());
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( tm1.tm_sec == time_sanity.tm_sec );
|
||||
VERIFY( tm1.tm_min == time_sanity.tm_min );
|
||||
VERIFY( tm1.tm_hour == time_sanity.tm_hour );
|
||||
VERIFY( rem1 == L" 06/26/97 Tuesday September 1997 Cindy Sherman" );
|
||||
|
||||
// 02 get_date
|
||||
wstring res2;
|
||||
err = goodbit;
|
||||
// White space is not eaten, so manually increment past it.
|
||||
iter_type end2 = tg.get_date(++end1, str.end(), iss, err, &tm1);
|
||||
wstring rem2(end2, str.end());
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( tm1.tm_year == time_sanity.tm_year );
|
||||
VERIFY( tm1.tm_mon == time_sanity.tm_mon );
|
||||
VERIFY( tm1.tm_mday == time_sanity.tm_mday );
|
||||
VERIFY( rem2 == L" Tuesday September 1997 Cindy Sherman" );
|
||||
|
||||
// 03 get_weekday
|
||||
wstring res3;
|
||||
err = goodbit;
|
||||
// White space is not eaten, so manually increment past it.
|
||||
iter_type end3 = tg.get_weekday(++end2, str.end(), iss, err, &tm1);
|
||||
wstring rem3(end3, str.end());
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( tm1.tm_wday == time_sanity.tm_wday );
|
||||
VERIFY( rem3 == L" September 1997 Cindy Sherman" );
|
||||
|
||||
// 04 get_monthname
|
||||
wstring res4;
|
||||
err = goodbit;
|
||||
// White space is not eaten, so manually increment past it.
|
||||
iter_type end4 = tg.get_monthname(++end3, str.end(), iss, err, &tm1);
|
||||
wstring rem4(end4, str.end());
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( tm1.tm_mon == 8 );
|
||||
VERIFY( rem4 == L" 1997 Cindy Sherman" );
|
||||
|
||||
// 05 get_year
|
||||
wstring res5;
|
||||
err = goodbit;
|
||||
// White space is not eaten, so manually increment past it.
|
||||
iter_type end5 = tg.get_year(++end4, str.end(), iss, err, &tm1);
|
||||
wstring rem5(end5, str.end());
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( tm1.tm_year == time_sanity.tm_year );
|
||||
VERIFY( rem5 == L" Cindy Sherman" );
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
@ -594,6 +681,8 @@ int main()
|
||||
test03();
|
||||
test04();
|
||||
test05();
|
||||
|
||||
test06();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// 2001-09-17 Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
// Copyright (C) 2001 Free Software Foundation
|
||||
// Copyright (C) 2001-2002 Free Software Foundation
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
@ -188,8 +188,52 @@ void test01()
|
||||
VERIFY( result12 != result11 );
|
||||
}
|
||||
|
||||
void test02()
|
||||
{
|
||||
using namespace std;
|
||||
bool test = true;
|
||||
|
||||
// Check time_put works with other iterators besides streambuf
|
||||
// output iterators. (As long as output_iterator requirements are met.)
|
||||
typedef string::iterator iter_type;
|
||||
typedef char_traits<char> traits;
|
||||
typedef time_put<char, iter_type> time_put_type;
|
||||
const ios_base::iostate goodbit = ios_base::goodbit;
|
||||
const ios_base::iostate eofbit = ios_base::eofbit;
|
||||
ios_base::iostate err = goodbit;
|
||||
const locale loc_c = locale::classic();
|
||||
const string x(50, 'x'); // have to have allocated string!
|
||||
string res;
|
||||
const tm time_sanity = { 0, 0, 12, 26, 5, 97, 2 };
|
||||
const char* date = "%X, %A, the second of %B, %Y";
|
||||
|
||||
ostringstream oss;
|
||||
oss.imbue(locale(loc_c, new time_put_type));
|
||||
|
||||
// Iterator advanced, state, output.
|
||||
const time_put_type& tp = use_facet<time_put_type>(oss.getloc());
|
||||
|
||||
// 01 date format
|
||||
res = x;
|
||||
iter_type ret1 = tp.put(res.begin(), oss, ' ', &time_sanity,
|
||||
date, date + traits::length(date));
|
||||
string sanity1(res.begin(), ret1);
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( res == "12:00:00, Tuesday, the second of June, 1997xxxxxxx" );
|
||||
VERIFY( sanity1 == "12:00:00, Tuesday, the second of June, 1997" );
|
||||
|
||||
// 02 char format
|
||||
res = x;
|
||||
iter_type ret2 = tp.put(res.begin(), oss, ' ', &time_sanity, 'A');
|
||||
string sanity2(res.begin(), ret2);
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( res == "Tuesdayxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" );
|
||||
VERIFY( sanity2 == "Tuesday" );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// 2001-10-02 Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
// Copyright (C) 2001 Free Software Foundation
|
||||
// Copyright (C) 2001-2002 Free Software Foundation
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
@ -189,12 +189,56 @@ void test01()
|
||||
wstring result12 = oss.str();
|
||||
VERIFY( result12 != result11 );
|
||||
}
|
||||
|
||||
void test02()
|
||||
{
|
||||
using namespace std;
|
||||
bool test = true;
|
||||
|
||||
// Check time_put works with other iterators besides streambuf
|
||||
// output iterators. (As long as output_iterator requirements are met.)
|
||||
typedef wstring::iterator iter_type;
|
||||
typedef char_traits<wchar_t> traits;
|
||||
typedef time_put<wchar_t, iter_type> time_put_type;
|
||||
const ios_base::iostate goodbit = ios_base::goodbit;
|
||||
const ios_base::iostate eofbit = ios_base::eofbit;
|
||||
ios_base::iostate err = goodbit;
|
||||
const locale loc_c = locale::classic();
|
||||
const wstring x(50, L'x'); // have to have allocated string!
|
||||
wstring res;
|
||||
const tm time_sanity = { 0, 0, 12, 26, 5, 97, 2 };
|
||||
const wchar_t* date = L"%X, %A, the second of %B, %Y";
|
||||
|
||||
ostringstream oss;
|
||||
oss.imbue(locale(loc_c, new time_put_type));
|
||||
|
||||
// Iterator advanced, state, output.
|
||||
const time_put_type& tp = use_facet<time_put_type>(oss.getloc());
|
||||
|
||||
// 01 date format
|
||||
res = x;
|
||||
iter_type ret1 = tp.put(res.begin(), oss, L' ', &time_sanity,
|
||||
date, date + traits::length(date));
|
||||
wstring sanity1(res.begin(), ret1);
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( res == L"12:00:00, Tuesday, the second of June, 1997xxxxxxx" );
|
||||
VERIFY( sanity1 == L"12:00:00, Tuesday, the second of June, 1997" );
|
||||
|
||||
// 02 char format
|
||||
res = x;
|
||||
iter_type ret2 = tp.put(res.begin(), oss, L' ', &time_sanity, 'A');
|
||||
wstring sanity2(res.begin(), ret2);
|
||||
VERIFY( err == goodbit );
|
||||
VERIFY( res == L"Tuesdayxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" );
|
||||
VERIFY( sanity2 == L"Tuesday" );
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _GLIBCPP_USE_WCHAR_T
|
||||
test01();
|
||||
test02();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user