1 // Copyright (C) 2006 Free Software Foundation
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
21 #include <cwchar> // for mbstate_t
24 #include <testsuite_hooks.h>
26 #if _GLIBCXX_USE___ENC_TRAITS
27 typedef std::codecvt<char, char, std::mbstate_t> c_codecvt;
29 #ifdef _GLIBCXX_USE_WCHAR_T
30 typedef std::codecvt<wchar_t, char, std::mbstate_t> w_codecvt;
33 class gnu_facet: public std::locale::facet
36 static std::locale::id id;
39 std::locale::id gnu_facet::id;
41 // Need some char_traits specializations for this to work.
42 typedef unsigned short unicode_t;
47 struct char_traits<unicode_t>
49 typedef unicode_t char_type;
50 // Unsigned as wint_t is unsigned.
51 typedef unsigned long int_type;
52 typedef streampos pos_type;
53 typedef streamoff off_type;
54 typedef mbstate_t state_type;
57 assign(char_type& __c1, const char_type& __c2);
60 eq(const char_type& __c1, const char_type& __c2);
63 lt(const char_type& __c1, const char_type& __c2);
66 compare(const char_type* __s1, const char_type* __s2, size_t __n)
67 { return memcmp(__s1, __s2, __n); }
70 length(const char_type* __s);
72 static const char_type*
73 find(const char_type* __s, size_t __n, const char_type& __a);
76 move(char_type* __s1, const char_type* __s2, size_t __n);
79 copy(char_type* __s1, const char_type* __s2, size_t __n)
80 { return static_cast<char_type*>(memcpy(__s1, __s2, __n)); }
83 assign(char_type* __s, size_t __n, char_type __a);
86 to_char_type(const int_type& __c);
89 to_int_type(const char_type& __c);
92 eq_int_type(const int_type& __c1, const int_type& __c2);
98 not_eof(const int_type& __c);
105 typedef unicode_t int_type;
106 typedef char ext_type;
107 typedef __enc_traits enc_type;
108 typedef codecvt<int_type, ext_type, enc_type> unicode_codecvt;
110 bool test __attribute__((unused)) = true;
113 locale loc13(locale::classic(), new unicode_codecvt);
114 VERIFY( loc01 != loc13 );
115 VERIFY( loc13.name() == "*" );
118 VERIFY( has_facet<c_codecvt>(loc13) );
119 #ifdef _GLIBCXX_USE_WCHAR_T
120 VERIFY( has_facet<w_codecvt>(loc13) );
122 VERIFY( has_facet<unicode_codecvt>(loc13) );
128 { use_facet<gnu_facet>(loc13); }
134 #endif // _GLIBCXX_USE___ENC_TRAITS
138 #if _GLIBCXX_USE___ENC_TRAITS