codecvt.h

来自「ARM Linux Tool 各种代码包括MTD」· C头文件 代码 · 共 718 行 · 第 1/2 页

H
718
字号
      virtual bool       do_always_noconv() const throw();      virtual int       do_length(const state_type&, const extern_type* __from, 		const extern_type* __end, size_t __max) const;      virtual int       do_max_length() const throw();    };  template<typename _InternT, typename _ExternT>    locale::id     codecvt<_InternT, _ExternT, __enc_traits>::id;  // This adaptor works around the signature problems of the second  // argument to iconv():  SUSv2 and others use 'const char**', but glibc 2.2  // uses 'char**', which is what the standard is (apparently) due to use  // in the future.  Using this adaptor, g++ will do the work for us.  template<typename _T>    inline size_t    __iconv_adaptor(size_t(*iconv_func)(iconv_t, _T, size_t*, char**, size_t*),                    iconv_t cd, char** inbuf, size_t* inbytesleft,                    char** outbuf, size_t* outbytesleft)    {      return iconv_func(cd, (_T)inbuf, inbytesleft, outbuf, outbytesleft);    }  template<typename _InternT, typename _ExternT>    codecvt_base::result    codecvt<_InternT, _ExternT, __enc_traits>::    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    {      result __ret = error;      if (__state._M_good())	{	  typedef state_type::__desc_type	__desc_type;	  const __desc_type* __desc = __state._M_get_out_descriptor();	  const size_t __fmultiple = sizeof(intern_type) / sizeof(char);	  size_t __flen = __fmultiple * (__from_end - __from);	  const size_t __tmultiple = sizeof(extern_type) / sizeof(char);	  size_t __tlen = __tmultiple * (__to_end - __to); 	  	  // Argument list for iconv specifies a byte sequence. Thus,	  // all to/from arrays must be brutally casted to char*.	  char* __cto = reinterpret_cast<char*>(__to);	  char* __cfrom;	  size_t __conv;	  // Some encodings need a byte order marker as the first item	  // in the byte stream, to designate endian-ness. The default	  // value for the byte order marker is NULL, so if this is	  // the case, it's not necessary and we can just go on our	  // merry way.	  int __int_bom = __state._M_get_internal_bom();	  if (__int_bom)	    {	  	      size_t __size = __from_end - __from;	      intern_type* __cfixed = static_cast<intern_type*>(__builtin_alloca(sizeof(intern_type) * (__size + 1)));	      __cfixed[0] = static_cast<intern_type>(__int_bom);	      char_traits<intern_type>::copy(__cfixed + 1, __from, __size);	      __cfrom = reinterpret_cast<char*>(__cfixed);	      __conv = __iconv_adaptor(iconv, *__desc, &__cfrom,                                        &__flen, &__cto, &__tlen); 	    }	  else	    {	      intern_type* __cfixed = const_cast<intern_type*>(__from);	      __cfrom = reinterpret_cast<char*>(__cfixed);	      __conv = __iconv_adaptor(iconv, *__desc, &__cfrom,                                       &__flen, &__cto, &__tlen); 	    }	  if (__conv != size_t(-1))	    {	      __from_next = reinterpret_cast<const intern_type*>(__cfrom);	      __to_next = reinterpret_cast<extern_type*>(__cto);	      __ret = ok;	    }	  else 	    {	      if (__flen < static_cast<size_t>(__from_end - __from))		{		  __from_next = reinterpret_cast<const intern_type*>(__cfrom);		  __to_next = reinterpret_cast<extern_type*>(__cto);		  __ret = partial;		}	      else		__ret = error;	    }	}      return __ret;     }  template<typename _InternT, typename _ExternT>    codecvt_base::result    codecvt<_InternT, _ExternT, __enc_traits>::    do_unshift(state_type& __state, extern_type* __to, 	       extern_type* __to_end, extern_type*& __to_next) const    {      result __ret = error;      if (__state._M_good())	{	  typedef state_type::__desc_type	__desc_type;	  const __desc_type* __desc = __state._M_get_in_descriptor();	  const size_t __tmultiple = sizeof(intern_type) / sizeof(char);	  size_t __tlen = __tmultiple * (__to_end - __to); 	  	  // Argument list for iconv specifies a byte sequence. Thus,	  // all to/from arrays must be brutally casted to char*.	  char* __cto = reinterpret_cast<char*>(__to);	  size_t __conv = __iconv_adaptor(iconv,*__desc, NULL, NULL,                                          &__cto, &__tlen); 	  	  if (__conv != size_t(-1))	    {	      __to_next = reinterpret_cast<extern_type*>(__cto);	      if (__tlen == __tmultiple * (__to_end - __to))		__ret = noconv;	      else if (__tlen == 0)		__ret = ok;	      else		__ret = partial;	    }	  else 	    __ret = error;	}      return __ret;     }     template<typename _InternT, typename _ExternT>    codecvt_base::result    codecvt<_InternT, _ExternT, __enc_traits>::    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    {       result __ret = error;      if (__state._M_good())	{	  typedef state_type::__desc_type	__desc_type;	  const __desc_type* __desc = __state._M_get_in_descriptor();	  const size_t __fmultiple = sizeof(extern_type) / sizeof(char);	  size_t __flen = __fmultiple * (__from_end - __from);	  const size_t __tmultiple = sizeof(intern_type) / sizeof(char);	  size_t __tlen = __tmultiple * (__to_end - __to); 	  	  // Argument list for iconv specifies a byte sequence. Thus,	  // all to/from arrays must be brutally casted to char*.	  char* __cto = reinterpret_cast<char*>(__to);	  char* __cfrom;	  size_t __conv;	  // Some encodings need a byte order marker as the first item	  // in the byte stream, to designate endian-ness. The default	  // value for the byte order marker is NULL, so if this is	  // the case, it's not necessary and we can just go on our	  // merry way.	  int __ext_bom = __state._M_get_external_bom();	  if (__ext_bom)	    {	  	      size_t __size = __from_end - __from;	      extern_type* __cfixed =  static_cast<extern_type*>(__builtin_alloca(sizeof(extern_type) * (__size + 1)));	      __cfixed[0] = static_cast<extern_type>(__ext_bom);	      char_traits<extern_type>::copy(__cfixed + 1, __from, __size);	      __cfrom = reinterpret_cast<char*>(__cfixed);	      __conv = __iconv_adaptor(iconv, *__desc, &__cfrom,                                       &__flen, &__cto, &__tlen); 	    }	  else	    {	      extern_type* __cfixed = const_cast<extern_type*>(__from);	      __cfrom = reinterpret_cast<char*>(__cfixed);	      __conv = __iconv_adaptor(iconv, *__desc, &__cfrom,                                       &__flen, &__cto, &__tlen); 	    }	  	  if (__conv != size_t(-1))	    {	      __from_next = reinterpret_cast<const extern_type*>(__cfrom);	      __to_next = reinterpret_cast<intern_type*>(__cto);	      __ret = ok;	    }	  else 	    {	      if (__flen < static_cast<size_t>(__from_end - __from))		{		  __from_next = reinterpret_cast<const extern_type*>(__cfrom);		  __to_next = reinterpret_cast<intern_type*>(__cto);		  __ret = partial;		}	      else		__ret = error;	    }	}      return __ret;     }    template<typename _InternT, typename _ExternT>    int     codecvt<_InternT, _ExternT, __enc_traits>::    do_encoding() const throw()    { return 0; }    template<typename _InternT, typename _ExternT>    bool     codecvt<_InternT, _ExternT, __enc_traits>::    do_always_noconv() const throw()    { return false; }    template<typename _InternT, typename _ExternT>    int     codecvt<_InternT, _ExternT, __enc_traits>::    do_length(const state_type&, const extern_type* __from, 	      const extern_type* __end, size_t __max) const    { return min(__max, static_cast<size_t>(__end - __from)); }#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS// 74.  Garbled text for codecvt::do_max_length  template<typename _InternT, typename _ExternT>    int     codecvt<_InternT, _ExternT, __enc_traits>::    do_max_length() const throw()    { return 1; }#endif#endif /* _GLIBCPP_USE_WCHAR_T */  // codecvt<char, char, mbstate_t> required specialization  template<>    class codecvt<char, char, mbstate_t>     : public __codecvt_abstract_base<char, char, mbstate_t>    {    public:            // Types:      typedef char 	intern_type;      typedef char 	extern_type;      typedef mbstate_t state_type;      // Data Members:      static locale::id id;      explicit       codecvt(size_t __refs = 0);    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();      virtual int       do_length(const state_type&, const extern_type* __from, 		const extern_type* __end, size_t __max) const;      virtual int       do_max_length() const throw();  };#ifdef _GLIBCPP_USE_WCHAR_T  // codecvt<wchar_t, char, mbstate_t> required specialization  template<>    class codecvt<wchar_t, char, mbstate_t>     : public __codecvt_abstract_base<wchar_t, char, mbstate_t>    {    public:      // Types:      typedef wchar_t 	intern_type;      typedef char 	extern_type;      typedef mbstate_t state_type;      // Data Members:      static locale::id id;      explicit       codecvt(size_t __refs = 0);    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();      virtual       int do_length(const state_type&, const extern_type* __from,		    const extern_type* __end, size_t __max) const;      virtual int       do_max_length() const throw();    };#endif //_GLIBCPP_USE_WCHAR_T  // 22.2.1.6  Template class codecvt_byname  template<typename _InternT, typename _ExternT, typename _StateT>    class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT>    {    public:      explicit       codecvt_byname(const char*, size_t __refs = 0)       : codecvt<_InternT, _ExternT, _StateT>(__refs) { }    protected:      virtual       ~codecvt_byname() { }    };#endif // _CPP_BITS_CODECVT_H// Local Variables:// mode:c++// End:

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?