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
00038
00039
00040
00041
#ifndef _CODECVT_H
00042
#define _CODECVT_H 1
00043
00044
#pragma GCC system_header
00045
00046
00047
00048 class codecvt_base
00049 {
00050
public:
00051
enum result
00052 {
00053 ok,
00054 partial,
00055 error,
00056 noconv
00057 };
00058 };
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
template<
typename _InternT,
typename _ExternT,
typename _StateT>
00074 class __codecvt_abstract_base
00075 :
public locale::facet,
public codecvt_base
00076 {
00077
public:
00078
00079
typedef codecvt_base::result result;
00080
typedef _InternT intern_type;
00081
typedef _ExternT extern_type;
00082
typedef _StateT state_type;
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
00115
00116
00117
00118
00119
00120 result
00121 out(state_type& __state,
const intern_type* __from,
00122
const intern_type* __from_end,
const intern_type*& __from_next,
00123 extern_type* __to, extern_type* __to_end,
00124 extern_type*& __to_next)
const
00125
{
00126
return this->do_out(__state, __from, __from_end, __from_next,
00127 __to, __to_end, __to_next);
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
00154
00155
00156
00157
00158
00159 result
00160 unshift(state_type& __state, extern_type* __to, extern_type* __to_end,
00161 extern_type*& __to_next)
const
00162
{
return this->do_unshift(__state, __to,__to_end,__to_next); }
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
00195
00196
00197
00198
00199 result
00200 in(state_type& __state,
const extern_type* __from,
00201
const extern_type* __from_end,
const extern_type*& __from_next,
00202 intern_type* __to, intern_type* __to_end,
00203 intern_type*& __to_next)
const
00204
{
00205
return this->do_in(__state, __from, __from_end, __from_next,
00206 __to, __to_end, __to_next);
00207 }
00208
00209
int
00210 encoding() const throw()
00211 {
return this->do_encoding(); }
00212
00213
bool
00214 always_noconv() const throw()
00215 {
return this->do_always_noconv(); }
00216
00217
int
00218 length(state_type& __state,
const extern_type* __from,
00219
const extern_type* __end, size_t __max)
const
00220
{
return this->do_length(__state, __from, __end, __max); }
00221
00222
int
00223 max_length() const throw()
00224 {
return this->do_max_length(); }
00225
00226
protected:
00227
explicit
00228 __codecvt_abstract_base(size_t __refs = 0) : locale::facet(__refs) { }
00229
00230
virtual
00231 ~__codecvt_abstract_base() { }
00232
00233
00234
00235
00236
00237
00238
00239
00240
virtual result
00241 do_out(state_type& __state,
const intern_type* __from,
00242
const intern_type* __from_end,
const intern_type*& __from_next,
00243 extern_type* __to, extern_type* __to_end,
00244 extern_type*& __to_next)
const = 0;
00245
00246
virtual result
00247 do_unshift(state_type& __state, extern_type* __to,
00248 extern_type* __to_end, extern_type*& __to_next)
const = 0;
00249
00250
virtual result
00251 do_in(state_type& __state,
const extern_type* __from,
00252
const extern_type* __from_end,
const extern_type*& __from_next,
00253 intern_type* __to, intern_type* __to_end,
00254 intern_type*& __to_next)
const = 0;
00255
00256
virtual int
00257 do_encoding() const throw() = 0;
00258
00259 virtual
bool
00260 do_always_noconv() const throw() = 0;
00261
00262 virtual
int
00263 do_length(state_type&, const extern_type* __from,
00264 const extern_type* __end, size_t __max) const = 0;
00265
00266 virtual
int
00267 do_max_length() const throw() = 0;
00268 };
00269
00270
00271
00272 template<typename _InternT, typename _ExternT, typename _StateT>
00273 class codecvt
00274 : public __codecvt_abstract_base<_InternT, _ExternT, _StateT>
00275 {
00276
public:
00277
00278
typedef codecvt_base::result result;
00279
typedef _InternT intern_type;
00280
typedef _ExternT extern_type;
00281
typedef _StateT state_type;
00282
00283
protected:
00284 __c_locale _M_c_locale_codecvt;
00285
00286
public:
00287
static locale::id
id;
00288
00289
explicit
00290 codecvt(size_t __refs = 0)
00291 : __codecvt_abstract_base<_InternT, _ExternT, _StateT> (__refs) { }
00292
00293
explicit
00294 codecvt(__c_locale __cloc, size_t __refs = 0);
00295
00296
protected:
00297
virtual
00298 ~codecvt() { }
00299
00300
virtual result
00301 do_out(state_type& __state,
const intern_type* __from,
00302
const intern_type* __from_end,
const intern_type*& __from_next,
00303 extern_type* __to, extern_type* __to_end,
00304 extern_type*& __to_next)
const;
00305
00306
virtual result
00307 do_unshift(state_type& __state, extern_type* __to,
00308 extern_type* __to_end, extern_type*& __to_next)
const;
00309
00310
virtual result
00311 do_in(state_type& __state,
const extern_type* __from,
00312
const extern_type* __from_end,
const extern_type*& __from_next,
00313 intern_type* __to, intern_type* __to_end,
00314 intern_type*& __to_next)
const;
00315
00316
virtual int
00317 do_encoding() const throw();
00318
00319 virtual
bool
00320 do_always_noconv() const throw();
00321
00322 virtual
int
00323 do_length(state_type&, const extern_type* __from,
00324 const extern_type* __end, size_t __max) const;
00325
00326 virtual
int
00327 do_max_length() const throw();
00328 };
00329
00330 template<typename _InternT, typename _ExternT, typename _StateT>
00331 locale::
id codecvt<_InternT, _ExternT, _StateT>::
id;
00332
00333
00334 template<>
00335 class codecvt<
char,
char, mbstate_t>
00336 : public __codecvt_abstract_base<
char,
char, mbstate_t>
00337 {
00338
public:
00339
00340
typedef char intern_type;
00341
typedef char extern_type;
00342
typedef mbstate_t state_type;
00343
00344
protected:
00345 __c_locale _M_c_locale_codecvt;
00346
00347
public:
00348
static locale::id
id;
00349
00350
explicit
00351 codecvt(size_t __refs = 0);
00352
00353
explicit
00354 codecvt(__c_locale __cloc, size_t __refs = 0);
00355
00356
protected:
00357
virtual
00358 ~codecvt();
00359
00360
virtual result
00361 do_out(state_type& __state,
const intern_type* __from,
00362
const intern_type* __from_end,
const intern_type*& __from_next,
00363 extern_type* __to, extern_type* __to_end,
00364 extern_type*& __to_next)
const;
00365
00366
virtual result
00367 do_unshift(state_type& __state, extern_type* __to,
00368 extern_type* __to_end, extern_type*& __to_next)
const;
00369
00370
virtual result
00371 do_in(state_type& __state,
const extern_type* __from,
00372
const extern_type* __from_end,
const extern_type*& __from_next,
00373 intern_type* __to, intern_type* __to_end,
00374 intern_type*& __to_next)
const;
00375
00376
virtual int
00377 do_encoding() const throw();
00378
00379 virtual
bool
00380 do_always_noconv() const throw();
00381
00382 virtual
int
00383 do_length(state_type&, const extern_type* __from,
00384 const extern_type* __end, size_t __max) const;
00385
00386 virtual
int
00387 do_max_length() const throw();
00388 };
00389
00390 #ifdef _GLIBCXX_USE_WCHAR_T
00391
00392 template<>
00393 class codecvt<
wchar_t,
char, mbstate_t>
00394 : public __codecvt_abstract_base<
wchar_t,
char, mbstate_t>
00395 {
00396
public:
00397
00398
typedef wchar_t intern_type;
00399
typedef char extern_type;
00400
typedef mbstate_t state_type;
00401
00402
protected:
00403 __c_locale _M_c_locale_codecvt;
00404
00405
public:
00406
static locale::id
id;
00407
00408
explicit
00409 codecvt(size_t __refs = 0);
00410
00411
explicit
00412 codecvt(__c_locale __cloc, size_t __refs = 0);
00413
00414
protected:
00415
virtual
00416 ~codecvt();
00417
00418
virtual result
00419 do_out(state_type& __state,
const intern_type* __from,
00420
const intern_type* __from_end,
const intern_type*& __from_next,
00421 extern_type* __to, extern_type* __to_end,
00422 extern_type*& __to_next)
const;
00423
00424
virtual result
00425 do_unshift(state_type& __state,
00426 extern_type* __to, extern_type* __to_end,
00427 extern_type*& __to_next)
const;
00428
00429
virtual result
00430 do_in(state_type& __state,
00431
const extern_type* __from,
const extern_type* __from_end,
00432
const extern_type*& __from_next,
00433 intern_type* __to, intern_type* __to_end,
00434 intern_type*& __to_next)
const;
00435
00436
virtual
00437
int do_encoding() const throw();
00438
00439 virtual
00440
bool do_always_noconv() const throw();
00441
00442 virtual
00443
int do_length(state_type&, const extern_type* __from,
00444 const extern_type* __end, size_t __max) const;
00445
00446 virtual
int
00447 do_max_length() const throw();
00448 };
00449 #endif
00450
00451
00452 template<typename _InternT, typename _ExternT, typename _StateT>
00453 class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT>
00454 {
00455
public:
00456
explicit
00457 codecvt_byname(
const char* __s, size_t __refs = 0)
00458 : codecvt<_InternT, _ExternT, _StateT>(__refs)
00459 {
00460
if (std::strcmp(__s,
"C") != 0 && std::strcmp(__s,
"POSIX") != 0)
00461 {
00462 this->_S_destroy_c_locale(this->_M_c_locale_codecvt);
00463 this->_S_create_c_locale(this->_M_c_locale_codecvt, __s);
00464 }
00465 }
00466
00467
protected:
00468
virtual
00469 ~codecvt_byname() { }
00470 };
00471
00472
00473
00474
#ifdef _GLIBCXX_USE_WCHAR_T
00475
#include <bits/codecvt_specializations.h>
00476
#endif
00477
00478
#endif // _CODECVT_H