xref: /dflybsd-src/contrib/gcc-4.7/libstdc++-v3/src/c++98/codecvt.cc (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino // Copyright (C) 2000, 2002, 2004, 2005, 2009 Free Software Foundation, Inc.
2*e4b17023SJohn Marino //
3*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library.  This library is free
4*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the
5*e4b17023SJohn Marino // terms of the GNU General Public License as published by the
6*e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option)
7*e4b17023SJohn Marino // any later version.
8*e4b17023SJohn Marino 
9*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful,
10*e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of
11*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*e4b17023SJohn Marino // GNU General Public License for more details.
13*e4b17023SJohn Marino 
14*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional
15*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version
16*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation.
17*e4b17023SJohn Marino 
18*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and
19*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program;
20*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
21*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>.
22*e4b17023SJohn Marino 
23*e4b17023SJohn Marino // Written by Benjamin Kosnik <bkoz@redhat.com>
24*e4b17023SJohn Marino 
25*e4b17023SJohn Marino #include <locale>
26*e4b17023SJohn Marino 
27*e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default)
28*e4b17023SJohn Marino {
29*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION
30*e4b17023SJohn Marino 
31*e4b17023SJohn Marino   // Definitions for locale::id of standard facets that are specialized.
32*e4b17023SJohn Marino  locale::id codecvt<char, char, mbstate_t>::id;
33*e4b17023SJohn Marino 
34*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T
35*e4b17023SJohn Marino   locale::id codecvt<wchar_t, char, mbstate_t>::id;
36*e4b17023SJohn Marino #endif
37*e4b17023SJohn Marino 
38*e4b17023SJohn Marino   codecvt<char, char, mbstate_t>::
codecvt(size_t __refs)39*e4b17023SJohn Marino   codecvt(size_t __refs)
40*e4b17023SJohn Marino   : __codecvt_abstract_base<char, char, mbstate_t>(__refs),
41*e4b17023SJohn Marino   _M_c_locale_codecvt(_S_get_c_locale())
42*e4b17023SJohn Marino   { }
43*e4b17023SJohn Marino 
44*e4b17023SJohn Marino   codecvt<char, char, mbstate_t>::
codecvt(__c_locale __cloc,size_t __refs)45*e4b17023SJohn Marino   codecvt(__c_locale __cloc, size_t __refs)
46*e4b17023SJohn Marino   : __codecvt_abstract_base<char, char, mbstate_t>(__refs),
47*e4b17023SJohn Marino   _M_c_locale_codecvt(_S_clone_c_locale(__cloc))
48*e4b17023SJohn Marino   { }
49*e4b17023SJohn Marino 
50*e4b17023SJohn Marino   codecvt<char, char, mbstate_t>::
~codecvt()51*e4b17023SJohn Marino   ~codecvt()
52*e4b17023SJohn Marino   { _S_destroy_c_locale(_M_c_locale_codecvt); }
53*e4b17023SJohn Marino 
54*e4b17023SJohn Marino   codecvt_base::result
55*e4b17023SJohn Marino   codecvt<char, char, mbstate_t>::
do_out(state_type &,const intern_type * __from,const intern_type *,const intern_type * & __from_next,extern_type * __to,extern_type *,extern_type * & __to_next) const56*e4b17023SJohn Marino   do_out(state_type&, const intern_type* __from,
57*e4b17023SJohn Marino 	 const intern_type*, const intern_type*& __from_next,
58*e4b17023SJohn Marino 	 extern_type* __to, extern_type*,
59*e4b17023SJohn Marino 	 extern_type*& __to_next) const
60*e4b17023SJohn Marino   {
61*e4b17023SJohn Marino     // _GLIBCXX_RESOLVE_LIB_DEFECTS
62*e4b17023SJohn Marino     // According to the resolution of DR19, "If returns noconv [...]
63*e4b17023SJohn Marino     // there are no changes to the values in [to, to_limit)."
64*e4b17023SJohn Marino     __from_next = __from;
65*e4b17023SJohn Marino     __to_next = __to;
66*e4b17023SJohn Marino     return noconv;
67*e4b17023SJohn Marino   }
68*e4b17023SJohn Marino 
69*e4b17023SJohn Marino   codecvt_base::result
70*e4b17023SJohn Marino   codecvt<char, char, mbstate_t>::
do_unshift(state_type &,extern_type * __to,extern_type *,extern_type * & __to_next) const71*e4b17023SJohn Marino   do_unshift(state_type&, extern_type* __to,
72*e4b17023SJohn Marino              extern_type*, extern_type*& __to_next) const
73*e4b17023SJohn Marino   {
74*e4b17023SJohn Marino     __to_next = __to;
75*e4b17023SJohn Marino     return noconv;
76*e4b17023SJohn Marino   }
77*e4b17023SJohn Marino 
78*e4b17023SJohn Marino   codecvt_base::result
79*e4b17023SJohn Marino   codecvt<char, char, mbstate_t>::
do_in(state_type &,const extern_type * __from,const extern_type *,const extern_type * & __from_next,intern_type * __to,intern_type *,intern_type * & __to_next) const80*e4b17023SJohn Marino   do_in(state_type&, const extern_type* __from,
81*e4b17023SJohn Marino 	const extern_type*, const extern_type*& __from_next,
82*e4b17023SJohn Marino 	intern_type* __to, intern_type*, intern_type*& __to_next) const
83*e4b17023SJohn Marino   {
84*e4b17023SJohn Marino     // _GLIBCXX_RESOLVE_LIB_DEFECTS
85*e4b17023SJohn Marino     // According to the resolution of DR19, "If returns noconv [...]
86*e4b17023SJohn Marino     // there are no changes to the values in [to, to_limit)."
87*e4b17023SJohn Marino     __from_next = __from;
88*e4b17023SJohn Marino     __to_next = __to;
89*e4b17023SJohn Marino     return noconv;
90*e4b17023SJohn Marino   }
91*e4b17023SJohn Marino 
92*e4b17023SJohn Marino   int
93*e4b17023SJohn Marino   codecvt<char, char, mbstate_t>::
do_encoding() const94*e4b17023SJohn Marino   do_encoding() const throw()
95*e4b17023SJohn Marino   { return 1; }
96*e4b17023SJohn Marino 
97*e4b17023SJohn Marino   bool
98*e4b17023SJohn Marino   codecvt<char, char, mbstate_t>::
do_always_noconv() const99*e4b17023SJohn Marino   do_always_noconv() const throw()
100*e4b17023SJohn Marino   { return true; }
101*e4b17023SJohn Marino 
102*e4b17023SJohn Marino   int
103*e4b17023SJohn Marino   codecvt<char, char, mbstate_t>::
do_length(state_type &,const extern_type * __from,const extern_type * __end,size_t __max) const104*e4b17023SJohn Marino   do_length (state_type&, const extern_type* __from,
105*e4b17023SJohn Marino 	     const extern_type* __end, size_t __max) const
106*e4b17023SJohn Marino   {
107*e4b17023SJohn Marino     size_t __d = static_cast<size_t>(__end - __from);
108*e4b17023SJohn Marino     return std::min(__max, __d);
109*e4b17023SJohn Marino   }
110*e4b17023SJohn Marino 
111*e4b17023SJohn Marino   int
112*e4b17023SJohn Marino   codecvt<char, char, mbstate_t>::
do_max_length() const113*e4b17023SJohn Marino   do_max_length() const throw()
114*e4b17023SJohn Marino   { return 1; }
115*e4b17023SJohn Marino 
116*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T
117*e4b17023SJohn Marino   // codecvt<wchar_t, char, mbstate_t> required specialization
118*e4b17023SJohn Marino   codecvt<wchar_t, char, mbstate_t>::
codecvt(size_t __refs)119*e4b17023SJohn Marino   codecvt(size_t __refs)
120*e4b17023SJohn Marino   : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs),
121*e4b17023SJohn Marino   _M_c_locale_codecvt(_S_get_c_locale())
122*e4b17023SJohn Marino   { }
123*e4b17023SJohn Marino 
124*e4b17023SJohn Marino   codecvt<wchar_t, char, mbstate_t>::
codecvt(__c_locale __cloc,size_t __refs)125*e4b17023SJohn Marino   codecvt(__c_locale __cloc, size_t __refs)
126*e4b17023SJohn Marino   : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs),
127*e4b17023SJohn Marino   _M_c_locale_codecvt(_S_clone_c_locale(__cloc))
128*e4b17023SJohn Marino   { }
129*e4b17023SJohn Marino 
130*e4b17023SJohn Marino   codecvt<wchar_t, char, mbstate_t>::
~codecvt()131*e4b17023SJohn Marino   ~codecvt()
132*e4b17023SJohn Marino   { _S_destroy_c_locale(_M_c_locale_codecvt); }
133*e4b17023SJohn Marino 
134*e4b17023SJohn Marino   codecvt_base::result
135*e4b17023SJohn Marino   codecvt<wchar_t, char, mbstate_t>::
do_unshift(state_type &,extern_type * __to,extern_type *,extern_type * & __to_next) const136*e4b17023SJohn Marino   do_unshift(state_type&, extern_type* __to,
137*e4b17023SJohn Marino 	     extern_type*, extern_type*& __to_next) const
138*e4b17023SJohn Marino   {
139*e4b17023SJohn Marino     // XXX Probably wrong for stateful encodings
140*e4b17023SJohn Marino     __to_next = __to;
141*e4b17023SJohn Marino     return noconv;
142*e4b17023SJohn Marino   }
143*e4b17023SJohn Marino 
144*e4b17023SJohn Marino   bool
145*e4b17023SJohn Marino   codecvt<wchar_t, char, mbstate_t>::
do_always_noconv() const146*e4b17023SJohn Marino   do_always_noconv() const throw()
147*e4b17023SJohn Marino   { return false; }
148*e4b17023SJohn Marino #endif //  _GLIBCXX_USE_WCHAR_T
149*e4b17023SJohn Marino 
150*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION
151*e4b17023SJohn Marino } // namespace
152