📄 codecvt_specializations.h
字号:
// Locale support (codecvt) -*- C++ -*-// Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.//// This file is part of the GNU ISO C++ Library. This library is free// software; you can redistribute it and/or modify it under the// terms of the GNU General Public License as published by the// Free Software Foundation; either version 2, or (at your option)// any later version.// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License along// with this library; see the file COPYING. If not, write to the Free// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,// USA.// As a special exception, you may use this file as part of a free software// library without restriction. Specifically, if other files instantiate// templates or use macros or inline functions from this file, or you compile// this file and link it with other files to produce an executable, this// file does not by itself cause the resulting executable to be covered by// the GNU General Public License. This exception does not however// invalidate any other reasons why the executable file might be covered by// the GNU General Public License.//// ISO C++ 14882: 22.2.1.5 Template class codecvt//// Warning: this file is not meant for user inclusion. Use <locale>.// Written by Benjamin Kosnik <bkoz@cygnus.com> // XXX // Define this here to codecvt.cc can have _S_max_size definition.#define _GLIBCPP_USE___ENC_TRAITS 1 // Extension to use icov for dealing with character encodings, // including conversions and comparisons between various character // sets. This object encapsulates data that may need to be shared between // char_traits, codecvt and ctype. class __enc_traits { public: // Types: // NB: A conversion descriptor subsumes and enhances the // functionality of a simple state type such as mbstate_t. typedef iconv_t __desc_type; protected: // Data Members: // Max size of charset encoding name static const int _S_max_size = 32; // Name of internal character set encoding. char _M_int_enc[_S_max_size]; // Name of external character set encoding. char _M_ext_enc[_S_max_size]; // Conversion descriptor between external encoding to internal encoding. __desc_type _M_in_desc; // Conversion descriptor between internal encoding to external encoding. __desc_type _M_out_desc; // Details the byte-order marker for the external encoding, if necessary. int _M_ext_bom; // Details the byte-order marker for the internal encoding, if necessary. int _M_int_bom; public: explicit __enc_traits() : _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0) { memset(_M_int_enc, 0, _S_max_size); memset(_M_ext_enc, 0, _S_max_size); } explicit __enc_traits(const char* __int, const char* __ext, int __ibom = 0, int __ebom = 0) : _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0) { strncpy(_M_int_enc, __int, _S_max_size); strncpy(_M_ext_enc, __ext, _S_max_size); } // 21.1.2 traits typedefs // p4 // typedef STATE_T state_type // requires: state_type shall meet the requirements of // CopyConstructible types (20.1.3) __enc_traits(const __enc_traits& __obj): _M_in_desc(0), _M_out_desc(0) { strncpy(_M_int_enc, __obj._M_int_enc, _S_max_size); strncpy(_M_ext_enc, __obj._M_ext_enc, _S_max_size); _M_ext_bom = __obj._M_ext_bom; _M_int_bom = __obj._M_int_bom; } // Need assignment operator as well. __enc_traits& operator=(const __enc_traits& __obj) { strncpy(_M_int_enc, __obj._M_int_enc, _S_max_size); strncpy(_M_ext_enc, __obj._M_ext_enc, _S_max_size); _M_in_desc = 0; _M_out_desc = 0; _M_ext_bom = __obj._M_ext_bom; _M_int_bom = __obj._M_int_bom; return *this; } ~__enc_traits() { __desc_type __err = reinterpret_cast<iconv_t>(-1); if (_M_in_desc && _M_in_desc != __err) iconv_close(_M_in_desc); if (_M_out_desc && _M_out_desc != __err) iconv_close(_M_out_desc); } void _M_init() { const __desc_type __err = reinterpret_cast<iconv_t>(-1); if (!_M_in_desc) { _M_in_desc = iconv_open(_M_int_enc, _M_ext_enc); if (_M_in_desc == __err) __throw_runtime_error("creating iconv input descriptor failed."); } if (!_M_out_desc) { _M_out_desc = iconv_open(_M_ext_enc, _M_int_enc); if (_M_out_desc == __err) __throw_runtime_error("creating iconv output descriptor failed."); } } bool _M_good() { const __desc_type __err = reinterpret_cast<iconv_t>(-1); bool __test = _M_in_desc && _M_in_desc != __err; __test &= _M_out_desc && _M_out_desc != __err; return __test; } const __desc_type* _M_get_in_descriptor() { return &_M_in_desc; } const __desc_type* _M_get_out_descriptor() { return &_M_out_desc; } int _M_get_external_bom() { return _M_ext_bom; } int _M_get_internal_bom() { return _M_int_bom; } const char* _M_get_internal_enc() { return _M_int_enc; } const char* _M_get_external_enc() { return _M_ext_enc; } }; // Partial specialization // This specialization takes advantage of iconv to provide code // conversions between a large number of character encodings. template<typename _InternT, typename _ExternT> class codecvt<_InternT, _ExternT, __enc_traits> : public __codecvt_abstract_base<_InternT, _ExternT, __enc_traits> { public: // Types: typedef codecvt_base::result result; typedef _InternT intern_type; typedef _ExternT extern_type; typedef __enc_traits state_type; typedef __enc_traits::__desc_type __desc_type; typedef __enc_traits __enc_type; // Data Members: static locale::id id; explicit codecvt(size_t __refs = 0) : __codecvt_abstract_base<intern_type, extern_type, state_type>(__refs) { } explicit codecvt(__enc_type* __enc, size_t __refs = 0) : __codecvt_abstract_base<intern_type, extern_type, state_type>(__refs) { } protected: virtual ~codecvt() { } virtual result do_out(state_type& __state, const intern_type* __from, const intern_type* __from_end, const intern_type*& __from_next, extern_type* __to, extern_type* __to_end, extern_type*& __to_next) const; virtual result do_unshift(state_type& __state, extern_type* __to, extern_type* __to_end, extern_type*& __to_next) const; virtual result do_in(state_type& __state, const extern_type* __from, const extern_type* __from_end, const extern_type*& __from_next, intern_type* __to, intern_type* __to_end, intern_type*& __to_next) const; virtual int do_encoding() const throw(); virtual bool do_always_noconv() const throw();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -