pod_char_traits.h (__gnu_cxx::character): Add char_type.

2005-04-14  Benjamin Kosnik  <bkoz@redhat.com>

	*  include/ext/pod_char_traits.h (__gnu_cxx::character): Add char_type.
	(character::to): New.
	(character::from): New.
	(operator==): Add state parameter.
	(operator<): Same.
	(char_traits::copy): Use std::copy.
	(char_traits::assign): Use std::fill_n.
	(char_traits::to_char_type): Use character::from.
	(char_traits::to_int_type): Use character::to.
	*  testsuite/testsuite_character.h (__gnu_test::character): Remove.
	(__gnu_test::conversion_state): Remove.
	(__gnu_test::pod_char): Remove.
	(pod_char): New typedef.
	(pod_uchar): New typedef.
	(pod_ushort): New typedef.
	*  testsuite/testsuite_character.cc: Fixups.
	*  testsuite/21_strings/basic_string/inserters_extractors/pod/
	10081-in.cc: Same.
	*  testsuite/21_strings/basic_string/inserters_extractors/pod/
	10081-out.cc: Same.
	*  testsuite/22_locale/numpunct/members/pod/1.cc: Same.
	*  testsuite/22_locale/numpunct/members/pod/2.cc: Same.
	*  testsuite/27_io/basic_filebuf/close/12790-1.cc: Same.
	*  testsuite/27_io/basic_filebuf/open/12790-1.cc: Same.
	*  testsuite/27_io/basic_filebuf/seekoff/12790-1.cc: Same.
	*  testsuite/27_io/basic_filebuf/seekoff/12790-2.cc: Same.
	*  testsuite/27_io/basic_filebuf/seekoff/12790-3.cc: Same.
	*  testsuite/27_io/basic_filebuf/seekoff/12790-4.cc: Same.
	*  testsuite/27_io/basic_filebuf/seekpos/12790-1.cc: Same.
	*  testsuite/27_io/basic_filebuf/seekpos/12790-2.cc: Same.
	*  testsuite/27_io/basic_filebuf/seekpos/12790-3.cc: Same.
	*  testsuite/27_io/basic_ios/imbue/14072.cc: Same.
	*  testsuite/27_io/basic_istream/extractors_arithmetic/pod/
	3983-1.cc: Same.
	*  testsuite/27_io/basic_istream/extractors_character/pod/
	3983-2.cc: Same.
	*  testsuite/27_io/basic_istream/extractors_other/pod/3983-3.cc: Same.
	*  testsuite/27_io/basic_istream/sentry/pod/1.cc: Same.
	*  testsuite/27_io/basic_ostream/sentry/pod/1.cc: Same.

From-SVN: r98165
This commit is contained in:
Benjamin Kosnik 2005-04-15 02:06:26 +00:00 committed by Benjamin Kosnik
parent a68bdb0b8d
commit 821503dbd6
23 changed files with 454 additions and 672 deletions

View File

@ -1,3 +1,45 @@
2005-04-14 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/pod_char_traits.h (__gnu_cxx::character): Add char_type.
(character::to): New.
(character::from): New.
(operator==): Add state parameter.
(operator<): Same.
(char_traits::copy): Use std::copy.
(char_traits::assign): Use std::fill_n.
(char_traits::to_char_type): Use character::from.
(char_traits::to_int_type): Use character::to.
* testsuite/testsuite_character.h (__gnu_test::character): Remove.
(__gnu_test::conversion_state): Remove.
(__gnu_test::pod_char): Remove.
(pod_char): New typedef.
(pod_uchar): New typedef.
(pod_ushort): New typedef.
* testsuite/testsuite_character.cc: Fixups.
* testsuite/21_strings/basic_string/inserters_extractors/pod/
10081-in.cc: Same.
* testsuite/21_strings/basic_string/inserters_extractors/pod/
10081-out.cc: Same.
* testsuite/22_locale/numpunct/members/pod/1.cc: Same.
* testsuite/22_locale/numpunct/members/pod/2.cc: Same.
* testsuite/27_io/basic_filebuf/close/12790-1.cc: Same.
* testsuite/27_io/basic_filebuf/open/12790-1.cc: Same.
* testsuite/27_io/basic_filebuf/seekoff/12790-1.cc: Same.
* testsuite/27_io/basic_filebuf/seekoff/12790-2.cc: Same.
* testsuite/27_io/basic_filebuf/seekoff/12790-3.cc: Same.
* testsuite/27_io/basic_filebuf/seekoff/12790-4.cc: Same.
* testsuite/27_io/basic_filebuf/seekpos/12790-1.cc: Same.
* testsuite/27_io/basic_filebuf/seekpos/12790-2.cc: Same.
* testsuite/27_io/basic_filebuf/seekpos/12790-3.cc: Same.
* testsuite/27_io/basic_ios/imbue/14072.cc: Same.
* testsuite/27_io/basic_istream/extractors_arithmetic/pod/
3983-1.cc: Same.
* testsuite/27_io/basic_istream/extractors_character/pod/
3983-2.cc: Same.
* testsuite/27_io/basic_istream/extractors_other/pod/3983-3.cc: Same.
* testsuite/27_io/basic_istream/sentry/pod/1.cc: Same.
* testsuite/27_io/basic_ostream/sentry/pod/1.cc: Same.
2005-04-12 Mike Stump <mrs@apple.com>
* configure: Regenerate.

View File

@ -1,6 +1,6 @@
// POD character, std::char_traits specialization -*- C++ -*-
// Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
// Copyright (C) 2002, 2003, 2004, 2005 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
@ -41,24 +41,47 @@
namespace __gnu_cxx
{
// POD character abstraction.
// NB: The char_type parameter is a subset of int_type, as to allow
// int_type to properly hold the full range of char_type values as
// well as EOF.
/// @brief A POD class that serves as a character abstraction class.
template<typename V, typename I, typename S = mbstate_t>
struct character
{
typedef V value_type;
typedef I int_type;
typedef S state_type;
typedef V value_type;
typedef I int_type;
typedef S state_type;
typedef character<V, I, S> char_type;
value_type value;
template<typename V2>
static char_type
from(const V2& v)
{
char_type ret = { static_cast<value_type>(v) };
return ret;
}
template<typename V2>
static V2
to(const char_type& c)
{
V2 ret = { static_cast<V2>(c.value) };
return ret;
}
};
template<typename V, typename I>
template<typename V, typename I, typename S>
inline bool
operator==(const character<V, I>& lhs, const character<V, I>& rhs)
operator==(const character<V, I, S>& lhs, const character<V, I, S>& rhs)
{ return lhs.value == rhs.value; }
template<typename V, typename I>
template<typename V, typename I, typename S>
inline bool
operator<(const character<V, I>& lhs, const character<V, I>& rhs)
operator<(const character<V, I, S>& lhs, const character<V, I, S>& rhs)
{ return lhs.value < rhs.value; }
} // namespace __gnu_cxx
@ -69,13 +92,6 @@ namespace std
struct char_traits<__gnu_cxx::character<V, I, S> >
{
typedef __gnu_cxx::character<V, I, S> char_type;
// NB: This type should be bigger than char_type, so as to
// properly hold EOF values in addition to the full range of
// char_type values.
// Also, assumes
// int_type(value_type) is valid.
// int_type(-1) is possible.
typedef typename char_type::int_type int_type;
typedef typename char_type::state_type state_type;
typedef fpos<state_type> pos_type;
@ -122,41 +138,47 @@ namespace std
static char_type*
move(char_type* __s1, const char_type* __s2, size_t __n)
{ return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }
{
return static_cast<char_type*>(std::memmove(__s1, __s2,
__n * sizeof(char_type)));
}
static char_type*
copy(char_type* __s1, const char_type* __s2, size_t __n)
{ return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }
{
std::copy(__s2, __s2 + __n, __s1);
return __s1;
}
static char_type*
assign(char_type* __s, size_t __n, char_type __a)
{
for (char_type* __p = __s; __p < __s + __n; ++__p)
assign(*__p, __a);
std::fill_n(__s, __n, __a);
return __s;
}
static char_type
to_char_type(const int_type& __c)
{
char_type __r = { __c };
return __r;
}
to_char_type(const int_type& __i)
{ return char_type::template from(__i); }
static int_type
to_int_type(const char_type& __c)
{ return int_type(__c.value); }
{ return char_type::template to<int_type>(__c); }
static bool
eq_int_type(const int_type& __c1, const int_type& __c2)
{ return __c1 == __c2; }
static int_type
eof() { return static_cast<int_type>(-1); }
eof()
{
int_type __r = { -1 };
return __r;
}
static int_type
not_eof(const int_type& __c)
{ return eq_int_type(__c, eof()) ? int_type(0) : __c; }
{ return eq_int_type(__c, eof()) ? int_type() : __c; }
};
}

View File

@ -37,10 +37,10 @@
void test01()
{
using namespace std;
using __gnu_test::pod_type;
typedef basic_string<pod_type> string_type;
typedef basic_stringbuf<pod_type> stringbuf_type;
typedef basic_istream<pod_type> istream_type;
using __gnu_test::pod_ushort;
typedef basic_string<pod_ushort> string_type;
typedef basic_stringbuf<pod_ushort> stringbuf_type;
typedef basic_istream<pod_ushort> istream_type;
bool test __attribute__((unused)) = true;
@ -61,7 +61,7 @@ void test01()
VERIFY( false );
}
const std::locale loc(std::locale::classic(), new std::ctype<pod_type>);
const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>);
stream.imbue(loc);
try
{
@ -76,12 +76,12 @@ void test01()
#if !__GXX_WEAK__
// Explicitly instantiate for systems with no COMDAT or weak support.
template
std::basic_string<__gnu_test::pod_type>::size_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_max_size;
std::basic_string<__gnu_test::pod_ushort>::size_type
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
template
__gnu_test::pod_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_terminal;
__gnu_test::pod_ushort
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
#endif
int main()

View File

@ -37,10 +37,10 @@
void test01()
{
using namespace std;
using __gnu_test::pod_type;
typedef basic_string<pod_type> string_type;
typedef basic_stringbuf<pod_type> stringbuf_type;
typedef basic_ostream<pod_type> ostream_type;
using __gnu_test::pod_ushort;
typedef basic_string<pod_ushort> string_type;
typedef basic_stringbuf<pod_ushort> stringbuf_type;
typedef basic_ostream<pod_ushort> ostream_type;
bool test __attribute__((unused)) = true;
@ -61,7 +61,7 @@ void test01()
VERIFY( false );
}
const std::locale loc(std::locale::classic(), new std::ctype<pod_type>);
const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>);
stream.imbue(loc);
try
{
@ -76,12 +76,12 @@ void test01()
#if !__GXX_WEAK__
// Explicitly instantiate for systems with no COMDAT or weak support.
template
std::basic_string<__gnu_test::pod_type>::size_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_max_size;
std::basic_string<__gnu_test::pod_ushort>::size_type
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
template
__gnu_test::pod_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_terminal;
__gnu_test::pod_ushort
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
#endif
int main()

View File

@ -30,42 +30,42 @@
void test01()
{
using namespace std;
using __gnu_test::pod_type;
using __gnu_test::value_type;
typedef numpunct<pod_type>::string_type string_type;
typedef basic_stringbuf<pod_type> stringbuf_type;
typedef basic_ostream<pod_type> ostream_type;
using __gnu_test::pod_ushort;
typedef pod_ushort::value_type value_type;
typedef numpunct<pod_ushort>::string_type string_type;
typedef basic_stringbuf<pod_ushort> stringbuf_type;
typedef basic_ostream<pod_ushort> ostream_type;
bool test __attribute__((unused)) = true;
// Pre-cache sanity check.
const locale loc(locale::classic(), new numpunct<pod_type>);
const numpunct<pod_type>& np = use_facet<numpunct<pod_type> >(loc);
const locale loc(locale::classic(), new numpunct<pod_ushort>);
const numpunct<pod_ushort>& np = use_facet<numpunct<pod_ushort> >(loc);
pod_type dp = np.decimal_point();
pod_type ts = np.thousands_sep();
pod_ushort dp = np.decimal_point();
pod_ushort ts = np.thousands_sep();
string g = np.grouping();
string_type strue = np.truename();
string_type sfalse = np.falsename();
pod_type basedp = { value_type('.') };
pod_type basets = { value_type(',') };
pod_ushort basedp = { value_type('.') };
pod_ushort basets = { value_type(',') };
string_type basetrue(4, pod_type());
string_type basetrue(4, pod_ushort());
basetrue[0].value = value_type('t');
basetrue[1].value = value_type('r');
basetrue[2].value = value_type('u');
basetrue[3].value = value_type('e');
string_type basefalse(5, pod_type());
string_type basefalse(5, pod_ushort());
basefalse[0].value = value_type('f');
basefalse[1].value = value_type('a');
basefalse[2].value = value_type('l');
basefalse[3].value = value_type('s');
basefalse[4].value = value_type('e');
VERIFY( char_traits<pod_type>::eq(dp, basedp) );
VERIFY( char_traits<pod_type>::eq(ts, basets) );
VERIFY( char_traits<pod_ushort>::eq(dp, basedp) );
VERIFY( char_traits<pod_ushort>::eq(ts, basets) );
VERIFY( g == "" );
VERIFY( strue == basetrue );
VERIFY( sfalse == basefalse );

View File

@ -30,10 +30,10 @@
void test01()
{
using namespace std;
using __gnu_test::pod_type;
using __gnu_test::pod_ushort;
typedef numpunct<pod_type>::string_type string_type;
typedef basic_ostringstream<pod_type> ostream_type;
typedef numpunct<pod_ushort>::string_type string_type;
typedef basic_ostringstream<pod_ushort> ostream_type;
bool test = true;
@ -58,7 +58,7 @@ void test01()
VERIFY( test );
// 2: fail, no ctype
const locale loc2(loc, new num_put<pod_type>);
const locale loc2(loc, new num_put<pod_ushort>);
os.clear();
os.imbue(loc2);
try
@ -74,7 +74,7 @@ void test01()
VERIFY( test );
// 3: fail, no numpunct
const locale loc3(loc2, new ctype<pod_type>);
const locale loc3(loc2, new ctype<pod_ushort>);
os.clear();
os.imbue(loc3);
try
@ -90,7 +90,7 @@ void test01()
VERIFY( test );
// 4: works.
const locale loc4(loc3, new numpunct<pod_type>);
const locale loc4(loc3, new numpunct<pod_ushort>);
os.clear();
os.imbue(loc4);
try

View File

@ -27,8 +27,8 @@
void test01()
{
using namespace std;
using __gnu_test::character;
typedef basic_filebuf<character>::traits_type traits_type;
using __gnu_test::pod_uchar;
typedef basic_filebuf<pod_uchar>::traits_type traits_type;
bool test __attribute__((unused)) = true;
const char* name = "tmp_close_12790";
@ -37,23 +37,23 @@ void test01()
new codecvt<traits_type::char_type, char,
traits_type::state_type>);
basic_filebuf<character> fb;
basic_filebuf<pod_uchar> fb;
fb.pubsetbuf(0, 0);
fb.pubimbue(loc);
fb.open(name, ios_base::out | ios_base::trunc);
fb.sputc(character::from_char('b'));
fb.sputc(character::from_char(0xff));
fb.sputc(character::from_char(0));
fb.sputc(pod_uchar::from<char>('b'));
fb.sputc(pod_uchar::from<char>(0xff));
fb.sputc(pod_uchar::from<char>(0));
// Check that close() writes unshift sequence
fb.close();
fb.open(name, ios_base::in | ios_base::out | ios_base::ate);
fb.sputc(character::from_char('a'));
fb.sputc(character::from_char(0xff));
fb.sputc(character::from_char(0));
fb.sputc(pod_uchar::from<char>('a'));
fb.sputc(pod_uchar::from<char>(0xff));
fb.sputc(pod_uchar::from<char>(0));
fb.close();
@ -66,7 +66,7 @@ void test01()
traits_type::int_type c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char('a')) );
pod_uchar::from<char>('a')) );
fb.close();
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003 Free Software Foundation, Inc.
// Copyright (C) 2003, 2005 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
@ -27,8 +27,8 @@
void test01()
{
using namespace std;
using __gnu_test::character;
typedef basic_filebuf<character>::traits_type traits_type;
using __gnu_test::pod_uchar;
typedef basic_filebuf<pod_uchar>::traits_type traits_type;
bool test __attribute__((unused)) = true;
const char* name = "tmp_open_12790";
@ -37,11 +37,11 @@ void test01()
new codecvt<traits_type::char_type, char,
traits_type::state_type>);
basic_filebuf<character> fb;
basic_filebuf<pod_uchar> fb;
fb.pubimbue(loc);
fb.open(name, ios_base::out);
fb.sputc(character::from_char('b'));
fb.sputc(pod_uchar::from<char>('b'));
fb.close();
// Check that reopened basic_filebuf begins in the initial state.
@ -49,7 +49,7 @@ void test01()
traits_type::int_type c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char('b')) );
pod_uchar::from<char>('b')) );
fb.close();
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003 Free Software Foundation, Inc.
// Copyright (C) 2003, 2005 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
@ -27,8 +27,8 @@
void test01()
{
using namespace std;
using __gnu_test::character;
typedef basic_filebuf<character>::traits_type traits_type;
using __gnu_test::pod_uchar;
typedef basic_filebuf<pod_uchar>::traits_type traits_type;
bool test __attribute__((unused)) = true;
const char* name = "tmp_seekoff_12790";
@ -37,17 +37,17 @@ void test01()
new codecvt<traits_type::char_type, char,
traits_type::state_type>);
basic_filebuf<character> fb;
basic_filebuf<pod_uchar> fb;
fb.pubimbue(loc);
fb.open(name, ios_base::out);
fb.sputc(character::from_char(0xff));
fb.sputc(character::from_char(0));
fb.sputc(character::from_char(0));
fb.sputc(character::from_char('a'));
fb.sputc(character::from_char('a'));
fb.sputc(character::from_char('a'));
fb.sputc(character::from_char('a'));
fb.sputc(pod_uchar::from<char>(0xff));
fb.sputc(pod_uchar::from<char>(0));
fb.sputc(pod_uchar::from<char>(0));
fb.sputc(pod_uchar::from<char>('a'));
fb.sputc(pod_uchar::from<char>('a'));
fb.sputc(pod_uchar::from<char>('a'));
fb.sputc(pod_uchar::from<char>('a'));
fb.close();
fb.open(name, ios_base::in);
@ -62,13 +62,13 @@ void test01()
traits_type::int_type c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char('a')) );
pod_uchar::from<char>('a')) );
fb.sbumpc();
fb.sbumpc();
c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char('a')) );
pod_uchar::from<char>('a')) );
c = fb.sbumpc();
VERIFY( c == traits_type::eof() );

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003 Free Software Foundation, Inc.
// Copyright (C) 2003, 2005 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
@ -27,8 +27,8 @@
void test01()
{
using namespace std;
using __gnu_test::character;
typedef basic_filebuf<character>::traits_type traits_type;
using __gnu_test::pod_uchar;
typedef basic_filebuf<pod_uchar>::traits_type traits_type;
bool test __attribute__((unused)) = true;
const char* name = "tmp_seekoff_12790";
@ -37,17 +37,17 @@ void test01()
new codecvt<traits_type::char_type, char,
traits_type::state_type>);
basic_filebuf<character> fb;
basic_filebuf<pod_uchar> fb;
fb.pubimbue(loc);
fb.open(name, ios_base::out);
fb.sputc(character::from_char(0xff));
fb.sputc(character::from_char(0));
fb.sputc(character::from_char(0));
fb.sputc(character::from_char('a'));
fb.sputc(character::from_char('a'));
fb.sputc(character::from_char('a'));
fb.sputc(character::from_char('a'));
fb.sputc(pod_uchar::from<char>(0xff));
fb.sputc(pod_uchar::from<char>(0));
fb.sputc(pod_uchar::from<char>(0));
fb.sputc(pod_uchar::from<char>('a'));
fb.sputc(pod_uchar::from<char>('a'));
fb.sputc(pod_uchar::from<char>('a'));
fb.sputc(pod_uchar::from<char>('a'));
fb.close();
fb.open(name, ios_base::in);
@ -62,7 +62,7 @@ void test01()
traits_type::int_type c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char(0xff)) );
pod_uchar::from<char>(0xff)) );
fb.sbumpc();
fb.sbumpc();
fb.sbumpc();
@ -71,7 +71,7 @@ void test01()
c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char('a')) );
pod_uchar::from<char>('a')) );
c = fb.sbumpc();
VERIFY( c == traits_type::eof() );

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003 Free Software Foundation, Inc.
// Copyright (C) 2003, 2005 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
@ -27,8 +27,8 @@
void test01()
{
using namespace std;
using __gnu_test::character;
typedef basic_filebuf<character>::traits_type traits_type;
using __gnu_test::pod_uchar;
typedef basic_filebuf<pod_uchar>::traits_type traits_type;
bool test __attribute__((unused)) = true;
const char* name = "tmp_seekoff_12790";
@ -37,16 +37,16 @@ void test01()
new codecvt<traits_type::char_type, char,
traits_type::state_type>);
basic_filebuf<character> fb;
basic_filebuf<pod_uchar> fb;
fb.pubimbue(loc);
fb.open(name, ios_base::out | ios_base::trunc);
fb.sputc(character::from_char('b'));
fb.sputc(character::from_char(0xff));
fb.sputc(character::from_char('a'));
fb.sputc(character::from_char(0xfc));
fb.sputc(character::from_char(0));
fb.sputc(character::from_char(0));
fb.sputc(pod_uchar::from<char>('b'));
fb.sputc(pod_uchar::from<char>(0xff));
fb.sputc(pod_uchar::from<char>('a'));
fb.sputc(pod_uchar::from<char>(0xfc));
fb.sputc(pod_uchar::from<char>(0));
fb.sputc(pod_uchar::from<char>(0));
fb.close();
fb.open(name, ios_base::in);
@ -60,7 +60,7 @@ void test01()
traits_type::int_type c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char('a')) );
pod_uchar::from<char>('a')) );
fb.sbumpc();
fb.pubseekpos(pos);
@ -68,7 +68,7 @@ void test01()
c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char('a')) );
pod_uchar::from<char>('a')) );
fb.close();
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003 Free Software Foundation, Inc.
// Copyright (C) 2003, 2005 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
@ -27,8 +27,8 @@
void test01()
{
using namespace std;
using __gnu_test::character;
typedef basic_filebuf<character>::traits_type traits_type;
using __gnu_test::pod_uchar;
typedef basic_filebuf<pod_uchar>::traits_type traits_type;
bool test __attribute__((unused)) = true;
const char* name = "tmp_seekoff_12790";
@ -37,20 +37,20 @@ void test01()
new codecvt<traits_type::char_type, char,
traits_type::state_type>);
basic_filebuf<character> fb;
basic_filebuf<pod_uchar> fb;
fb.pubsetbuf(0, 0);
fb.pubimbue(loc);
fb.open(name, ios_base::in | ios_base::out | ios_base::trunc);
fb.sputc(character::from_char('b'));
fb.sputc(character::from_char(0xff));
fb.sputc(pod_uchar::from<char>('b'));
fb.sputc(pod_uchar::from<char>(0xff));
// Check that seekoff sets the current state during output
traits_type::pos_type pos = fb.pubseekoff(0, ios_base::cur);
fb.sputc(character::from_char('a'));
fb.sputc(character::from_char(0xff));
fb.sputc(character::from_char(0));
fb.sputc(character::from_char(0));
fb.sputc(pod_uchar::from<char>('a'));
fb.sputc(pod_uchar::from<char>(0xff));
fb.sputc(pod_uchar::from<char>(0));
fb.sputc(pod_uchar::from<char>(0));
fb.pubseekoff(0, ios_base::beg);
fb.sbumpc();
@ -59,7 +59,7 @@ void test01()
traits_type::int_type c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char('a')) );
pod_uchar::from<char>('a')) );
fb.close();
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003 Free Software Foundation, Inc.
// Copyright (C) 2003, 2005 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
@ -27,8 +27,8 @@
void test01()
{
using namespace std;
using __gnu_test::character;
typedef basic_filebuf<character>::traits_type traits_type;
using __gnu_test::pod_uchar;
typedef basic_filebuf<pod_uchar>::traits_type traits_type;
bool test __attribute__((unused)) = true;
const char* name = "tmp_seekpos_12790";
@ -37,16 +37,16 @@ void test01()
new codecvt<traits_type::char_type, char,
traits_type::state_type>);
basic_filebuf<character> fb;
basic_filebuf<pod_uchar> fb;
fb.pubsetbuf(0, 0);
fb.pubimbue(loc);
fb.open(name, ios_base::in | ios_base::out | ios_base::trunc);
traits_type::pos_type pos = fb.pubseekoff(0, ios_base::cur);
fb.sputc(character::from_char('a'));
fb.sputc(character::from_char(0xff));
fb.sputc(character::from_char(0));
fb.sputc(character::from_char(0));
fb.sputc(pod_uchar::from<char>('a'));
fb.sputc(pod_uchar::from<char>(0xff));
fb.sputc(pod_uchar::from<char>(0));
fb.sputc(pod_uchar::from<char>(0));
// Check that seekpos restores the state correctly
fb.pubseekpos(pos);
@ -54,7 +54,7 @@ void test01()
traits_type::int_type c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char('a')) );
pod_uchar::from<char>('a')) );
fb.close();
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003 Free Software Foundation, Inc.
// Copyright (C) 2003, 2005 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
@ -27,8 +27,8 @@
void test01()
{
using namespace std;
using __gnu_test::character;
typedef basic_filebuf<character>::traits_type traits_type;
using __gnu_test::pod_uchar;
typedef basic_filebuf<pod_uchar>::traits_type traits_type;
bool test __attribute__((unused)) = true;
const char* name = "tmp_seekpos_12790";
@ -37,16 +37,16 @@ void test01()
new codecvt<traits_type::char_type, char,
traits_type::state_type>);
basic_filebuf<character> fb;
basic_filebuf<pod_uchar> fb;
fb.pubimbue(loc);
fb.open(name, ios_base::out | ios_base::trunc);
fb.sputc(character::from_char('b'));
fb.sputc(character::from_char(0xff));
fb.sputc(character::from_char('a'));
fb.sputc(character::from_char(0xfc));
fb.sputc(character::from_char(0));
fb.sputc(character::from_char(0));
fb.sputc(pod_uchar::from<char>('b'));
fb.sputc(pod_uchar::from<char>(0xff));
fb.sputc(pod_uchar::from<char>('a'));
fb.sputc(pod_uchar::from<char>(0xfc));
fb.sputc(pod_uchar::from<char>(0));
fb.sputc(pod_uchar::from<char>(0));
fb.close();
fb.open(name, ios_base::in);
@ -62,14 +62,14 @@ void test01()
traits_type::int_type c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char('a')) );
pod_uchar::from<char>('a')) );
fb.sbumpc();
fb.pubseekpos(pos2);
c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char('a')) );
pod_uchar::from<char>('a')) );
fb.close();
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003 Free Software Foundation, Inc.
// Copyright (C) 2003, 2005 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
@ -27,8 +27,8 @@
void test01()
{
using namespace std;
using __gnu_test::character;
typedef basic_filebuf<character>::traits_type traits_type;
using __gnu_test::pod_uchar;
typedef basic_filebuf<pod_uchar>::traits_type traits_type;
bool test __attribute__((unused)) = true;
const char* name = "tmp_seekpos_12790";
@ -37,14 +37,14 @@ void test01()
new codecvt<traits_type::char_type, char,
traits_type::state_type>);
basic_filebuf<character> fb;
basic_filebuf<pod_uchar> fb;
fb.pubimbue(loc);
fb.open(name, ios_base::in | ios_base::out | ios_base::trunc);
fb.sputc(character::from_char('b'));
fb.sputc(character::from_char(0xff));
fb.sputc(character::from_char('c'));
fb.sputc(character::from_char(0xff));
fb.sputc(pod_uchar::from<char>('b'));
fb.sputc(pod_uchar::from<char>(0xff));
fb.sputc(pod_uchar::from<char>('c'));
fb.sputc(pod_uchar::from<char>(0xff));
fb.pubseekoff(0, ios_base::beg);
fb.sbumpc();
@ -56,18 +56,18 @@ void test01()
// Check that seekoff sets the current state for output
fb.pubseekpos(pos);
fb.sputc(character::from_char('a'));
fb.sputc(character::from_char(0));
fb.sputc(character::from_char(0));
fb.sputc(character::from_char(0));
fb.sputc(character::from_char(0));
fb.sputc(pod_uchar::from<char>('a'));
fb.sputc(pod_uchar::from<char>(0));
fb.sputc(pod_uchar::from<char>(0));
fb.sputc(pod_uchar::from<char>(0));
fb.sputc(pod_uchar::from<char>(0));
fb.pubseekpos(pos);
traits_type::int_type c = fb.sbumpc();
VERIFY( c != traits_type::eof() );
VERIFY( traits_type::eq(traits_type::to_char_type(c),
character::from_char('a')) );
pod_uchar::from<char>('a')) );
fb.close();
}

View File

@ -35,134 +35,6 @@
#include <testsuite_hooks.h>
#include <testsuite_character.h>
namespace std
{
template<>
class ctype<__gnu_test::character>
: public locale::facet, public ctype_base
{
public:
typedef __gnu_test::character char_type;
explicit ctype(size_t refs = 0)
: locale::facet(refs) { }
bool
is(mask m, char_type c) const
{ return this->do_is(m, c); }
const char_type*
is(const char_type* low, const char_type* high, mask* vec) const
{ return this->do_is(low, high, vec); }
const char_type*
scan_is(mask m, const char_type* low, const char_type* high) const
{ return this->do_scan_is(m, low, high); }
const char_type*
scan_not(mask m, const char_type* low, const char_type* high) const
{ return this->do_scan_not(m, low, high); }
char_type
toupper(char_type c) const
{ return this->do_toupper(c); }
const char_type*
toupper(char_type* low, const char_type* high) const
{ return this->do_toupper(low, high); }
char_type
tolower(char_type c) const
{ return this->do_tolower(c); }
const char_type*
tolower(char_type* low, const char_type* high) const
{ return this->do_tolower(low, high); }
char_type
widen(char c) const
{ return this->do_widen(c); }
const char*
widen(const char* low, const char* high, char_type* to) const
{ return this->do_widen(low, high, to); }
char
narrow(char_type c, char dfault) const
{ return this->do_narrow(c, dfault); }
const char_type*
narrow(const char_type* low, const char_type* high,
char dfault, char* to) const
{ return this->do_narrow(low, high, dfault, to); }
static locale::id id;
protected:
~ctype()
{ }
virtual bool
do_is(mask m, char_type c) const
{ return false; }
virtual const char_type*
do_is(const char_type* low, const char_type* high, mask* vec) const
{
fill_n(vec, high - low, mask());
return high;
}
virtual const char_type*
do_scan_is(mask m, const char_type* low, const char_type* high) const
{ return high; }
virtual const char_type*
do_scan_not(mask m, const char_type* low, const char_type* high) const
{ return low; }
virtual char_type
do_toupper(char_type c) const
{ return c; }
virtual const char_type*
do_toupper(char_type* low, const char_type* high) const
{ return high; }
virtual char_type
do_tolower(char_type c) const
{ return c; }
virtual const char_type*
do_tolower(char_type* low, const char_type* high) const
{ return high; }
virtual char_type
do_widen(char c) const
{ return __gnu_test::character::from_char(c); }
virtual const char*
do_widen(const char* low, const char* high, char_type* dest) const
{
transform(low, high, dest, &__gnu_test::character::from_char);
return high;
}
virtual char
do_narrow(char_type, char dfault) const
{ return dfault; }
virtual const char_type*
do_narrow(const char_type* low, const char_type* high,
char dfault, char* dest) const
{
fill_n(dest, high - low, dfault);
return high;
}
};
locale::id ctype<__gnu_test::character>::id;
} // namespace std
// libstdc++/14072
void test01()
{
@ -170,12 +42,12 @@ void test01()
using namespace std;
locale loc;
loc = locale(loc, new ctype<__gnu_test::character>());
loc = locale(loc, new num_get<__gnu_test::character>());
loc = locale(loc, new num_put<__gnu_test::character>());
loc = locale(loc, new ctype<__gnu_test::pod_uchar>());
loc = locale(loc, new num_get<__gnu_test::pod_uchar>());
loc = locale(loc, new num_put<__gnu_test::pod_uchar>());
locale::global(loc);
basic_stringstream<__gnu_test::character> s;
basic_stringstream<__gnu_test::pod_uchar> s;
s << "10\n";
s.seekg(0, ios_base::beg);
s.imbue(locale::classic());

View File

@ -39,10 +39,9 @@
void test03()
{
using namespace std;
using __gnu_test::pod_type;
using __gnu_test::value_type;
typedef basic_stringbuf<pod_type> stringbuf_type;
typedef basic_istream<pod_type> istream_type;
using __gnu_test::pod_ushort;
typedef basic_stringbuf<pod_ushort> stringbuf_type;
typedef basic_istream<pod_ushort> istream_type;
stringbuf_type strbuf01;
istream_type iss(&strbuf01);
@ -63,12 +62,12 @@ void test03()
#if !__GXX_WEAK__
// Explicitly instantiate for systems with no COMDAT or weak support.
template
std::basic_string<__gnu_test::pod_type>::size_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_max_size;
std::basic_string<__gnu_test::pod_ushort>::size_type
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
template
__gnu_test::pod_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_terminal;
__gnu_test::pod_ushort
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
#endif
int main()

View File

@ -39,10 +39,10 @@
void test03()
{
using namespace std;
using __gnu_test::pod_type;
using __gnu_test::value_type;
typedef basic_stringbuf<pod_type> stringbuf_type;
typedef basic_istream<pod_type> istream_type;
using __gnu_test::pod_ushort;
typedef pod_ushort::value_type value_type;
typedef basic_stringbuf<pod_ushort> stringbuf_type;
typedef basic_istream<pod_ushort> istream_type;
stringbuf_type strbuf01;
istream_type iss(&strbuf01);
@ -50,7 +50,7 @@ void test03()
bool test __attribute__((unused)) = true;
// input streams
pod_type arr[6] = { value_type('a'), value_type('b'),
pod_ushort arr[6] = { value_type('a'), value_type('b'),
value_type('c'), value_type('d'), value_type('e') };
try
@ -66,12 +66,12 @@ void test03()
#if !__GXX_WEAK__
// Explicitly instantiate for systems with no COMDAT or weak support.
template
std::basic_string<__gnu_test::pod_type>::size_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_max_size;
std::basic_string<__gnu_test::pod_ushort>::size_type
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
template
__gnu_test::pod_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_terminal;
__gnu_test::pod_ushort
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
#endif
int main()

View File

@ -39,10 +39,9 @@
void test03()
{
using namespace std;
using __gnu_test::pod_type;
using __gnu_test::value_type;
typedef basic_stringbuf<pod_type> stringbuf_type;
typedef basic_istream<pod_type> istream_type;
using __gnu_test::pod_ushort;
typedef basic_stringbuf<pod_ushort> stringbuf_type;
typedef basic_istream<pod_ushort> istream_type;
stringbuf_type strbuf01;
istream_type iss(&strbuf01);
@ -62,12 +61,12 @@ void test03()
#if !__GXX_WEAK__
// Explicitly instantiate for systems with no COMDAT or weak support.
template
std::basic_string<__gnu_test::pod_type>::size_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_max_size;
std::basic_string<__gnu_test::pod_ushort>::size_type
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
template
__gnu_test::pod_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_terminal;
__gnu_test::pod_ushort
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
#endif
int main()

View File

@ -38,10 +38,10 @@
void test01()
{
using namespace std;
using __gnu_test::pod_type;
typedef basic_string<pod_type> string_type;
typedef basic_stringbuf<pod_type> stringbuf_type;
typedef basic_istream<pod_type> istream_type;
using __gnu_test::pod_ushort;
typedef basic_string<pod_ushort> string_type;
typedef basic_stringbuf<pod_ushort> stringbuf_type;
typedef basic_istream<pod_ushort> istream_type;
bool test __attribute__((unused)) = true;
@ -80,7 +80,7 @@ void test01()
}
// imbued.
const std::locale loc(std::locale::classic(), new std::ctype<pod_type>);
const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>);
istr01.imbue(loc);
try
{
@ -158,12 +158,12 @@ void test01()
#if !__GXX_WEAK__
// Explicitly instantiate for systems with no COMDAT or weak support.
template
std::basic_string<__gnu_test::pod_type>::size_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_max_size;
std::basic_string<__gnu_test::pod_ushort>::size_type
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
template
__gnu_test::pod_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_terminal;
__gnu_test::pod_ushort
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
#endif
int main()

View File

@ -38,10 +38,10 @@
void test01()
{
using namespace std;
using __gnu_test::pod_type;
typedef basic_string<pod_type> string_type;
typedef basic_stringbuf<pod_type> stringbuf_type;
typedef basic_ostream<pod_type> ostream_type;
using __gnu_test::pod_ushort;
typedef basic_string<pod_ushort> string_type;
typedef basic_stringbuf<pod_ushort> stringbuf_type;
typedef basic_ostream<pod_ushort> ostream_type;
bool test __attribute__((unused)) = true;
@ -69,7 +69,7 @@ void test01()
}
// imbued.
const std::locale loc(std::locale::classic(), new std::ctype<pod_type>);
const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>);
ostr01.imbue(loc);
try
{
@ -114,12 +114,12 @@ void test01()
#if !__GXX_WEAK__
// Explicitly instantiate for systems with no COMDAT or weak support.
template
std::basic_string<__gnu_test::pod_type>::size_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_max_size;
std::basic_string<__gnu_test::pod_ushort>::size_type
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
template
__gnu_test::pod_type
std::basic_string<__gnu_test::pod_type>::_Rep::_S_terminal;
__gnu_test::pod_ushort
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
#endif
int main()

View File

@ -34,65 +34,67 @@
namespace std
{
locale::id
codecvt<__gnu_test::character, char, __gnu_test::conversion_state>::id;
codecvt<__gnu_test::pod_uchar, char, __gnu_test::pod_state>::id;
locale::id
ctype<__gnu_test::pod_uchar>::id;
// Member specializations for the existing facet classes.
// NB: This isn't especially portable. Perhaps a better way would be
// to just specialize all of numpunct and ctype.
using __gnu_test::int_type;
using __gnu_test::value_type;
using __gnu_test::pod_type;
using __gnu_test::pod_ushort;
typedef pod_ushort::value_type value_type;
template<>
bool
ctype<pod_type>::
ctype<pod_ushort>::
do_is(mask, char_type) const { return true; }
template<>
const pod_type*
ctype<pod_type>::
const pod_ushort*
ctype<pod_ushort>::
do_is(const char_type* __lo, const char_type*, mask*) const
{ return __lo; }
template<>
const pod_type*
ctype<pod_type>::
const pod_ushort*
ctype<pod_ushort>::
do_scan_is(mask, const char_type* __lo, const char_type*) const
{ return __lo; }
template<>
const pod_type*
ctype<pod_type>::
const pod_ushort*
ctype<pod_ushort>::
do_scan_not(mask, const char_type* __lo, const char_type*) const
{ return __lo; }
template<>
pod_type
ctype<pod_type>::
pod_ushort
ctype<pod_ushort>::
do_toupper(char_type __c) const
{ return __c; }
template<>
const pod_type*
ctype<pod_type>::
const pod_ushort*
ctype<pod_ushort>::
do_toupper(char_type*, const char_type* __hi) const
{ return __hi; }
template<>
pod_type
ctype<pod_type>::
pod_ushort
ctype<pod_ushort>::
do_tolower(char_type __c) const
{ return __c; }
template<>
const pod_type*
ctype<pod_type>::
const pod_ushort*
ctype<pod_ushort>::
do_tolower(char_type*, const char_type* __hi) const
{ return __hi; }
template<>
pod_type
ctype<pod_type>::
pod_ushort
ctype<pod_ushort>::
do_widen(char __c) const
{
char_type ret = { value_type(__c) };
@ -101,7 +103,7 @@ namespace std
template<>
const char*
ctype<pod_type>::
ctype<pod_ushort>::
do_widen(const char* __lo, const char* __hi, char_type* __dest) const
{
while (__lo < __hi)
@ -115,14 +117,14 @@ namespace std
template<>
char
ctype<pod_type>::
ctype<pod_ushort>::
do_narrow(char_type __wc, char) const
{ return static_cast<char>(__wc.value); }
template<>
const pod_type*
ctype<pod_type>::
do_narrow(const pod_type* __lo, const pod_type* __hi,
const pod_ushort*
ctype<pod_ushort>::
do_narrow(const pod_ushort* __lo, const pod_ushort* __hi,
char, char* __dest) const
{
while (__lo < __hi)
@ -135,14 +137,14 @@ namespace std
}
template<>
ctype<pod_type>::~ctype() { }
ctype<pod_ushort>::~ctype() { }
template<>
void
numpunct<pod_type>::_M_initialize_numpunct(__c_locale)
numpunct<pod_ushort>::_M_initialize_numpunct(__c_locale)
{
if (!_M_data)
_M_data = new __numpunct_cache<pod_type>;
_M_data = new __numpunct_cache<pod_ushort>;
_M_data->_M_grouping = "";
_M_data->_M_use_grouping = false;
@ -155,33 +157,33 @@ namespace std
value_type v = __num_base::_S_atoms_out[i];
_M_data->_M_atoms_out[i].value = v;
}
_M_data->_M_atoms_out[__num_base::_S_oend] = pod_type();
_M_data->_M_atoms_out[__num_base::_S_oend] = pod_ushort();
for (size_t j = 0; j < __num_base::_S_iend; ++j)
_M_data->_M_atoms_in[j].value = value_type(__num_base::_S_atoms_in[j]);
_M_data->_M_atoms_in[__num_base::_S_iend] = pod_type();
_M_data->_M_atoms_in[__num_base::_S_iend] = pod_ushort();
// "true"
pod_type* __truename = new pod_type[4 + 1];
pod_ushort* __truename = new pod_ushort[4 + 1];
__truename[0].value = value_type('t');
__truename[1].value = value_type('r');
__truename[2].value = value_type('u');
__truename[3].value = value_type('e');
__truename[4] = pod_type();
__truename[4] = pod_ushort();
_M_data->_M_truename = __truename;
// "false"
pod_type* __falsename = new pod_type[5 + 1];
pod_ushort* __falsename = new pod_ushort[5 + 1];
__falsename[0].value = value_type('f');
__falsename[1].value = value_type('a');
__falsename[2].value = value_type('l');
__falsename[3].value = value_type('s');
__falsename[4].value = value_type('e');
__falsename[5] = pod_type();
__falsename[5] = pod_ushort();
_M_data->_M_falsename = __falsename;
}
template<>
numpunct<pod_type>::~numpunct()
numpunct<pod_ushort>::~numpunct()
{ delete _M_data; }
} // namespace std

View File

@ -40,176 +40,78 @@
namespace __gnu_test
{
// Character type
struct character
{
unsigned char val;
static character from_char(char c)
{
character ret;
ret.val = c;
return ret;
}
};
inline bool
operator==(const character& lhs, const character& rhs)
{ return lhs.val == rhs.val; }
// State type.
struct conversion_state
{
unsigned int state;
};
// Test data types.
struct pod_char
{
unsigned char c;
};
inline bool
operator==(const pod_char& lhs, const pod_char& rhs)
{ return lhs.c == rhs.c; }
struct pod_int
{
int i;
int value;
};
struct state
inline bool
operator==(const pod_int& lhs, const pod_int& rhs)
{ return lhs.value == rhs.value; }
inline bool
operator<(const pod_int& lhs, const pod_int& rhs)
{ return lhs.value < rhs.value; }
struct pod_state
{
unsigned long l;
unsigned long l2;
unsigned long value;
};
typedef unsigned short value_type;
typedef unsigned int int_type;
typedef __gnu_cxx::character<value_type, int_type> pod_type;
inline bool
operator==(const pod_state& lhs, const pod_state& rhs)
{ return lhs.value == rhs.value; }
inline bool
operator<(const pod_state& lhs, const pod_state& rhs)
{ return lhs.value < rhs.value; }
// Alternate character types.
using __gnu_cxx::character;
typedef character<unsigned char, pod_int, pod_state> pod_char;
typedef character<unsigned char, unsigned int, pod_state> pod_uchar;
typedef character<unsigned short, unsigned int> pod_ushort;
// Specializations.
// pod_char
template<>
template<typename V2>
inline pod_char::char_type
pod_char::char_type::from(const V2& v)
{
char_type ret = { static_cast<value_type>(v.value) };
return ret;
}
template<>
template<typename V2>
inline V2
pod_char::char_type::to(const char_type& c)
{
V2 ret = { c.value };
return ret;
}
// pod_uchar
template<>
template<typename V2>
inline pod_uchar::char_type
pod_uchar::char_type::from(const V2& v)
{
char_type ret;
ret.value = (v >> 5);
return ret;
}
template<>
template<typename V2>
inline V2
pod_uchar::char_type::to(const char_type& c)
{ return static_cast<V2>(c.value << 5); }
}; // namespace __gnu_test
namespace std
{
// A std::char_traits specialization. Meets the additional
// requirements for basic_filebuf.
template<>
struct char_traits<__gnu_test::character>
{
typedef __gnu_test::character char_type;
typedef unsigned int int_type;
typedef __gnu_test::conversion_state state_type;
typedef streamoff off_type;
typedef fpos<state_type> pos_type;
static void
assign(char_type& c1, const char_type& c2)
{ c1 = c2; }
static bool
eq(const char_type& c1, const char_type& c2)
{ return c1.val == c2.val; }
static bool
lt(const char_type& c1, const char_type& c2)
{ return c1.val < c2.val; }
static int
compare(const char_type* s1, const char_type* s2, size_t n)
{
for (size_t i = 0; i < n; ++i)
{
if (lt(s1[i], s2[i]))
return -1;
else if (lt(s2[i], s1[i]))
return 1;
}
return 0;
}
static size_t
length(const char_type* s)
{
size_t n = 0;
while (!eq(s[n], char_type()))
++n;
return n;
}
static const char_type*
find(const char_type* s, size_t n, const char_type& a)
{
for (size_t i = 0; i < n; ++i)
{
if (eq(s[i], a))
return s + i;
}
return NULL;
}
static char_type*
move(char_type* s1, const char_type* s2, size_t n)
{
if (s1 > s2)
{
for (size_t i = 0; i < n; ++i)
assign(s1[n - i - 1], s2[n - i - 1]);
}
else
{
for (size_t i = 0; i < n; ++i)
assign(s1[i], s2[i]);
}
return s1;
}
static char_type*
copy(char_type* s1, const char_type* s2, size_t n)
{
for (size_t i = 0; i < n; ++i)
assign(s1[i], s2[i]);
return s1;
}
static char_type*
assign(char_type* s, size_t n, char_type a)
{
for (size_t i = 0; i < n; ++i)
assign(s[i], a);
return s;
}
static int_type
not_eof(const int_type& c)
{
if (eq_int_type(c, eof()))
return 0;
return c;
}
// Note non-trivial conversion to maximize chance of catching bugs
static char_type
to_char_type(const int_type& c)
{
char_type ret;
ret.val = (c >> 5);
return ret;
}
static int_type
to_int_type(const char_type& c)
{
return c.val << 5;
}
static bool
eq_int_type(const int_type& c1, const int_type& c2)
{ return c1 == c2; }
static int_type eof()
{ return 0xf; }
};
// codecvt specialization
//
// The conversion performed by the specialization is not supposed to
@ -227,58 +129,21 @@ namespace std
// state. Output those bytes.
// 3. tmp becomes the new value of state.
template<>
class codecvt<__gnu_test::character, char, __gnu_test::conversion_state>
: public locale::facet, public codecvt_base
class codecvt<__gnu_test::pod_uchar, char, __gnu_test::pod_state>
: public __codecvt_abstract_base<__gnu_test::pod_uchar, char,
__gnu_test::pod_state>
{
public:
typedef __gnu_test::character intern_type;
typedef char extern_type;
typedef __gnu_test::conversion_state state_type;
typedef codecvt_base::result result;
typedef __gnu_test::pod_uchar intern_type;
typedef char extern_type;
typedef __gnu_test::pod_state state_type;
typedef __codecvt_abstract_base<intern_type, extern_type, state_type>
base_type;
explicit codecvt(size_t refs = 0)
: locale::facet(refs)
explicit codecvt(size_t refs = 0) : base_type(refs)
{ }
result
out(state_type& state, const intern_type* from,
const intern_type* from_end, const intern_type*& from_next,
extern_type* to, extern_type* to_limit, extern_type*& to_next) const
{
return do_out(state, from, from_end, from_next,
to, to_limit, to_next);
}
result
unshift(state_type& state, extern_type* to, extern_type* to_limit,
extern_type*& to_next) const
{ return do_unshift(state, to, to_limit, to_next); }
result
in(state_type& state, const extern_type* from,
const extern_type* from_end, const extern_type*& from_next,
intern_type* to, intern_type* to_limit, intern_type*& to_next) const
{
return do_in(state, from, from_end, from_next,
to, to_limit, to_next);
}
int
encoding() const throw()
{ return do_encoding(); }
bool
always_noconv() const throw()
{ return do_always_noconv(); }
int
length(state_type& state, const extern_type* from,
const extern_type* end, size_t max) const
{ return do_length(state, from, end, max); }
int
max_length() const throw()
{ return do_max_length(); }
static locale::id id;
protected:
@ -293,8 +158,8 @@ namespace std
{
while (from < from_end && to < to_limit)
{
unsigned char tmp = (state.state ^ from->val);
if (state.state & 0x8)
unsigned char tmp = (state.value ^ from->value);
if (state.value & 0x8)
{
if (to >= to_limit - 2)
break;
@ -309,7 +174,7 @@ namespace std
*to++ = (tmp & 0xf);
*to++ = ((tmp >> 4) & 0xf);
}
state.state = tmp;
state.value = tmp;
++from;
}
@ -330,13 +195,13 @@ namespace std
if (c & 0xc0)
{
// Unshift sequence
state.state &= c;
state.value &= c;
++from;
continue;
}
unsigned char tmp;
if (state.state & 0x8)
if (state.value & 0x8)
{
if (from >= from_end - 2)
break;
@ -351,8 +216,8 @@ namespace std
tmp = (*from++ & 0xf);
tmp |= ((*from++ << 4) & 0xf0);
}
to->val = (tmp ^ state.state);
state.state = tmp;
to->value = (tmp ^ state.value);
state.value = tmp;
++to;
}
@ -368,7 +233,7 @@ namespace std
for (unsigned int i = 0; i < CHAR_BIT; ++i)
{
unsigned int mask = (1 << i);
if (state.state & mask)
if (state.value & mask)
{
if (to == to_limit)
{
@ -376,13 +241,13 @@ namespace std
return partial;
}
state.state &= ~mask;
state.value &= ~mask;
*to++ = static_cast<unsigned char>(~mask);
}
}
to_next = to;
return state.state == 0 ? ok : error;
return state.value == 0 ? ok : error;
}
virtual int
@ -404,13 +269,13 @@ namespace std
if (c & 0xc0)
{
// Unshift sequence
state.state &= c;
state.value &= c;
++from;
continue;
}
unsigned char tmp;
if (state.state & 0x8)
if (state.value & 0x8)
{
if (from >= end - 2)
break;
@ -425,7 +290,7 @@ namespace std
tmp = (*from++ & 0xf);
tmp |= ((*from++ << 4) & 0xf0);
}
state.state = tmp;
state.value = tmp;
--max;
}
return from - beg;
@ -438,97 +303,78 @@ namespace std
{ return 11; }
};
// A std::char_traits specialization with POD types for char_type,
// int_type, and state_type.
template<>
struct char_traits<__gnu_test::pod_char>
class ctype<__gnu_test::pod_uchar>
: public __ctype_abstract_base<__gnu_test::pod_uchar>
{
typedef __gnu_test::pod_char char_type;
typedef __gnu_test::pod_int int_type;
typedef __gnu_test::state state_type;
typedef fpos<state_type> pos_type;
typedef streamoff off_type;
static void
assign(char_type& c1, const char_type& c2)
{ c1.c = c2.c; }
public:
typedef __gnu_test::pod_uchar char_type;
static bool
eq(const char_type& c1, const char_type& c2)
{ return c1.c == c2.c; }
explicit ctype(size_t refs = 0)
: __ctype_abstract_base<__gnu_test::pod_uchar>(refs) { }
static bool
lt(const char_type& c1, const char_type& c2)
{ return c1.c < c2.c; }
static locale::id id;
static int
compare(const char_type* s1, const char_type* s2, size_t n)
{ return memcmp(s1, s2, n); }
protected:
~ctype()
{ }
static size_t
length(const char_type* s)
{ return strlen(reinterpret_cast<const char*>(s)); }
virtual bool
do_is(mask m, char_type c) const
{ return false; }
static const char_type*
find(const char_type* s, size_t n, const char_type& a)
{ return static_cast<const char_type*>(memchr(s, a.c, n)); }
static char_type*
move(char_type* s1, const char_type* s2, size_t n)
virtual const char_type*
do_is(const char_type* low, const char_type* high, mask* vec) const
{
memmove(s1, s2, n);
return s1;
fill_n(vec, high - low, mask());
return high;
}
static char_type*
copy(char_type* s1, const char_type* s2, size_t n)
virtual const char_type*
do_scan_is(mask m, const char_type* low, const char_type* high) const
{ return high; }
virtual const char_type*
do_scan_not(mask m, const char_type* low, const char_type* high) const
{ return low; }
virtual char_type
do_toupper(char_type c) const
{ return c; }
virtual const char_type*
do_toupper(char_type* low, const char_type* high) const
{ return high; }
virtual char_type
do_tolower(char_type c) const
{ return c; }
virtual const char_type*
do_tolower(char_type* low, const char_type* high) const
{ return high; }
virtual char_type
do_widen(char c) const
{ return __gnu_test::pod_uchar::from<char>(c); }
virtual const char*
do_widen(const char* low, const char* high, char_type* dest) const
{
memcpy(s1, s2, n);
return s1;
transform(low, high, dest, &__gnu_test::pod_uchar::from<char>);
return high;
}
static char_type*
assign(char_type* s, size_t n, char_type a)
{
memset(s, a.c, n);
return s;
}
virtual char
do_narrow(char_type, char dfault) const
{ return dfault; }
static char_type
to_char_type(const int_type& c)
virtual const char_type*
do_narrow(const char_type* low, const char_type* high,
char dfault, char* dest) const
{
char_type ret;
ret.c = static_cast<unsigned char>(c.i);
return ret;
}
static int_type
to_int_type(const char_type& c)
{
int_type ret;
ret.i = c.c;
return ret;
}
static bool
eq_int_type(const int_type& c1, const int_type& c2)
{ return c1.i == c2.i; }
static int_type
eof()
{
int_type n;
n.i = -10;
return n;
}
static int_type
not_eof(const int_type& c)
{
if (eq_int_type(c, eof()))
return int_type();
return c;
fill_n(dest, high - low, dfault);
return high;
}
};
} // namespace std