]>
Commit | Line | Data |
---|---|---|
1d487aca | 1 | // Locale support (codecvt) -*- C++ -*- |
2 | ||
f1717362 | 3 | // Copyright (C) 2000-2016 Free Software Foundation, Inc. |
1d487aca | 4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
6bc9506f | 8 | // Free Software Foundation; either version 3, or (at your option) |
1d487aca | 9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
6bc9506f | 16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
1d487aca | 19 | |
6bc9506f | 20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
1d487aca | 24 | |
944beac5 | 25 | /** @file bits/codecvt.h |
26 | * This is an internal header file, included by other library headers. | |
5846aeac | 27 | * Do not attempt to use it directly. @headername{locale} |
944beac5 | 28 | */ |
29 | ||
1d487aca | 30 | // |
31 | // ISO C++ 14882: 22.2.1.5 Template class codecvt | |
32 | // | |
33 | ||
4d292396 | 34 | // Written by Benjamin Kosnik <bkoz@redhat.com> |
1d487aca | 35 | |
5a64d8cf | 36 | #ifndef _CODECVT_H |
37 | #define _CODECVT_H 1 | |
1d487aca | 38 | |
cd319190 | 39 | #pragma GCC system_header |
40 | ||
2948dd21 | 41 | namespace std _GLIBCXX_VISIBILITY(default) |
42 | { | |
43 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
0e014800 | 44 | |
4a77b438 | 45 | /// Empty base class for codecvt facet [22.2.1.5]. |
1d487aca | 46 | class codecvt_base |
47 | { | |
48 | public: | |
49 | enum result | |
50 | { | |
51 | ok, | |
52 | partial, | |
53 | error, | |
54 | noconv | |
55 | }; | |
56 | }; | |
57 | ||
ed73ad37 | 58 | /** |
81e48263 | 59 | * @brief Common base for codecvt functions. |
ed73ad37 | 60 | * |
61 | * This template class provides implementations of the public functions | |
62 | * that forward to the protected virtual functions. | |
63 | * | |
64 | * This template also provides abstract stubs for the protected virtual | |
65 | * functions. | |
66 | */ | |
1d487aca | 67 | template<typename _InternT, typename _ExternT, typename _StateT> |
bae9b8af | 68 | class __codecvt_abstract_base |
1d487aca | 69 | : public locale::facet, public codecvt_base |
70 | { | |
71 | public: | |
72 | // Types: | |
a314f26a | 73 | typedef codecvt_base::result result; |
bae9b8af | 74 | typedef _InternT intern_type; |
75 | typedef _ExternT extern_type; | |
76 | typedef _StateT state_type; | |
77 | ||
1d487aca | 78 | // 22.2.1.5.1 codecvt members |
ed73ad37 | 79 | /** |
80 | * @brief Convert from internal to external character set. | |
81 | * | |
82 | * Converts input string of intern_type to output string of | |
83 | * extern_type. This is analogous to wcsrtombs. It does this by | |
84 | * calling codecvt::do_out. | |
85 | * | |
86 | * The source and destination character sets are determined by the | |
87 | * facet's locale, internal and external types. | |
88 | * | |
89 | * The characters in [from,from_end) are converted and written to | |
90 | * [to,to_end). from_next and to_next are set to point to the | |
91 | * character following the last successfully converted character, | |
92 | * respectively. If the result needed no conversion, from_next and | |
93 | * to_next are not affected. | |
94 | * | |
9fc1117c | 95 | * The @a state argument should be initialized if the input is at the |
ed73ad37 | 96 | * beginning and carried from a previous call if continuing |
97 | * conversion. There are no guarantees about how @a state is used. | |
98 | * | |
fdc7233f | 99 | * The result returned is a member of codecvt_base::result. If |
100 | * all the input is converted, returns codecvt_base::ok. If no | |
101 | * conversion is necessary, returns codecvt_base::noconv. If | |
102 | * the input ends early or there is insufficient space in the | |
103 | * output, returns codecvt_base::partial. Otherwise the | |
104 | * conversion failed and codecvt_base::error is returned. | |
ed73ad37 | 105 | * |
e12e4f3b | 106 | * @param __state Persistent conversion state data. |
107 | * @param __from Start of input. | |
108 | * @param __from_end End of input. | |
109 | * @param __from_next Returns start of unconverted data. | |
110 | * @param __to Start of output buffer. | |
111 | * @param __to_end End of output buffer. | |
112 | * @param __to_next Returns start of unused output area. | |
ed73ad37 | 113 | * @return codecvt_base::result. |
114 | */ | |
1d487aca | 115 | result |
bae9b8af | 116 | out(state_type& __state, const intern_type* __from, |
1d487aca | 117 | const intern_type* __from_end, const intern_type*& __from_next, |
bae9b8af | 118 | extern_type* __to, extern_type* __to_end, |
1d487aca | 119 | extern_type*& __to_next) const |
bae9b8af | 120 | { |
121 | return this->do_out(__state, __from, __from_end, __from_next, | |
122 | __to, __to_end, __to_next); | |
1d487aca | 123 | } |
124 | ||
ed73ad37 | 125 | /** |
126 | * @brief Reset conversion state. | |
127 | * | |
128 | * Writes characters to output that would restore @a state to initial | |
129 | * conditions. The idea is that if a partial conversion occurs, then | |
130 | * the converting the characters written by this function would leave | |
131 | * the state in initial conditions, rather than partial conversion | |
132 | * state. It does this by calling codecvt::do_unshift(). | |
133 | * | |
134 | * For example, if 4 external characters always converted to 1 internal | |
135 | * character, and input to in() had 6 external characters with state | |
136 | * saved, this function would write two characters to the output and | |
137 | * set the state to initialized conditions. | |
138 | * | |
139 | * The source and destination character sets are determined by the | |
140 | * facet's locale, internal and external types. | |
141 | * | |
142 | * The result returned is a member of codecvt_base::result. If the | |
143 | * state could be reset and data written, returns codecvt_base::ok. If | |
144 | * no conversion is necessary, returns codecvt_base::noconv. If the | |
145 | * output has insufficient space, returns codecvt_base::partial. | |
146 | * Otherwise the reset failed and codecvt_base::error is returned. | |
147 | * | |
e12e4f3b | 148 | * @param __state Persistent conversion state data. |
149 | * @param __to Start of output buffer. | |
150 | * @param __to_end End of output buffer. | |
151 | * @param __to_next Returns start of unused output area. | |
ed73ad37 | 152 | * @return codecvt_base::result. |
153 | */ | |
1d487aca | 154 | result |
155 | unshift(state_type& __state, extern_type* __to, extern_type* __to_end, | |
156 | extern_type*& __to_next) const | |
157 | { return this->do_unshift(__state, __to,__to_end,__to_next); } | |
158 | ||
ed73ad37 | 159 | /** |
160 | * @brief Convert from external to internal character set. | |
161 | * | |
162 | * Converts input string of extern_type to output string of | |
163 | * intern_type. This is analogous to mbsrtowcs. It does this by | |
164 | * calling codecvt::do_in. | |
165 | * | |
166 | * The source and destination character sets are determined by the | |
167 | * facet's locale, internal and external types. | |
168 | * | |
169 | * The characters in [from,from_end) are converted and written to | |
170 | * [to,to_end). from_next and to_next are set to point to the | |
171 | * character following the last successfully converted character, | |
172 | * respectively. If the result needed no conversion, from_next and | |
173 | * to_next are not affected. | |
174 | * | |
9fc1117c | 175 | * The @a state argument should be initialized if the input is at the |
ed73ad37 | 176 | * beginning and carried from a previous call if continuing |
177 | * conversion. There are no guarantees about how @a state is used. | |
178 | * | |
fdc7233f | 179 | * The result returned is a member of codecvt_base::result. If |
180 | * all the input is converted, returns codecvt_base::ok. If no | |
181 | * conversion is necessary, returns codecvt_base::noconv. If | |
182 | * the input ends early or there is insufficient space in the | |
183 | * output, returns codecvt_base::partial. Otherwise the | |
184 | * conversion failed and codecvt_base::error is returned. | |
ed73ad37 | 185 | * |
e12e4f3b | 186 | * @param __state Persistent conversion state data. |
187 | * @param __from Start of input. | |
188 | * @param __from_end End of input. | |
189 | * @param __from_next Returns start of unconverted data. | |
190 | * @param __to Start of output buffer. | |
191 | * @param __to_end End of output buffer. | |
192 | * @param __to_next Returns start of unused output area. | |
ed73ad37 | 193 | * @return codecvt_base::result. |
194 | */ | |
1d487aca | 195 | result |
bae9b8af | 196 | in(state_type& __state, const extern_type* __from, |
1d487aca | 197 | const extern_type* __from_end, const extern_type*& __from_next, |
bae9b8af | 198 | intern_type* __to, intern_type* __to_end, |
1d487aca | 199 | intern_type*& __to_next) const |
bae9b8af | 200 | { |
1d487aca | 201 | return this->do_in(__state, __from, __from_end, __from_next, |
bae9b8af | 202 | __to, __to_end, __to_next); |
1d487aca | 203 | } |
204 | ||
bae9b8af | 205 | int |
1d487aca | 206 | encoding() const throw() |
207 | { return this->do_encoding(); } | |
208 | ||
bae9b8af | 209 | bool |
1d487aca | 210 | always_noconv() const throw() |
211 | { return this->do_always_noconv(); } | |
212 | ||
213 | int | |
4229b2e4 | 214 | length(state_type& __state, const extern_type* __from, |
1d487aca | 215 | const extern_type* __end, size_t __max) const |
216 | { return this->do_length(__state, __from, __end, __max); } | |
217 | ||
bae9b8af | 218 | int |
1d487aca | 219 | max_length() const throw() |
220 | { return this->do_max_length(); } | |
221 | ||
222 | protected: | |
bae9b8af | 223 | explicit |
1d487aca | 224 | __codecvt_abstract_base(size_t __refs = 0) : locale::facet(__refs) { } |
225 | ||
bae9b8af | 226 | virtual |
1d487aca | 227 | ~__codecvt_abstract_base() { } |
228 | ||
ed73ad37 | 229 | /** |
230 | * @brief Convert from internal to external character set. | |
231 | * | |
232 | * Converts input string of intern_type to output string of | |
233 | * extern_type. This function is a hook for derived classes to change | |
234 | * the value returned. @see out for more information. | |
235 | */ | |
1d487aca | 236 | virtual result |
bae9b8af | 237 | do_out(state_type& __state, const intern_type* __from, |
1d487aca | 238 | const intern_type* __from_end, const intern_type*& __from_next, |
239 | extern_type* __to, extern_type* __to_end, | |
240 | extern_type*& __to_next) const = 0; | |
241 | ||
242 | virtual result | |
bae9b8af | 243 | do_unshift(state_type& __state, extern_type* __to, |
1d487aca | 244 | extern_type* __to_end, extern_type*& __to_next) const = 0; |
bae9b8af | 245 | |
1d487aca | 246 | virtual result |
bae9b8af | 247 | do_in(state_type& __state, const extern_type* __from, |
248 | const extern_type* __from_end, const extern_type*& __from_next, | |
249 | intern_type* __to, intern_type* __to_end, | |
1d487aca | 250 | intern_type*& __to_next) const = 0; |
bae9b8af | 251 | |
252 | virtual int | |
1d487aca | 253 | do_encoding() const throw() = 0; |
254 | ||
bae9b8af | 255 | virtual bool |
1d487aca | 256 | do_always_noconv() const throw() = 0; |
257 | ||
bae9b8af | 258 | virtual int |
259 | do_length(state_type&, const extern_type* __from, | |
1d487aca | 260 | const extern_type* __end, size_t __max) const = 0; |
261 | ||
bae9b8af | 262 | virtual int |
1d487aca | 263 | do_max_length() const throw() = 0; |
264 | }; | |
265 | ||
add48425 | 266 | /** |
267 | * @brief Primary class template codecvt. | |
268 | * @ingroup locales | |
269 | * | |
270 | * NB: Generic, mostly useless implementation. | |
271 | * | |
272 | */ | |
273 | template<typename _InternT, typename _ExternT, typename _StateT> | |
bae9b8af | 274 | class codecvt |
1d487aca | 275 | : public __codecvt_abstract_base<_InternT, _ExternT, _StateT> |
276 | { | |
bae9b8af | 277 | public: |
1d487aca | 278 | // Types: |
a314f26a | 279 | typedef codecvt_base::result result; |
bae9b8af | 280 | typedef _InternT intern_type; |
281 | typedef _ExternT extern_type; | |
282 | typedef _StateT state_type; | |
1d487aca | 283 | |
a314f26a | 284 | protected: |
285 | __c_locale _M_c_locale_codecvt; | |
286 | ||
287 | public: | |
bae9b8af | 288 | static locale::id id; |
1d487aca | 289 | |
bae9b8af | 290 | explicit |
291 | codecvt(size_t __refs = 0) | |
565587b9 | 292 | : __codecvt_abstract_base<_InternT, _ExternT, _StateT> (__refs), |
293 | _M_c_locale_codecvt(0) | |
294 | { } | |
a314f26a | 295 | |
bae9b8af | 296 | explicit |
a314f26a | 297 | codecvt(__c_locale __cloc, size_t __refs = 0); |
1d487aca | 298 | |
299 | protected: | |
bae9b8af | 300 | virtual |
1d487aca | 301 | ~codecvt() { } |
a7ecd4b4 | 302 | |
303 | virtual result | |
bae9b8af | 304 | do_out(state_type& __state, const intern_type* __from, |
a7ecd4b4 | 305 | const intern_type* __from_end, const intern_type*& __from_next, |
306 | extern_type* __to, extern_type* __to_end, | |
307 | extern_type*& __to_next) const; | |
308 | ||
309 | virtual result | |
bae9b8af | 310 | do_unshift(state_type& __state, extern_type* __to, |
a7ecd4b4 | 311 | extern_type* __to_end, extern_type*& __to_next) const; |
bae9b8af | 312 | |
a7ecd4b4 | 313 | virtual result |
bae9b8af | 314 | do_in(state_type& __state, const extern_type* __from, |
315 | const extern_type* __from_end, const extern_type*& __from_next, | |
316 | intern_type* __to, intern_type* __to_end, | |
a7ecd4b4 | 317 | intern_type*& __to_next) const; |
bae9b8af | 318 | |
319 | virtual int | |
a7ecd4b4 | 320 | do_encoding() const throw(); |
321 | ||
bae9b8af | 322 | virtual bool |
a7ecd4b4 | 323 | do_always_noconv() const throw(); |
324 | ||
bae9b8af | 325 | virtual int |
326 | do_length(state_type&, const extern_type* __from, | |
a7ecd4b4 | 327 | const extern_type* __end, size_t __max) const; |
328 | ||
bae9b8af | 329 | virtual int |
a7ecd4b4 | 330 | do_max_length() const throw(); |
1d487aca | 331 | }; |
332 | ||
333 | template<typename _InternT, typename _ExternT, typename _StateT> | |
334 | locale::id codecvt<_InternT, _ExternT, _StateT>::id; | |
335 | ||
4a77b438 | 336 | /// class codecvt<char, char, mbstate_t> specialization. |
1d487aca | 337 | template<> |
bae9b8af | 338 | class codecvt<char, char, mbstate_t> |
1d487aca | 339 | : public __codecvt_abstract_base<char, char, mbstate_t> |
340 | { | |
a6766bdf | 341 | friend class messages<char>; |
342 | ||
bae9b8af | 343 | public: |
1d487aca | 344 | // Types: |
bae9b8af | 345 | typedef char intern_type; |
346 | typedef char extern_type; | |
347 | typedef mbstate_t state_type; | |
a314f26a | 348 | |
349 | protected: | |
350 | __c_locale _M_c_locale_codecvt; | |
1d487aca | 351 | |
a314f26a | 352 | public: |
1d487aca | 353 | static locale::id id; |
354 | ||
bae9b8af | 355 | explicit |
1d487aca | 356 | codecvt(size_t __refs = 0); |
357 | ||
bae9b8af | 358 | explicit |
a314f26a | 359 | codecvt(__c_locale __cloc, size_t __refs = 0); |
1bd80d36 | 360 | |
1d487aca | 361 | protected: |
bae9b8af | 362 | virtual |
1d487aca | 363 | ~codecvt(); |
364 | ||
365 | virtual result | |
bae9b8af | 366 | do_out(state_type& __state, const intern_type* __from, |
1d487aca | 367 | const intern_type* __from_end, const intern_type*& __from_next, |
368 | extern_type* __to, extern_type* __to_end, | |
369 | extern_type*& __to_next) const; | |
370 | ||
371 | virtual result | |
bae9b8af | 372 | do_unshift(state_type& __state, extern_type* __to, |
1d487aca | 373 | extern_type* __to_end, extern_type*& __to_next) const; |
374 | ||
375 | virtual result | |
bae9b8af | 376 | do_in(state_type& __state, const extern_type* __from, |
1d487aca | 377 | const extern_type* __from_end, const extern_type*& __from_next, |
bae9b8af | 378 | intern_type* __to, intern_type* __to_end, |
1d487aca | 379 | intern_type*& __to_next) const; |
380 | ||
bae9b8af | 381 | virtual int |
1d487aca | 382 | do_encoding() const throw(); |
383 | ||
bae9b8af | 384 | virtual bool |
1d487aca | 385 | do_always_noconv() const throw(); |
386 | ||
bae9b8af | 387 | virtual int |
388 | do_length(state_type&, const extern_type* __from, | |
1d487aca | 389 | const extern_type* __end, size_t __max) const; |
390 | ||
bae9b8af | 391 | virtual int |
1d487aca | 392 | do_max_length() const throw(); |
393 | }; | |
394 | ||
5a64d8cf | 395 | #ifdef _GLIBCXX_USE_WCHAR_T |
5c67f184 | 396 | /** @brief Class codecvt<wchar_t, char, mbstate_t> specialization. |
397 | * | |
398 | * Converts between narrow and wide characters in the native character set | |
399 | */ | |
1d487aca | 400 | template<> |
bae9b8af | 401 | class codecvt<wchar_t, char, mbstate_t> |
1d487aca | 402 | : public __codecvt_abstract_base<wchar_t, char, mbstate_t> |
403 | { | |
a6766bdf | 404 | friend class messages<wchar_t>; |
405 | ||
1d487aca | 406 | public: |
407 | // Types: | |
bae9b8af | 408 | typedef wchar_t intern_type; |
409 | typedef char extern_type; | |
410 | typedef mbstate_t state_type; | |
1d487aca | 411 | |
a314f26a | 412 | protected: |
413 | __c_locale _M_c_locale_codecvt; | |
414 | ||
415 | public: | |
bae9b8af | 416 | static locale::id id; |
1d487aca | 417 | |
bae9b8af | 418 | explicit |
1d487aca | 419 | codecvt(size_t __refs = 0); |
420 | ||
bae9b8af | 421 | explicit |
1bd80d36 | 422 | codecvt(__c_locale __cloc, size_t __refs = 0); |
423 | ||
1d487aca | 424 | protected: |
bae9b8af | 425 | virtual |
1d487aca | 426 | ~codecvt(); |
427 | ||
428 | virtual result | |
bae9b8af | 429 | do_out(state_type& __state, const intern_type* __from, |
1d487aca | 430 | const intern_type* __from_end, const intern_type*& __from_next, |
431 | extern_type* __to, extern_type* __to_end, | |
432 | extern_type*& __to_next) const; | |
433 | ||
434 | virtual result | |
435 | do_unshift(state_type& __state, | |
436 | extern_type* __to, extern_type* __to_end, | |
437 | extern_type*& __to_next) const; | |
438 | ||
439 | virtual result | |
440 | do_in(state_type& __state, | |
441 | const extern_type* __from, const extern_type* __from_end, | |
442 | const extern_type*& __from_next, | |
443 | intern_type* __to, intern_type* __to_end, | |
444 | intern_type*& __to_next) const; | |
445 | ||
bae9b8af | 446 | virtual |
1d487aca | 447 | int do_encoding() const throw(); |
448 | ||
bae9b8af | 449 | virtual |
1d487aca | 450 | bool do_always_noconv() const throw(); |
451 | ||
bae9b8af | 452 | virtual |
4229b2e4 | 453 | int do_length(state_type&, const extern_type* __from, |
1d487aca | 454 | const extern_type* __end, size_t __max) const; |
455 | ||
bae9b8af | 456 | virtual int |
1d487aca | 457 | do_max_length() const throw(); |
458 | }; | |
5a64d8cf | 459 | #endif //_GLIBCXX_USE_WCHAR_T |
1d487aca | 460 | |
5c67f184 | 461 | #if __cplusplus >= 201103L |
462 | #ifdef _GLIBCXX_USE_C99_STDINT_TR1 | |
463 | /** @brief Class codecvt<char16_t, char, mbstate_t> specialization. | |
464 | * | |
465 | * Converts between UTF-16 and UTF-8. | |
466 | */ | |
467 | template<> | |
468 | class codecvt<char16_t, char, mbstate_t> | |
469 | : public __codecvt_abstract_base<char16_t, char, mbstate_t> | |
470 | { | |
471 | public: | |
472 | // Types: | |
473 | typedef char16_t intern_type; | |
474 | typedef char extern_type; | |
475 | typedef mbstate_t state_type; | |
476 | ||
477 | public: | |
478 | static locale::id id; | |
479 | ||
480 | explicit | |
481 | codecvt(size_t __refs = 0) | |
482 | : __codecvt_abstract_base<char16_t, char, mbstate_t>(__refs) { } | |
483 | ||
484 | protected: | |
485 | virtual | |
486 | ~codecvt(); | |
487 | ||
488 | virtual result | |
489 | do_out(state_type& __state, const intern_type* __from, | |
490 | const intern_type* __from_end, const intern_type*& __from_next, | |
491 | extern_type* __to, extern_type* __to_end, | |
492 | extern_type*& __to_next) const; | |
493 | ||
494 | virtual result | |
495 | do_unshift(state_type& __state, | |
496 | extern_type* __to, extern_type* __to_end, | |
497 | extern_type*& __to_next) const; | |
498 | ||
499 | virtual result | |
500 | do_in(state_type& __state, | |
501 | const extern_type* __from, const extern_type* __from_end, | |
502 | const extern_type*& __from_next, | |
503 | intern_type* __to, intern_type* __to_end, | |
504 | intern_type*& __to_next) const; | |
505 | ||
506 | virtual | |
507 | int do_encoding() const throw(); | |
508 | ||
509 | virtual | |
510 | bool do_always_noconv() const throw(); | |
511 | ||
512 | virtual | |
513 | int do_length(state_type&, const extern_type* __from, | |
514 | const extern_type* __end, size_t __max) const; | |
515 | ||
516 | virtual int | |
517 | do_max_length() const throw(); | |
518 | }; | |
519 | ||
520 | /** @brief Class codecvt<char32_t, char, mbstate_t> specialization. | |
521 | * | |
522 | * Converts between UTF-32 and UTF-8. | |
523 | */ | |
524 | template<> | |
525 | class codecvt<char32_t, char, mbstate_t> | |
526 | : public __codecvt_abstract_base<char32_t, char, mbstate_t> | |
527 | { | |
528 | public: | |
529 | // Types: | |
530 | typedef char32_t intern_type; | |
531 | typedef char extern_type; | |
532 | typedef mbstate_t state_type; | |
533 | ||
534 | public: | |
535 | static locale::id id; | |
536 | ||
537 | explicit | |
538 | codecvt(size_t __refs = 0) | |
539 | : __codecvt_abstract_base<char32_t, char, mbstate_t>(__refs) { } | |
540 | ||
541 | protected: | |
542 | virtual | |
543 | ~codecvt(); | |
544 | ||
545 | virtual result | |
546 | do_out(state_type& __state, const intern_type* __from, | |
547 | const intern_type* __from_end, const intern_type*& __from_next, | |
548 | extern_type* __to, extern_type* __to_end, | |
549 | extern_type*& __to_next) const; | |
550 | ||
551 | virtual result | |
552 | do_unshift(state_type& __state, | |
553 | extern_type* __to, extern_type* __to_end, | |
554 | extern_type*& __to_next) const; | |
555 | ||
556 | virtual result | |
557 | do_in(state_type& __state, | |
558 | const extern_type* __from, const extern_type* __from_end, | |
559 | const extern_type*& __from_next, | |
560 | intern_type* __to, intern_type* __to_end, | |
561 | intern_type*& __to_next) const; | |
562 | ||
563 | virtual | |
564 | int do_encoding() const throw(); | |
565 | ||
566 | virtual | |
567 | bool do_always_noconv() const throw(); | |
568 | ||
569 | virtual | |
570 | int do_length(state_type&, const extern_type* __from, | |
571 | const extern_type* __end, size_t __max) const; | |
572 | ||
573 | virtual int | |
574 | do_max_length() const throw(); | |
575 | }; | |
576 | ||
577 | #endif // _GLIBCXX_USE_C99_STDINT_TR1 | |
578 | #endif // C++11 | |
579 | ||
4a77b438 | 580 | /// class codecvt_byname [22.2.1.6]. |
1d487aca | 581 | template<typename _InternT, typename _ExternT, typename _StateT> |
582 | class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> | |
583 | { | |
584 | public: | |
bae9b8af | 585 | explicit |
586 | codecvt_byname(const char* __s, size_t __refs = 0) | |
1bd80d36 | 587 | : codecvt<_InternT, _ExternT, _StateT>(__refs) |
bae9b8af | 588 | { |
c7599825 | 589 | if (__builtin_strcmp(__s, "C") != 0 |
590 | && __builtin_strcmp(__s, "POSIX") != 0) | |
0f902b7d | 591 | { |
4bada8ba | 592 | this->_S_destroy_c_locale(this->_M_c_locale_codecvt); |
593 | this->_S_create_c_locale(this->_M_c_locale_codecvt, __s); | |
0f902b7d | 594 | } |
1bd80d36 | 595 | } |
596 | ||
8507df0a | 597 | #if __cplusplus >= 201103L |
598 | explicit | |
599 | codecvt_byname(const string& __s, size_t __refs = 0) | |
600 | : codecvt_byname(__s.c_str(), __refs) { } | |
601 | #endif | |
602 | ||
603 | protected: | |
604 | virtual | |
605 | ~codecvt_byname() { } | |
606 | }; | |
607 | ||
608 | #if __cplusplus >= 201103L && defined(_GLIBCXX_USE_C99_STDINT_TR1) | |
609 | template<> | |
610 | class codecvt_byname<char16_t, char, mbstate_t> | |
611 | : public codecvt<char16_t, char, mbstate_t> | |
612 | { | |
613 | public: | |
614 | explicit | |
615 | codecvt_byname(const char* __s, size_t __refs = 0) | |
616 | : codecvt<char16_t, char, mbstate_t>(__refs) { } | |
617 | ||
618 | explicit | |
619 | codecvt_byname(const string& __s, size_t __refs = 0) | |
620 | : codecvt_byname(__s.c_str(), __refs) { } | |
621 | ||
1d487aca | 622 | protected: |
bae9b8af | 623 | virtual |
1d487aca | 624 | ~codecvt_byname() { } |
625 | }; | |
1d487aca | 626 | |
8507df0a | 627 | template<> |
628 | class codecvt_byname<char32_t, char, mbstate_t> | |
629 | : public codecvt<char32_t, char, mbstate_t> | |
630 | { | |
631 | public: | |
632 | explicit | |
633 | codecvt_byname(const char* __s, size_t __refs = 0) | |
634 | : codecvt<char32_t, char, mbstate_t>(__refs) { } | |
635 | ||
636 | explicit | |
637 | codecvt_byname(const string& __s, size_t __refs = 0) | |
638 | : codecvt_byname(__s.c_str(), __refs) { } | |
639 | ||
640 | protected: | |
641 | virtual | |
642 | ~codecvt_byname() { } | |
643 | }; | |
644 | #endif | |
645 | ||
022ea294 | 646 | // Inhibit implicit instantiations for required instantiations, |
647 | // which are defined via explicit instantiations elsewhere. | |
022ea294 | 648 | #if _GLIBCXX_EXTERN_TEMPLATE |
649 | extern template class codecvt_byname<char, char, mbstate_t>; | |
650 | ||
651 | extern template | |
652 | const codecvt<char, char, mbstate_t>& | |
653 | use_facet<codecvt<char, char, mbstate_t> >(const locale&); | |
654 | ||
655 | extern template | |
656 | bool | |
657 | has_facet<codecvt<char, char, mbstate_t> >(const locale&); | |
658 | ||
659 | #ifdef _GLIBCXX_USE_WCHAR_T | |
660 | extern template class codecvt_byname<wchar_t, char, mbstate_t>; | |
661 | ||
662 | extern template | |
663 | const codecvt<wchar_t, char, mbstate_t>& | |
664 | use_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&); | |
665 | ||
666 | extern template | |
667 | bool | |
668 | has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&); | |
669 | #endif | |
8507df0a | 670 | |
671 | #if __cplusplus >= 201103L && defined(_GLIBCXX_USE_C99_STDINT_TR1) | |
672 | extern template class codecvt_byname<char16_t, char, mbstate_t>; | |
673 | extern template class codecvt_byname<char32_t, char, mbstate_t>; | |
674 | #endif | |
675 | ||
022ea294 | 676 | #endif |
677 | ||
2948dd21 | 678 | _GLIBCXX_END_NAMESPACE_VERSION |
cb38c7e0 | 679 | } // namespace std |
0e014800 | 680 | |
5a64d8cf | 681 | #endif // _CODECVT_H |