libstdc++
|
00001 // <codecvt> -*- C++ -*- 00002 00003 // Copyright (C) 2015-2019 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 // ISO C++ 14882: 22.5 Standard code conversion facets 00026 00027 /** @file include/codecvt 00028 * This is a Standard C++ Library header. 00029 */ 00030 00031 #ifndef _GLIBCXX_CODECVT 00032 #define _GLIBCXX_CODECVT 1 00033 00034 #pragma GCC system_header 00035 00036 #if __cplusplus < 201103L 00037 # include <bits/c++0x_warning.h> 00038 #else 00039 00040 #include <bits/locale_classes.h> 00041 #include <bits/codecvt.h> 00042 00043 namespace std _GLIBCXX_VISIBILITY(default) 00044 { 00045 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00046 00047 enum codecvt_mode 00048 { 00049 consume_header = 4, 00050 generate_header = 2, 00051 little_endian = 1 00052 }; 00053 00054 template<typename _Elem, unsigned long _Maxcode = 0x10ffff, 00055 codecvt_mode _Mode = (codecvt_mode)0> 00056 class codecvt_utf8 : public codecvt<_Elem, char, mbstate_t> 00057 { 00058 public: 00059 explicit 00060 codecvt_utf8(size_t __refs = 0); 00061 00062 ~codecvt_utf8(); 00063 }; 00064 00065 template<typename _Elem, unsigned long _Maxcode = 0x10ffff, 00066 codecvt_mode _Mode = (codecvt_mode)0> 00067 class codecvt_utf16 : public codecvt<_Elem, char, mbstate_t> 00068 { 00069 public: 00070 explicit 00071 codecvt_utf16(size_t __refs = 0); 00072 00073 ~codecvt_utf16(); 00074 }; 00075 00076 template<typename _Elem, unsigned long _Maxcode = 0x10ffff, 00077 codecvt_mode _Mode = (codecvt_mode)0> 00078 class codecvt_utf8_utf16 : public codecvt<_Elem, char, mbstate_t> 00079 { 00080 public: 00081 explicit 00082 codecvt_utf8_utf16(size_t __refs = 0); 00083 00084 ~codecvt_utf8_utf16(); 00085 }; 00086 00087 #define _GLIBCXX_CODECVT_SPECIALIZATION2(_NAME, _ELEM) \ 00088 template<> \ 00089 class _NAME<_ELEM> \ 00090 : public codecvt<_ELEM, char, mbstate_t> \ 00091 { \ 00092 public: \ 00093 typedef _ELEM intern_type; \ 00094 typedef char extern_type; \ 00095 typedef mbstate_t state_type; \ 00096 \ 00097 protected: \ 00098 _NAME(unsigned long __maxcode, codecvt_mode __mode, size_t __refs) \ 00099 : codecvt(__refs), _M_maxcode(__maxcode), _M_mode(__mode) { } \ 00100 \ 00101 virtual \ 00102 ~_NAME(); \ 00103 \ 00104 virtual result \ 00105 do_out(state_type& __state, const intern_type* __from, \ 00106 const intern_type* __from_end, const intern_type*& __from_next, \ 00107 extern_type* __to, extern_type* __to_end, \ 00108 extern_type*& __to_next) const; \ 00109 \ 00110 virtual result \ 00111 do_unshift(state_type& __state, \ 00112 extern_type* __to, extern_type* __to_end, \ 00113 extern_type*& __to_next) const; \ 00114 \ 00115 virtual result \ 00116 do_in(state_type& __state, \ 00117 const extern_type* __from, const extern_type* __from_end, \ 00118 const extern_type*& __from_next, \ 00119 intern_type* __to, intern_type* __to_end, \ 00120 intern_type*& __to_next) const; \ 00121 \ 00122 virtual \ 00123 int do_encoding() const throw(); \ 00124 \ 00125 virtual \ 00126 bool do_always_noconv() const throw(); \ 00127 \ 00128 virtual \ 00129 int do_length(state_type&, const extern_type* __from, \ 00130 const extern_type* __end, size_t __max) const; \ 00131 \ 00132 virtual int \ 00133 do_max_length() const throw(); \ 00134 \ 00135 private: \ 00136 unsigned long _M_maxcode; \ 00137 codecvt_mode _M_mode; \ 00138 } 00139 00140 #define _GLIBCXX_CODECVT_SPECIALIZATION(_NAME, _ELEM) \ 00141 _GLIBCXX_CODECVT_SPECIALIZATION2(__ ## _NAME ## _base, _ELEM); \ 00142 template<unsigned long _Maxcode, codecvt_mode _Mode> \ 00143 class _NAME<_ELEM, _Maxcode, _Mode> \ 00144 : public __ ## _NAME ## _base<_ELEM> \ 00145 { \ 00146 public: \ 00147 explicit \ 00148 _NAME(size_t __refs = 0) \ 00149 : __ ## _NAME ## _base<_ELEM>(std::min(_Maxcode, 0x10fffful), \ 00150 _Mode, __refs) \ 00151 { } \ 00152 } 00153 00154 template<typename _Elem> class __codecvt_utf8_base; 00155 template<typename _Elem> class __codecvt_utf16_base; 00156 template<typename _Elem> class __codecvt_utf8_utf16_base; 00157 00158 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, char16_t); 00159 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, char16_t); 00160 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, char16_t); 00161 00162 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, char32_t); 00163 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, char32_t); 00164 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, char32_t); 00165 00166 #ifdef _GLIBCXX_USE_WCHAR_T 00167 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, wchar_t); 00168 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, wchar_t); 00169 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, wchar_t); 00170 #endif 00171 00172 _GLIBCXX_END_NAMESPACE_VERSION 00173 } // namespace 00174 00175 #endif // C++11 00176 00177 #endif /* _GLIBCXX_CODECVT */