Import of virgin gcc 4.0.0 distribution.
[dragonfly.git] / contrib / gcc-4.0 / libstdc++-v3 / src / codecvt.cc
1 // Copyright (C) 2000, 2002, 2004, 2005 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 2, 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 // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
18
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction.  Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License.  This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
27
28 // Written by Benjamin Kosnik <bkoz@redhat.com>
29
30 #include <locale>
31
32 namespace std 
33 {
34   // Definitions for locale::id of standard facets that are specialized.
35  locale::id codecvt<char, char, mbstate_t>::id;
36
37 #ifdef _GLIBCXX_USE_WCHAR_T  
38   locale::id codecvt<wchar_t, char, mbstate_t>::id;
39 #endif
40
41   codecvt<char, char, mbstate_t>::
42   codecvt(size_t __refs)
43   : __codecvt_abstract_base<char, char, mbstate_t>(__refs),
44   _M_c_locale_codecvt(_S_get_c_locale())
45   { }
46
47   codecvt<char, char, mbstate_t>::
48   codecvt(__c_locale __cloc, size_t __refs)
49   : __codecvt_abstract_base<char, char, mbstate_t>(__refs),
50   _M_c_locale_codecvt(_S_clone_c_locale(__cloc))
51   { }
52
53   codecvt<char, char, mbstate_t>::
54   ~codecvt()
55   { _S_destroy_c_locale(_M_c_locale_codecvt); }
56   
57   codecvt_base::result
58   codecvt<char, char, mbstate_t>::
59   do_out(state_type&, const intern_type* __from, 
60          const intern_type*, const intern_type*& __from_next,
61          extern_type* __to, extern_type*, 
62          extern_type*& __to_next) const
63   { 
64     // _GLIBCXX_RESOLVE_LIB_DEFECTS
65     // According to the resolution of DR19, "If returns noconv [...]
66     // there are no changes to the values in [to, to_limit)."
67     __from_next = __from; 
68     __to_next = __to;
69     return noconv;  
70   }
71   
72   codecvt_base::result
73   codecvt<char, char, mbstate_t>::
74   do_unshift(state_type&, extern_type* __to,
75              extern_type*, extern_type*& __to_next) const
76   { 
77     __to_next = __to; 
78     return noconv; 
79   }
80   
81   codecvt_base::result
82   codecvt<char, char, mbstate_t>::
83   do_in(state_type&, const extern_type* __from, 
84         const extern_type*, const extern_type*& __from_next,
85         intern_type* __to, intern_type*, intern_type*& __to_next) const
86   {
87     // _GLIBCXX_RESOLVE_LIB_DEFECTS
88     // According to the resolution of DR19, "If returns noconv [...]
89     // there are no changes to the values in [to, to_limit)."
90     __from_next = __from; 
91     __to_next = __to;
92     return noconv;  
93   }
94
95   int 
96   codecvt<char, char, mbstate_t>::
97   do_encoding() const throw() 
98   { return 1; }
99   
100   bool 
101   codecvt<char, char, mbstate_t>::
102   do_always_noconv() const throw() 
103   { return true; }
104   
105   int 
106   codecvt<char, char, mbstate_t>::
107   do_length (state_type&, const extern_type* __from,
108              const extern_type* __end, size_t __max) const
109   { 
110     size_t __d = static_cast<size_t>(__end - __from);
111     return std::min(__max, __d); 
112   }
113   
114   int 
115   codecvt<char, char, mbstate_t>::
116   do_max_length() const throw() 
117   { return 1; }
118   
119 #ifdef _GLIBCXX_USE_WCHAR_T
120   // codecvt<wchar_t, char, mbstate_t> required specialization
121   codecvt<wchar_t, char, mbstate_t>::
122   codecvt(size_t __refs)
123   : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs),
124   _M_c_locale_codecvt(_S_get_c_locale())
125   { }
126
127   codecvt<wchar_t, char, mbstate_t>::
128   codecvt(__c_locale __cloc, size_t __refs)
129   : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs),
130   _M_c_locale_codecvt(_S_clone_c_locale(__cloc))
131   { }
132
133   codecvt<wchar_t, char, mbstate_t>::
134   ~codecvt()
135   { _S_destroy_c_locale(_M_c_locale_codecvt); }
136   
137   codecvt_base::result
138   codecvt<wchar_t, char, mbstate_t>::
139   do_unshift(state_type&, extern_type* __to,
140              extern_type*, extern_type*& __to_next) const
141   {
142     // XXX Probably wrong for stateful encodings
143     __to_next = __to;
144     return noconv;
145   }
146   
147   bool 
148   codecvt<wchar_t, char, mbstate_t>::
149   do_always_noconv() const throw()
150   { return false; }
151 #endif //  _GLIBCXX_USE_WCHAR_T
152 } // namespace std