00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef _CODECVT_H
00038 #define _CODECVT_H 1
00039
00040 #pragma GCC system_header
00041
00042 _GLIBCXX_BEGIN_NAMESPACE(std)
00043
00044
00045 class codecvt_base
00046 {
00047 public:
00048 enum result
00049 {
00050 ok,
00051 partial,
00052 error,
00053 noconv
00054 };
00055 };
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 template<typename _InternT, typename _ExternT, typename _StateT>
00067 class __codecvt_abstract_base
00068 : public locale::facet, public codecvt_base
00069 {
00070 public:
00071
00072 typedef codecvt_base::result result;
00073 typedef _InternT intern_type;
00074 typedef _ExternT extern_type;
00075 typedef _StateT state_type;
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 result
00115 out(state_type& __state, const intern_type* __from,
00116 const intern_type* __from_end, const intern_type*& __from_next,
00117 extern_type* __to, extern_type* __to_end,
00118 extern_type*& __to_next) const
00119 {
00120 return this->do_out(__state, __from, __from_end, __from_next,
00121 __to, __to_end, __to_next);
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 result
00154 unshift(state_type& __state, extern_type* __to, extern_type* __to_end,
00155 extern_type*& __to_next) const
00156 { return this->do_unshift(__state, __to,__to_end,__to_next); }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 result
00195 in(state_type& __state, const extern_type* __from,
00196 const extern_type* __from_end, const extern_type*& __from_next,
00197 intern_type* __to, intern_type* __to_end,
00198 intern_type*& __to_next) const
00199 {
00200 return this->do_in(__state, __from, __from_end, __from_next,
00201 __to, __to_end, __to_next);
00202 }
00203
00204 int
00205 encoding() const throw()
00206 { return this->do_encoding(); }
00207
00208 bool
00209 always_noconv() const throw()
00210 { return this->do_always_noconv(); }
00211
00212 int
00213 length(state_type& __state, const extern_type* __from,
00214 const extern_type* __end, size_t __max) const
00215 { return this->do_length(__state, __from, __end, __max); }
00216
00217 int
00218 max_length() const throw()
00219 { return this->do_max_length(); }
00220
00221 protected:
00222 explicit
00223 __codecvt_abstract_base(size_t __refs = 0) : locale::facet(__refs) { }
00224
00225 virtual
00226 ~__codecvt_abstract_base() { }
00227
00228
00229
00230
00231
00232
00233
00234
00235 virtual result
00236 do_out(state_type& __state, const intern_type* __from,
00237 const intern_type* __from_end, const intern_type*& __from_next,
00238 extern_type* __to, extern_type* __to_end,
00239 extern_type*& __to_next) const = 0;
00240
00241 virtual result
00242 do_unshift(state_type& __state, extern_type* __to,
00243 extern_type* __to_end, extern_type*& __to_next) const = 0;
00244
00245 virtual result
00246 do_in(state_type& __state, const extern_type* __from,
00247 const extern_type* __from_end, const extern_type*& __from_next,
00248 intern_type* __to, intern_type* __to_end,
00249 intern_type*& __to_next) const = 0;
00250
00251 virtual int
00252 do_encoding() const throw() = 0;
00253
00254 virtual bool
00255 do_always_noconv() const throw() = 0;
00256
00257 virtual int
00258 do_length(state_type&, const extern_type* __from,
00259 const extern_type* __end, size_t __max) const = 0;
00260
00261 virtual int
00262 do_max_length() const throw() = 0;
00263 };
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 template<typename _InternT, typename _ExternT, typename _StateT>
00275 class codecvt
00276 : public __codecvt_abstract_base<_InternT, _ExternT, _StateT>
00277 {
00278 public:
00279
00280 typedef codecvt_base::result result;
00281 typedef _InternT intern_type;
00282 typedef _ExternT extern_type;
00283 typedef _StateT state_type;
00284
00285 protected:
00286 __c_locale _M_c_locale_codecvt;
00287
00288 public:
00289 static locale::id id;
00290
00291 explicit
00292 codecvt(size_t __refs = 0)
00293 : __codecvt_abstract_base<_InternT, _ExternT, _StateT> (__refs) { }
00294
00295 explicit
00296 codecvt(__c_locale __cloc, size_t __refs = 0);
00297
00298 protected:
00299 virtual
00300 ~codecvt() { }
00301
00302 virtual result
00303 do_out(state_type& __state, const intern_type* __from,
00304 const intern_type* __from_end, const intern_type*& __from_next,
00305 extern_type* __to, extern_type* __to_end,
00306 extern_type*& __to_next) const;
00307
00308 virtual result
00309 do_unshift(state_type& __state, extern_type* __to,
00310 extern_type* __to_end, extern_type*& __to_next) const;
00311
00312 virtual result
00313 do_in(state_type& __state, const extern_type* __from,
00314 const extern_type* __from_end, const extern_type*& __from_next,
00315 intern_type* __to, intern_type* __to_end,
00316 intern_type*& __to_next) const;
00317
00318 virtual int
00319 do_encoding() const throw();
00320
00321 virtual bool
00322 do_always_noconv() const throw();
00323
00324 virtual int
00325 do_length(state_type&, const extern_type* __from,
00326 const extern_type* __end, size_t __max) const;
00327
00328 virtual int
00329 do_max_length() const throw();
00330 };
00331
00332 template<typename _InternT, typename _ExternT, typename _StateT>
00333 locale::id codecvt<_InternT, _ExternT, _StateT>::id;
00334
00335
00336 template<>
00337 class codecvt<char, char, mbstate_t>
00338 : public __codecvt_abstract_base<char, char, mbstate_t>
00339 {
00340 public:
00341
00342 typedef char intern_type;
00343 typedef char extern_type;
00344 typedef mbstate_t state_type;
00345
00346 protected:
00347 __c_locale _M_c_locale_codecvt;
00348
00349 public:
00350 static locale::id id;
00351
00352 explicit
00353 codecvt(size_t __refs = 0);
00354
00355 explicit
00356 codecvt(__c_locale __cloc, size_t __refs = 0);
00357
00358 protected:
00359 virtual
00360 ~codecvt();
00361
00362 virtual result
00363 do_out(state_type& __state, const intern_type* __from,
00364 const intern_type* __from_end, const intern_type*& __from_next,
00365 extern_type* __to, extern_type* __to_end,
00366 extern_type*& __to_next) const;
00367
00368 virtual result
00369 do_unshift(state_type& __state, extern_type* __to,
00370 extern_type* __to_end, extern_type*& __to_next) const;
00371
00372 virtual result
00373 do_in(state_type& __state, const extern_type* __from,
00374 const extern_type* __from_end, const extern_type*& __from_next,
00375 intern_type* __to, intern_type* __to_end,
00376 intern_type*& __to_next) const;
00377
00378 virtual int
00379 do_encoding() const throw();
00380
00381 virtual bool
00382 do_always_noconv() const throw();
00383
00384 virtual int
00385 do_length(state_type&, const extern_type* __from,
00386 const extern_type* __end, size_t __max) const;
00387
00388 virtual int
00389 do_max_length() const throw();
00390 };
00391
00392 #ifdef _GLIBCXX_USE_WCHAR_T
00393
00394 template<>
00395 class codecvt<wchar_t, char, mbstate_t>
00396 : public __codecvt_abstract_base<wchar_t, char, mbstate_t>
00397 {
00398 public:
00399
00400 typedef wchar_t intern_type;
00401 typedef char extern_type;
00402 typedef mbstate_t state_type;
00403
00404 protected:
00405 __c_locale _M_c_locale_codecvt;
00406
00407 public:
00408 static locale::id id;
00409
00410 explicit
00411 codecvt(size_t __refs = 0);
00412
00413 explicit
00414 codecvt(__c_locale __cloc, size_t __refs = 0);
00415
00416 protected:
00417 virtual
00418 ~codecvt();
00419
00420 virtual result
00421 do_out(state_type& __state, const intern_type* __from,
00422 const intern_type* __from_end, const intern_type*& __from_next,
00423 extern_type* __to, extern_type* __to_end,
00424 extern_type*& __to_next) const;
00425
00426 virtual result
00427 do_unshift(state_type& __state,
00428 extern_type* __to, extern_type* __to_end,
00429 extern_type*& __to_next) const;
00430
00431 virtual result
00432 do_in(state_type& __state,
00433 const extern_type* __from, const extern_type* __from_end,
00434 const extern_type*& __from_next,
00435 intern_type* __to, intern_type* __to_end,
00436 intern_type*& __to_next) const;
00437
00438 virtual
00439 int do_encoding() const throw();
00440
00441 virtual
00442 bool do_always_noconv() const throw();
00443
00444 virtual
00445 int do_length(state_type&, const extern_type* __from,
00446 const extern_type* __end, size_t __max) const;
00447
00448 virtual int
00449 do_max_length() const throw();
00450 };
00451 #endif //_GLIBCXX_USE_WCHAR_T
00452
00453
00454 template<typename _InternT, typename _ExternT, typename _StateT>
00455 class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT>
00456 {
00457 public:
00458 explicit
00459 codecvt_byname(const char* __s, size_t __refs = 0)
00460 : codecvt<_InternT, _ExternT, _StateT>(__refs)
00461 {
00462 if (__builtin_strcmp(__s, "C") != 0
00463 && __builtin_strcmp(__s, "POSIX") != 0)
00464 {
00465 this->_S_destroy_c_locale(this->_M_c_locale_codecvt);
00466 this->_S_create_c_locale(this->_M_c_locale_codecvt, __s);
00467 }
00468 }
00469
00470 protected:
00471 virtual
00472 ~codecvt_byname() { }
00473 };
00474
00475
00476
00477
00478 #if _GLIBCXX_EXTERN_TEMPLATE
00479 extern template class codecvt_byname<char, char, mbstate_t>;
00480
00481 extern template
00482 const codecvt<char, char, mbstate_t>&
00483 use_facet<codecvt<char, char, mbstate_t> >(const locale&);
00484
00485 extern template
00486 bool
00487 has_facet<codecvt<char, char, mbstate_t> >(const locale&);
00488
00489 #ifdef _GLIBCXX_USE_WCHAR_T
00490 extern template class codecvt_byname<wchar_t, char, mbstate_t>;
00491
00492 extern template
00493 const codecvt<wchar_t, char, mbstate_t>&
00494 use_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
00495
00496 extern template
00497 bool
00498 has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
00499 #endif
00500 #endif
00501
00502 _GLIBCXX_END_NAMESPACE
00503
00504 #endif // _CODECVT_H