mirror of git://gcc.gnu.org/git/gcc.git
re PR libstdc++/54354 (TODO extended iomanip manipulators std::get_time and std::put_time (C++11, section 27.7.5))
2014-10-14 Rüdiger Sonderfeld <ruediger@c-plusplus.de> PR libstdc++/54354 * include/std/iomanip (_Put_time): New struct. (put_time): New manipulator. (operator<<): New overloaded function. * testsuite/27_io/manipulators/extended/put_time/char/1.cc: New. * testsuite/27_io/manipulators/extended/put_time/char/2.cc: New. * testsuite/27_io/manipulators/extended/put_time/wchar_t/1.cc: New. * testsuite/27_io/manipulators/extended/put_time/wchar_t/2.cc: New. From-SVN: r216211
This commit is contained in:
parent
78bd42c423
commit
ffffc732ef
|
|
@ -1,3 +1,14 @@
|
||||||
|
2014-10-14 Rüdiger Sonderfeld <ruediger@c-plusplus.de>
|
||||||
|
|
||||||
|
PR libstdc++/54354
|
||||||
|
* include/std/iomanip (_Put_time): New struct.
|
||||||
|
(put_time): New manipulator.
|
||||||
|
(operator<<): New overloaded function.
|
||||||
|
* testsuite/27_io/manipulators/extended/put_time/char/1.cc: New.
|
||||||
|
* testsuite/27_io/manipulators/extended/put_time/char/2.cc: New.
|
||||||
|
* testsuite/27_io/manipulators/extended/put_time/wchar_t/1.cc: New.
|
||||||
|
* testsuite/27_io/manipulators/extended/put_time/wchar_t/2.cc: New.
|
||||||
|
|
||||||
2014-10-14 Kai Tietz <ktietz@redhat.com>
|
2014-10-14 Kai Tietz <ktietz@redhat.com>
|
||||||
|
|
||||||
PR libstdc++/57440
|
PR libstdc++/57440
|
||||||
|
|
|
||||||
|
|
@ -337,6 +337,61 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
return __os;
|
return __os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename _CharT>
|
||||||
|
struct _Put_time
|
||||||
|
{
|
||||||
|
const std::tm* _M_tmb;
|
||||||
|
const _CharT* _M_fmt;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Extended manipulator for formatting time.
|
||||||
|
*
|
||||||
|
* This manipulator uses time_put::put to format time.
|
||||||
|
* [ext.manip]
|
||||||
|
*
|
||||||
|
* @param __tmb struct tm time data to format.
|
||||||
|
* @param __fmt format string.
|
||||||
|
*/
|
||||||
|
template<typename _CharT>
|
||||||
|
inline _Put_time<_CharT>
|
||||||
|
put_time(const std::tm* __tmb, const _CharT* __fmt)
|
||||||
|
{ return { __tmb, __fmt }; }
|
||||||
|
|
||||||
|
template<typename _CharT, typename _Traits>
|
||||||
|
basic_ostream<_CharT, _Traits>&
|
||||||
|
operator<<(basic_ostream<_CharT, _Traits>& __os, _Put_time<_CharT> __f)
|
||||||
|
{
|
||||||
|
typename basic_ostream<_CharT, _Traits>::sentry __cerb(__os);
|
||||||
|
if (__cerb)
|
||||||
|
{
|
||||||
|
ios_base::iostate __err = ios_base::goodbit;
|
||||||
|
__try
|
||||||
|
{
|
||||||
|
typedef ostreambuf_iterator<_CharT, _Traits> _Iter;
|
||||||
|
typedef time_put<_CharT, _Iter> _TimePut;
|
||||||
|
|
||||||
|
const _CharT* const __fmt_end = __f._M_fmt +
|
||||||
|
_Traits::length(__f._M_fmt);
|
||||||
|
|
||||||
|
const _TimePut& __mp = use_facet<_TimePut>(__os.getloc());
|
||||||
|
if (__mp.put(_Iter(__os.rdbuf()), __os, __os.fill(),
|
||||||
|
__f._M_tmb, __f._M_fmt, __fmt_end).failed())
|
||||||
|
__err |= ios_base::badbit;
|
||||||
|
}
|
||||||
|
__catch(__cxxabiv1::__forced_unwind&)
|
||||||
|
{
|
||||||
|
__os._M_setstate(ios_base::badbit);
|
||||||
|
__throw_exception_again;
|
||||||
|
}
|
||||||
|
__catch(...)
|
||||||
|
{ __os._M_setstate(ios_base::badbit); }
|
||||||
|
if (__err)
|
||||||
|
__os.setstate(__err);
|
||||||
|
}
|
||||||
|
return __os;
|
||||||
|
}
|
||||||
|
|
||||||
#if __cplusplus > 201103L
|
#if __cplusplus > 201103L
|
||||||
|
|
||||||
#define __cpp_lib_quoted_string_io 201304
|
#define __cpp_lib_quoted_string_io 201304
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
// { dg-options " -std=gnu++11 " }
|
||||||
|
|
||||||
|
// 2014-04-14 Rüdiger Sonderfeld <ruediger@c-plusplus.de>
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// 27.7.5. (C++11) Extended manipulators [ext.manip]: put_time
|
||||||
|
|
||||||
|
#include <locale>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
bool test __attribute__((unused)) = true;
|
||||||
|
locale loc_c = locale::classic();
|
||||||
|
ostringstream oss;
|
||||||
|
oss.imbue(loc_c);
|
||||||
|
const tm time1 = __gnu_test::test_tm(0, 0, 12, 4, 3, 71, 0, 93, 0);
|
||||||
|
oss << put_time(&time1, "%a %Y");
|
||||||
|
VERIFY(oss.str() == "Sun 1971");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
// { dg-require-namedlocale "de_DE.utf8" }
|
||||||
|
// { dg-options " -std=gnu++11 " }
|
||||||
|
|
||||||
|
// 2014-04-14 Rüdiger Sonderfeld <ruediger@c-plusplus.de>
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// 27.7.5. (C++11) Extended manipulators [ext.manip]: put_time
|
||||||
|
|
||||||
|
#include <locale>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
|
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 );
|
||||||
|
ostringstream oss;
|
||||||
|
oss.imbue(loc_de);
|
||||||
|
const tm time1 = __gnu_test::test_tm(0, 0, 12, 4, 3, 71, 0, 93, 0);
|
||||||
|
oss << put_time(&time1, "%A %Y");
|
||||||
|
VERIFY(oss.str() == "Sonntag 1971");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
// { dg-options " -std=gnu++11 " }
|
||||||
|
|
||||||
|
// 2014-04-14 Rüdiger Sonderfeld <ruediger@c-plusplus.de>
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// 27.7.5. (C++11) Extended manipulators [ext.manip]: put_time
|
||||||
|
|
||||||
|
#include <locale>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
bool test __attribute__((unused)) = true;
|
||||||
|
locale loc_c = locale::classic();
|
||||||
|
wostringstream oss;
|
||||||
|
oss.imbue(loc_c);
|
||||||
|
const tm time1 = __gnu_test::test_tm(0, 0, 12, 4, 3, 71, 0, 93, 0);
|
||||||
|
oss << put_time(&time1, L"%a %Y");
|
||||||
|
VERIFY(oss.str() == L"Sun 1971");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
// { dg-require-namedlocale "de_DE.utf8" }
|
||||||
|
// { dg-options " -std=gnu++11 " }
|
||||||
|
|
||||||
|
// 2014-04-14 Rüdiger Sonderfeld <ruediger@c-plusplus.de>
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// 27.7.5. (C++11) Extended manipulators [ext.manip]: put_time
|
||||||
|
|
||||||
|
#include <locale>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
|
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 );
|
||||||
|
wostringstream oss;
|
||||||
|
oss.imbue(loc_de);
|
||||||
|
const tm time1 = __gnu_test::test_tm(0, 0, 12, 4, 3, 71, 0, 93, 0);
|
||||||
|
oss << put_time(&time1, L"%A %Y");
|
||||||
|
VERIFY(oss.str() == L"Sonntag 1971");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue