From 0de0b10caa957f793e1f7bec18c1243b39bdc636 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=BCdiger=20Sonderfeld?= Date: Mon, 22 Dec 2014 13:45:52 +0000 Subject: [PATCH] re PR libstdc++/54354 (TODO extended iomanip manipulators std::get_time and std::put_time (C++11, section 27.7.5)) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2014-12-22 Rüdiger Sonderfeld PR libstdc++/54354 * include/std/iomanip (_Get_time): New struct. (get_time): New manipulator. (operator<<): New overloaded function. * testsuite/27_io/manipulators/extended/get_time/char/1.cc: New. * testsuite/27_io/manipulators/extended/get_time/char/2.cc: New. * testsuite/27_io/manipulators/extended/get_time/wchar_t/1.cc: New. * testsuite/27_io/manipulators/extended/get_time/wchar_t/2.cc: New. From-SVN: r219013 --- libstdc++-v3/ChangeLog | 11 ++++ libstdc++-v3/include/std/iomanip | 54 +++++++++++++++++++ .../manipulators/extended/get_time/char/1.cc | 49 +++++++++++++++++ .../manipulators/extended/get_time/char/2.cc | 49 +++++++++++++++++ .../extended/get_time/wchar_t/1.cc | 49 +++++++++++++++++ .../extended/get_time/wchar_t/2.cc | 50 +++++++++++++++++ 6 files changed, 262 insertions(+) create mode 100644 libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/wchar_t/2.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 41a91c54524..6deaf4c6bc6 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2014-12-22 Rüdiger Sonderfeld + + PR libstdc++/54354 + * include/std/iomanip (_Get_time): New struct. + (get_time): New manipulator. + (operator<<): New overloaded function. + * testsuite/27_io/manipulators/extended/get_time/char/1.cc: New. + * testsuite/27_io/manipulators/extended/get_time/char/2.cc: New. + * testsuite/27_io/manipulators/extended/get_time/wchar_t/1.cc: New. + * testsuite/27_io/manipulators/extended/get_time/wchar_t/2.cc: New. + 2014-12-22 Rüdiger Sonderfeld Jonathan Wakely diff --git a/libstdc++-v3/include/std/iomanip b/libstdc++-v3/include/std/iomanip index fce74c95f01..080dae34777 100644 --- a/libstdc++-v3/include/std/iomanip +++ b/libstdc++-v3/include/std/iomanip @@ -392,6 +392,60 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __os; } + template + struct _Get_time + { + std::tm* _M_tmb; + const _CharT* _M_fmt; + }; + + /** + * @brief Extended manipulator for extracting time. + * + * This manipulator uses time_get::get to extract time. + * [ext.manip] + * + * @param __tmb struct to extract the time data to. + * @param __fmt format string. + */ + template + inline _Get_time<_CharT> + get_time(std::tm* __tmb, const _CharT* __fmt) + { return { __tmb, __fmt }; } + + template + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, _Get_time<_CharT> __f) + { + typename basic_istream<_CharT, _Traits>::sentry __cerb(__is, false); + if (__cerb) + { + ios_base::iostate __err = ios_base::goodbit; + __try + { + typedef istreambuf_iterator<_CharT, _Traits> _Iter; + typedef time_get<_CharT, _Iter> _TimeGet; + + const _CharT* const __fmt_end = __f._M_fmt + + _Traits::length(__f._M_fmt); + + const _TimeGet& __mg = use_facet<_TimeGet>(__is.getloc()); + __mg.get(_Iter(__is.rdbuf()), _Iter(), __is, + __err, __f._M_tmb, __f._M_fmt, __fmt_end); + } + __catch(__cxxabiv1::__forced_unwind&) + { + __is._M_setstate(ios_base::badbit); + __throw_exception_again; + } + __catch(...) + { __is._M_setstate(ios_base::badbit); } + if (__err) + __is.setstate(__err); + } + return __is; + } + #if __cplusplus > 201103L #define __cpp_lib_quoted_string_io 201304 diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/1.cc new file mode 100644 index 00000000000..07f0111d75c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/1.cc @@ -0,0 +1,49 @@ +// { dg-options " -std=gnu++11 " } + +// 2014-04-14 Rüdiger Sonderfeld + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// 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 +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.7.5. (C++11) Extended manipulators [ext.manip]: put_time + +#include +#include +#include +#include + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + locale loc_c = locale::classic(); + istringstream iss; + iss.imbue(loc_c); + iss.str("12:01:30 1971"); + tm time1; + iss >> get_time(&time1, "%H:%M:%S %Y"); + VERIFY( static_cast(iss) ); + VERIFY(time1.tm_hour == 12); + VERIFY(time1.tm_min == 1); + VERIFY(time1.tm_sec == 30); + VERIFY(time1.tm_year == 71); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc new file mode 100644 index 00000000000..fcba0c753e3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc @@ -0,0 +1,49 @@ +// { dg-require-namedlocale "de_DE.utf8" } +// { dg-options " -std=gnu++11 " } + +// 2014-04-14 Rüdiger Sonderfeld + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// 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 +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.7.5. (C++11) Extended manipulators [ext.manip]: put_time + +#include +#include +#include +#include + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE.utf8"); + VERIFY( loc_de != loc_c ); + istringstream iss; + iss.imbue(loc_de); + iss.str("Di 1971"); + tm time1; + iss >> get_time(&time1, "%a %Y"); + VERIFY(time1.tm_wday == 2); + VERIFY(time1.tm_year == 71); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/wchar_t/1.cc new file mode 100644 index 00000000000..ed0325add6e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/wchar_t/1.cc @@ -0,0 +1,49 @@ +// { dg-options " -std=gnu++11 " } + +// 2014-04-14 Rüdiger Sonderfeld + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// 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 +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.7.5. (C++11) Extended manipulators [ext.manip]: put_time + +#include +#include +#include +#include + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + locale loc_c = locale::classic(); + wistringstream iss; + iss.imbue(loc_c); + iss.str(L"12:01:30 1971"); + tm time1; + iss >> get_time(&time1, L"%H:%M:%S %Y"); + VERIFY( static_cast(iss) ); + VERIFY(time1.tm_hour = 12); + VERIFY(time1.tm_min = 1); + VERIFY(time1.tm_sec == 30); + VERIFY(time1.tm_year == 71); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/wchar_t/2.cc new file mode 100644 index 00000000000..4d28498c30f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/wchar_t/2.cc @@ -0,0 +1,50 @@ +// { dg-require-namedlocale "de_DE.utf8" } +// { dg-options " -std=gnu++11 " } + +// 2014-04-14 Rüdiger Sonderfeld + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// 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 +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.7.5. (C++11) Extended manipulators [ext.manip]: put_time + +#include +#include +#include +#include +#include + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE.utf8"); + VERIFY( loc_de != loc_c ); + wistringstream iss; + iss.imbue(loc_de); + iss.str(L"Montag 1971"); + tm time1; + iss >> get_time(&time1, L"%A %Y"); + VERIFY(time1.tm_wday == 1); + VERIFY(time1.tm_year == 71); +} + +int main() +{ + test01(); +} -- 2.30.2