Import gcc-4.4.1
[dragonfly.git] / contrib / gcc-4.4 / libstdc++-v3 / src / codecvt.cc
1 // Copyright (C) 2000, 2002, 2004, 2005, 2009 Free Software Foundation, Inc.
2 //
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 3, or (at your option)
7 // any later version.
8
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.
13
14 // Under Section 7 of GPL version 3, you are granted additional
15 // permissions described in the GCC Runtime Library Exception, version
16 // 3.1, as published by the Free Software Foundation.
17
18 // You should have received a copy of the GNU General Public License and
19 // a copy of the GCC Runtime Library Exception along with this program;
20 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
21 // <http://www.gnu.org/licenses/>.
22
23 // Written by Benjamin Kosnik <bkoz@redhat.com>
24
25 #include <locale>
26
27 _GLIBCXX_BEGIN_NAMESPACE(std)
28
29   // Definitions for locale::id of standard facets that are specialized.
30  locale::id codecvt<char, char, mbstate_t>::id;
31
32 #ifdef _GLIBCXX_USE_WCHAR_T  
33   locale::id codecvt<wchar_t, char, mbstate_t>::id;
34 #endif
35
36   codecvt<char, char, mbstate_t>::
37   codecvt(size_t __refs)
38   : __codecvt_abstract_base<char, char, mbstate_t>(__refs),
39   _M_c_locale_codecvt(_S_get_c_locale())
40   { }
41
42   codecvt<char, char, mbstate_t>::
43   codecvt(__c_locale __cloc, size_t __refs)
44   : __codecvt_abstract_base<char, char, mbstate_t>(__refs),
45   _M_c_locale_codecvt(_S_clone_c_locale(__cloc))
46   { }
47
48   codecvt<char, char, mbstate_t>::
49   ~codecvt()
50   { _S_destroy_c_locale(_M_c_locale_codecvt); }
51   
52   codecvt_base::result
53   codecvt<char, char, mbstate_t>::
54   do_out(state_type&, const intern_type* __from, 
55          const intern_type*, const intern_type*& __from_next,
56          extern_type* __to, extern_type*, 
57          extern_type*& __to_next) const
58   { 
59     // _GLIBCXX_RESOLVE_LIB_DEFECTS
60     // According to the resolution of DR19, "If returns noconv [...]
61     // there are no changes to the values in [to, to_limit)."
62     __from_next = __from; 
63     __to_next = __to;
64     return noconv;  
65   }
66   
67   codecvt_base::result
68   codecvt<char, char, mbstate_t>::
69   do_unshift(state_type&, extern_type* __to,
70              extern_type*, extern_type*& __to_next) const
71   { 
72     __to_next = __to; 
73     return noconv; 
74   }
75   
76   codecvt_base::result
77   codecvt<char, char, mbstate_t>::
78   do_in(state_type&, const extern_type* __from, 
79         const extern_type*, const extern_type*& __from_next,
80         intern_type* __to, intern_type*, intern_type*& __to_next) const
81   {
82     // _GLIBCXX_RESOLVE_LIB_DEFECTS
83     // According to the resolution of DR19, "If returns noconv [...]
84     // there are no changes to the values in [to, to_limit)."
85     __from_next = __from; 
86     __to_next = __to;
87     return noconv;  
88   }
89
90   int 
91   codecvt<char, char, mbstate_t>::
92   do_encoding() const throw() 
93   { return 1; }
94   
95   bool 
96   codecvt<char, char, mbstate_t>::
97   do_always_noconv() const throw() 
98   { return true; }
99   
100   int 
101   codecvt<char, char, mbstate_t>::
102   do_length (state_type&, const extern_type* __from,
103              const extern_type* __end, size_t __max) const
104   { 
105     size_t __d = static_cast<size_t>(__end - __from);
106     return std::min(__max, __d); 
107   }
108   
109   int 
110   codecvt<char, char, mbstate_t>::
111   do_max_length() const throw() 
112   { return 1; }
113   
114 #ifdef _GLIBCXX_USE_WCHAR_T
115   // codecvt<wchar_t, char, mbstate_t> required specialization
116   codecvt<wchar_t, char, mbstate_t>::
117   codecvt(size_t __refs)
118   : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs),
119   _M_c_locale_codecvt(_S_get_c_locale())
120   { }
121
122   codecvt<wchar_t, char, mbstate_t>::
123   codecvt(__c_locale __cloc, size_t __refs)
124   : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs),
125   _M_c_locale_codecvt(_S_clone_c_locale(__cloc))
126   { }
127
128   codecvt<wchar_t, char, mbstate_t>::
129   ~codecvt()
130   { _S_destroy_c_locale(_M_c_locale_codecvt); }
131   
132   codecvt_base::result
133   codecvt<wchar_t, char, mbstate_t>::
134   do_unshift(state_type&, extern_type* __to,
135              extern_type*, extern_type*& __to_next) const
136   {
137     // XXX Probably wrong for stateful encodings
138     __to_next = __to;
139     return noconv;
140   }
141   
142   bool 
143   codecvt<wchar_t, char, mbstate_t>::
144   do_always_noconv() const throw()
145   { return false; }
146 #endif //  _GLIBCXX_USE_WCHAR_T
147
148 _GLIBCXX_END_NAMESPACE