locale_facets.tcc (time_put::put): Correct output iterator positions.
authorBenjamin Kosnik <bkoz@redhat.com>
Tue, 15 Jan 2002 04:23:46 +0000 (04:23 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Tue, 15 Jan 2002 04:23:46 +0000 (04:23 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/locale_facets.tcc
libstdc++-v3/testsuite/22_locale/money_put_members_char.cc
libstdc++-v3/testsuite/22_locale/time_get_members_char.cc
libstdc++-v3/testsuite/22_locale/time_get_members_wchar_t.cc
libstdc++-v3/testsuite/22_locale/time_put_members_char.cc
libstdc++-v3/testsuite/22_locale/time_put_members_wchar_t.cc

index 383bb751da1679eecca6832b3bed3616ac9ca79c..0394ed1f2743be0ab32694ab4b35513de71908ea 100644 (file)
@@ -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.
index 396f4236c4c600da49363e8a74f08e478cdb9d3a..57cab783fe68693061d5a07411a6a96f5d257ff3 100644 (file)
@@ -1516,13 +1516,13 @@ namespace std
                  break;
                case 'I':
                  // Hour [01, 12]. [tm_hour]
-                 _M_extract_num(__beg, __end, __tm->tm_hour, 1, 12, 2,
+                 _M_extract_num(__beg, __end, __tm->tm_hour, 1, 12, 2, 
                                 __ctype, __err);
                  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;
     }
 
index 3c318cec211b3338dcfb6c849e13ac070bf32b9a..3c5ef00edae8a4ac1873c932aa8a02fa437c215b 100644 (file)
@@ -290,4 +290,3 @@ int main()
   test03();
   return 0;
 }
-
index b477ba223174ccaa844891dc5ac60888998369b6..2b69be3317ad9f99a5fbc94da5fd78956ba895a3 100644 (file)
@@ -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;
 }
index dfddc0325c5602c3cdf3b91103cd5a8c4b6b50cc..298d85a12c5674603daa0d17a9437ecc0e1e819c 100644 (file)
@@ -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;
 }
index c751cbd3984d85384721d9a5c900cef922d546ee..96d24fc041e82d7707294a0ab9d783e1ddf63316 100644 (file)
@@ -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;
 }
index cde8bd4baa3f2a9d3ed81039c6bcb966b3054492..48543b7132dc326e64c53a2f86fede7c83287d45 100644 (file)
@@ -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;
 }