From patchwork Mon Dec 22 13:45:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 423404 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EEE0D1400B7 for ; Tue, 23 Dec 2014 00:45:50 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:content-transfer-encoding:in-reply-to; q=dns; s= default; b=gf3S0qny7Yuss8K4BtXjQTGwq0L+awKbos/Wuhu7Mc/sDl+9wSzvp p2eUbwp5gcCIOG3HEYsMbq636MzGoQEm5RT6lzodRY6TlnJ6wtR+rSnE3DYTiizb tc3a38FKxQ3mBv6dbu5VPSsGZ0IxEJEEWxFo3gur1+Y4uOsJGG8uR4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:content-transfer-encoding:in-reply-to; s=default; bh=H4JnWy8CJQcfRPChAFnY17pCc9A=; b=JU0CgfVjFJGxKKVW2z9rpmWKv5sL wxOHqtAHIUWFe6LP2rcn9lSxrZwzQ6/UaUh6SK8xeJ4UbQv2aCSwX75A2QcFLRwk UQ+S23QfjSexvD4BDqsarF+gAqBTiIl70IbSmPRA4F2W4/s08ka/SkRI/8t1kF2t dmncw0z2zN93GZk= Received: (qmail 29282 invoked by alias); 22 Dec 2014 13:45:43 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 29264 invoked by uid 89); 22 Dec 2014 13:45:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 22 Dec 2014 13:45:40 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBMDja98013094 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 22 Dec 2014 08:45:36 -0500 Received: from localhost (ovpn-116-62.ams2.redhat.com [10.36.116.62]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBMDjZLE018497; Mon, 22 Dec 2014 08:45:35 -0500 Date: Mon, 22 Dec 2014 13:45:35 +0000 From: Jonathan Wakely To: =?iso-8859-1?Q?R=FCdiger?= Sonderfeld Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH 3/3] libstdc++: Add get_time support. Message-ID: <20141222134535.GM3134@redhat.com> References: <4101158.bo7u6shvv6@descartes> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4101158.bo7u6shvv6@descartes> User-Agent: Mutt/1.5.23 (2014-03-12) On 15/04/14 23:20 +0200, RĂ¼diger Sonderfeld wrote: >* libstdc++-v3/include/std/iomanip (_Get_time): New struct. > (get_time): New manipulator [ext.manip]. > (operator>>): New overloaded function. >* libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/1.cc: >* libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc: >* libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/wchar_t/1.cc: >* libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/wchar_t/2.cc: > New file. Committed as attached - thanks for the patches, after this there are very few C++11 features missing from libstdc++! commit bec22aeacafd666944490aebc1afa007e0043f8f Author: Jonathan Wakely Date: Tue Oct 14 13:31:28 2014 +0100 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. diff --git a/libstdc++-v3/include/std/iomanip b/libstdc++-v3/include/std/iomanip index fce74c9..080dae3 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 0000000..07f0111 --- /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 0000000..fcba0c7 --- /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 0000000..ed0325a --- /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 0000000..4d28498 --- /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(); +}