Commit 96d8c147 by Jonathan Wakely Committed by Jonathan Wakely

locale_conv.h (wstring_convert, [...]): New.

	* include/bits/locale_conv.h (wstring_convert, wbuffer_convert): New.
	* include/std/locale: Include new header.
	* include/Makefile.am: Add it.
	* include/Makefile.in: Regenerate.
	* testsuite/22_locale/conversions/buffer/requirements/typedefs.cc: New.
	* testsuite/22_locale/conversions/string/1.cc: New.
	* testsuite/22_locale/conversions/string/2.cc: New.
	* testsuite/22_locale/conversions/string/requirements/typedefs.cc: New.
	* testsuite/22_locale/conversions/string/requirements/typedefs-2.cc:
	New.

From-SVN: r219780
parent 28af1fb3
2015-01-16 Jonathan Wakely <jwakely@redhat.com> 2015-01-16 Jonathan Wakely <jwakely@redhat.com>
* include/bits/locale_conv.h (wstring_convert, wbuffer_convert): New.
* include/std/locale: Include new header.
* include/Makefile.am: Add it.
* include/Makefile.in: Regenerate.
* testsuite/22_locale/conversions/buffer/requirements/typedefs.cc: New.
* testsuite/22_locale/conversions/string/1.cc: New.
* testsuite/22_locale/conversions/string/2.cc: New.
* testsuite/22_locale/conversions/string/requirements/typedefs.cc: New.
* testsuite/22_locale/conversions/string/requirements/typedefs-2.cc:
New.
2015-01-16 Jonathan Wakely <jwakely@redhat.com>
* config/abi/pre/gnu.ver: Export new symbols. * config/abi/pre/gnu.ver: Export new symbols.
* include/Makefile.am: Add codecvt. * include/Makefile.am: Add codecvt.
* include/Makefile.in: Regenerate. * include/Makefile.in: Regenerate.
......
...@@ -113,6 +113,7 @@ bits_headers = \ ...@@ -113,6 +113,7 @@ bits_headers = \
${bits_srcdir}/list.tcc \ ${bits_srcdir}/list.tcc \
${bits_srcdir}/locale_classes.h \ ${bits_srcdir}/locale_classes.h \
${bits_srcdir}/locale_classes.tcc \ ${bits_srcdir}/locale_classes.tcc \
${bits_srcdir}/locale_conv.h \
${bits_srcdir}/locale_facets.h \ ${bits_srcdir}/locale_facets.h \
${bits_srcdir}/locale_facets.tcc \ ${bits_srcdir}/locale_facets.tcc \
${bits_srcdir}/locale_facets_nonio.h \ ${bits_srcdir}/locale_facets_nonio.h \
......
...@@ -381,6 +381,7 @@ bits_headers = \ ...@@ -381,6 +381,7 @@ bits_headers = \
${bits_srcdir}/list.tcc \ ${bits_srcdir}/list.tcc \
${bits_srcdir}/locale_classes.h \ ${bits_srcdir}/locale_classes.h \
${bits_srcdir}/locale_classes.tcc \ ${bits_srcdir}/locale_classes.tcc \
${bits_srcdir}/locale_conv.h \
${bits_srcdir}/locale_facets.h \ ${bits_srcdir}/locale_facets.h \
${bits_srcdir}/locale_facets.tcc \ ${bits_srcdir}/locale_facets.tcc \
${bits_srcdir}/locale_facets_nonio.h \ ${bits_srcdir}/locale_facets_nonio.h \
......
...@@ -39,5 +39,8 @@ ...@@ -39,5 +39,8 @@
#include <bits/locale_classes.h> #include <bits/locale_classes.h>
#include <bits/locale_facets.h> #include <bits/locale_facets.h>
#include <bits/locale_facets_nonio.h> #include <bits/locale_facets_nonio.h>
#if __cplusplus >= 201103L
# include <bits/locale_conv.h>
#endif
#endif /* _GLIBCXX_LOCALE */ #endif /* _GLIBCXX_LOCALE */
// { dg-do compile }
// { dg-options "-std=gnu++11" }
// Copyright (C) 2012 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
// 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/>.
// 22.3.3.2.3 Buffer conversions
#include <locale>
#include <type_traits>
void test01()
{
// Check for required typedefs
struct cvt_type : std::codecvt<wchar_t, char, mbstate_t> { };
typedef std::char_traits<wchar_t> traits_type;
typedef std::wbuffer_convert<cvt_type, wchar_t, traits_type> test_type;
typedef test_type::state_type state_type;
static_assert( std::is_same<cvt_type::state_type, state_type>::value,
"state type" );
}
// { dg-do compile }
// { dg-options "-std=gnu++11" }
// Copyright (C) 2012 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
// 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/>.
// 22.3.3.2.2 String conversions
#include <locale>
#include <string>
#include <testsuite_hooks.h>
template<typename Elem>
struct cvt : std::codecvt<Elem, char, std::mbstate_t> { };
template<typename Elem>
using str_conv = std::wstring_convert<cvt<Elem>, Elem>;
using std::string;
using std::wstring;
void test01()
{
typedef str_conv<char> sc; // noconv
sc c;
string input = "King for a day...";
string output = c.from_bytes(input);
VERIFY( input == output );
VERIFY( c.converted() == output.length() );
string roundtrip = c.to_bytes(output);
VERIFY( input == roundtrip );
VERIFY( c.converted() == roundtrip.length() );
}
void test02()
{
typedef str_conv<wchar_t> wsc;
wsc c;
string input = "Fool for a lifetime";
wstring output = c.from_bytes(input);
VERIFY( c.converted() == output.length() );
VERIFY( L"Fool for a lifetime" == output );
string roundtrip = c.to_bytes(output);
VERIFY( input == roundtrip );
VERIFY( c.converted() == roundtrip.length() );
VERIFY( c.from_bytes(input[0]) == output.substr(0, 1) );
VERIFY( c.from_bytes(input.c_str()) == output );
VERIFY( c.from_bytes(input.data(), input.data()+input.size()) == output );
VERIFY( c.to_bytes(output[0]) == input.substr(0, 1) );
VERIFY( c.to_bytes(output.c_str()) == input );
VERIFY( c.to_bytes(output.data(), output.data()+output.size()) == input );
}
int main()
{
test01();
test02();
}
// { dg-options "-std=gnu++11" }
// Copyright (C) 2012 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
// 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/>.
// 22.3.3.2.2 String conversions
#include <locale>
#include <string>
#include <testsuite_hooks.h>
template<typename Elem>
struct cvt : std::codecvt<Elem, char, std::mbstate_t> { };
template<typename Elem>
using str_conv = std::wstring_convert<cvt<Elem>, Elem>;
using std::string;
using std::wstring;
// test conversion errors, with and without error strings
void test01()
{
typedef str_conv<wchar_t> sc;
const sc::byte_string berr = "invalid wide string";
const sc::wide_string werr = L"invalid byte string";
sc c(berr, werr);
string input = "Stop";
input += char(0xff);
input += char(0xff);
wstring woutput = c.from_bytes(input);
VERIFY( werr == woutput );
wstring winput = L"Stop";
winput += wchar_t(0xff);
winput += wchar_t(0xff);
string output = c.to_bytes(winput);
VERIFY( berr == output );
}
int main()
{
test01();
}
// { dg-do compile }
// { dg-options "-std=gnu++11" }
// Copyright (C) 2012 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
// 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/>.
// 22.3.3.2.2 String conversions
#include <locale>
#include <string>
#include <type_traits>
#include <testsuite_allocator.h>
template<typename T>
using alloc = __gnu_test::uneq_allocator<T>;
template<typename C>
using Str = std::basic_string<C, std::char_traits<C>, alloc<C>>;
struct cvt : std::codecvt<wchar_t, char, std::mbstate_t> { };
using wconv = std::wstring_convert<cvt, wchar_t, alloc<wchar_t>, alloc<char>>;
static_assert( std::is_same<wconv::byte_string, Str<char>>::value,
"byte string is std::string" );
static_assert( std::is_same<wconv::wide_string, Str<wchar_t>>::value,
"wide string is std::wstring" );
// { dg-do compile }
// { dg-options "-std=gnu++11" }
// Copyright (C) 2012 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
// 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/>.
// 22.3.3.2.2 String conversions
#include <locale>
void test01()
{
// Check for required typedefs
typedef std::codecvt<wchar_t, char, mbstate_t> codecvt_type;
typedef std::wstring_convert<codecvt_type> test_type;
typedef test_type::byte_string byte_string;
typedef test_type::wide_string wide_string;
typedef test_type::state_type state_type;
typedef test_type::int_type int_type;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment