From patchwork Tue Oct 14 17:01:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 399504 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 B310914009E for ; Wed, 15 Oct 2014 04:02:17 +1100 (EST) 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=Q/u0d6ur4jUv7mEqqDQ1d20aW4i8i2I1DdgixszLLxNmd4cn8eQ75 6c2S8Ql6cVCsQrtPVj5adld8bvnMTawFYcWt4fJCA+DRm7Z4xcwPKfCGKI2SUIk9 A17xnLah57MmhZZJRQysjZgR5VaaCboCY3YwrfDD6HgT1emvZ0mrK0= 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=Z9vUkBcYyYVF2PkOKO39RxD4Viw=; b=NDrXEfPiySla+q5Zwu9PlYNpFoOj MT5RXpFljdXmQuXuCxulagAGd41/BlhW3pzNulwiEKOUbVhNGVPdUCuP2/QPxXwk H+TU5j1GSA5kpNGr2Qiy56Jp9Q+01zvppaUrsNqsVMk5C84v7HhXTJy+8u7bV1SU Frto0KQBnWkwFZM= Received: (qmail 27070 invoked by alias); 14 Oct 2014 17:02:10 -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 27002 invoked by uid 89); 14 Oct 2014 17:02:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_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; Tue, 14 Oct 2014 17:02:06 +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 s9EH21fS017533 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Oct 2014 13:02:01 -0400 Received: from localhost (ovpn-116-121.ams2.redhat.com [10.36.116.121]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s9EH203f016631; Tue, 14 Oct 2014 13:02:01 -0400 Date: Tue, 14 Oct 2014 18:01:59 +0100 From: Jonathan Wakely To: =?iso-8859-1?Q?R=FCdiger?= Sonderfeld Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH 2/3] libstdc++: Add put_time support. Message-ID: <20141014170159.GA4197@redhat.com> References: <20579426.HgWSEr9zjR@descartes> <20141013120812.GM4197@redhat.com> <20141013152819.GR4197@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20141013152819.GR4197@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) On 13/10/14 16:28 +0100, Jonathan Wakely wrote: >On 13/10/14 13:08 +0100, Jonathan Wakely wrote: >>On 15/04/14 23:20 +0200, RĂ¼diger Sonderfeld wrote: >>>Described in [ext.manip]. >>> >>>* libstdc++-v3/include/std/iomanip (_Put_time): New struct. >>>(put_time): New manipulator. >>>(operator<<): New overloaded function. >>>* libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/char/1.cc: >>>* libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/char/2.cc: >>>* libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/wchar_t/1.cc: >>>* libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/wchar_t/2.cc: >>>New file. >> >>The 27_io/manipulators/extended/put_time/char/2.cc and >>27_io/manipulators/extended/put_time/wchar_t/2.cc tests fail for me. >> >>i2.exe: /home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/char/2.cc:41: void test01(): Assertion `oss.str() == "Son 1971"' failed. >>FAIL: 27_io/manipulators/extended/put_time/char/2.cc execution test > >With my de_DE.utf8 locale the output is "So 1971" not "Son 1971". > >$ LANG=de_DE.utf8 date +%a Mo So let's just test the full name and not worry about how it's abbreviated. Tested x86_64-linux, committed to trunk. commit 4ae8f20e4924754d7fb7809730f5491dc6a74944 Author: Jonathan Wakely Date: Tue Oct 14 17:48:44 2014 +0100 2014-10-14 R??diger Sonderfeld 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. diff --git a/libstdc++-v3/include/std/iomanip b/libstdc++-v3/include/std/iomanip index 9625d43..fce74c9 100644 --- a/libstdc++-v3/include/std/iomanip +++ b/libstdc++-v3/include/std/iomanip @@ -337,6 +337,61 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __os; } + template + 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 + inline _Put_time<_CharT> + put_time(const std::tm* __tmb, const _CharT* __fmt) + { return { __tmb, __fmt }; } + + template + 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 #define __cpp_lib_quoted_string_io 201304 diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/char/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/char/1.cc new file mode 100644 index 0000000..76e64ea --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/char/1.cc @@ -0,0 +1,44 @@ +// { 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(); + 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(); +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/char/2.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/char/2.cc new file mode 100644 index 0000000..bc3a387 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/char/2.cc @@ -0,0 +1,47 @@ +// { 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 ); + 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(); +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/wchar_t/1.cc new file mode 100644 index 0000000..3b5d5fa --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/wchar_t/1.cc @@ -0,0 +1,44 @@ +// { 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(); + 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(); +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/wchar_t/2.cc new file mode 100644 index 0000000..7dc90d0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_time/wchar_t/2.cc @@ -0,0 +1,47 @@ +// { 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 ); + 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(); +}