Extension to use iconv for dealing with character encodings.
codecvt<InternT, _ExternT, encoding_state> specialization.
44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
56 typedef iconv_t descriptor_type;
66 descriptor_type _M_in_desc;
69 descriptor_type _M_out_desc;
85 : _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0), _M_bytes(0)
89 encoding_state(
const char* __int,
const char* __ext,
90 int __ibom = 0,
int __ebom = 0,
int __bytes = 1)
91 : _M_int_enc(__int), _M_ext_enc(__ext), _M_in_desc(0), _M_out_desc(0),
92 _M_ext_bom(__ebom), _M_int_bom(__ibom), _M_bytes(__bytes)
103 encoding_state(
const encoding_state& __obj) : _M_in_desc(0), _M_out_desc(0)
104 { construct(__obj); }
108 operator=(
const encoding_state& __obj)
120 const descriptor_type __err = (iconv_t)(-1);
121 bool __test = _M_in_desc && _M_in_desc != __err;
122 __test &= _M_out_desc && _M_out_desc != __err;
127 character_ratio()
const
131 internal_encoding()
const
132 {
return _M_int_enc; }
136 {
return _M_int_bom; }
139 external_encoding()
const
140 {
return _M_ext_enc; }
144 {
return _M_ext_bom; }
146 const descriptor_type&
147 in_descriptor()
const
148 {
return _M_in_desc; }
150 const descriptor_type&
151 out_descriptor()
const
152 {
return _M_out_desc; }
158 const descriptor_type __err = (iconv_t)(-1);
159 const bool __have_encodings = _M_int_enc.size() && _M_ext_enc.size();
160 if (!_M_in_desc && __have_encodings)
162 _M_in_desc = iconv_open(_M_int_enc.c_str(), _M_ext_enc.c_str());
163 if (_M_in_desc == __err)
164 std::__throw_runtime_error(__N(
"encoding_state::_M_init "
165 "creating iconv input descriptor failed"));
167 if (!_M_out_desc && __have_encodings)
169 _M_out_desc = iconv_open(_M_ext_enc.c_str(), _M_int_enc.c_str());
170 if (_M_out_desc == __err)
171 std::__throw_runtime_error(__N(
"encoding_state::_M_init "
172 "creating iconv output descriptor failed"));
177 construct(
const encoding_state& __obj)
180 _M_int_enc = __obj._M_int_enc;
181 _M_ext_enc = __obj._M_ext_enc;
182 _M_ext_bom = __obj._M_ext_bom;
183 _M_int_bom = __obj._M_int_bom;
184 _M_bytes = __obj._M_bytes;
191 const descriptor_type __err = (iconv_t)(-1);
192 if (_M_in_desc && _M_in_desc != __err)
194 iconv_close(_M_in_desc);
197 if (_M_out_desc && _M_out_desc != __err)
199 iconv_close(_M_out_desc);
209 template<
typename _CharT>
210 struct encoding_char_traits :
public std::char_traits<_CharT>
212 typedef encoding_state state_type;
213 typedef typename std::fpos<state_type> pos_type;
216 _GLIBCXX_END_NAMESPACE_VERSION
basic_string< char > string
Definition: string:1153