codekingpro/portable-devtools
114k
1// -*- C++ -*-2//===-------------------------- codecvt -----------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX_CODECVT11#define _LIBCUDACXX_CODECVT12 13/*14 codecvt synopsis15 16namespace std17{18 19enum codecvt_mode20{21 consume_header = 4,22 generate_header = 2,23 little_endian = 124};25 26template <class Elem, unsigned long Maxcode = 0x10ffff,27 codecvt_mode Mode = (codecvt_mode)0>28class codecvt_utf829 : public codecvt<Elem, char, mbstate_t>30{31 explicit codecvt_utf8(size_t refs = 0);32 ~codecvt_utf8();33};34 35template <class Elem, unsigned long Maxcode = 0x10ffff,36 codecvt_mode Mode = (codecvt_mode)0>37class codecvt_utf1638 : public codecvt<Elem, char, mbstate_t>39{40 explicit codecvt_utf16(size_t refs = 0);41 ~codecvt_utf16();42};43 44template <class Elem, unsigned long Maxcode = 0x10ffff,45 codecvt_mode Mode = (codecvt_mode)0>46class codecvt_utf8_utf1647 : public codecvt<Elem, char, mbstate_t>48{49 explicit codecvt_utf8_utf16(size_t refs = 0);50 ~codecvt_utf8_utf16();51};52 53} // std54 55*/56 57#include <__config>58#include <__locale>59 60#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)61# pragma GCC system_header62#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)63# pragma clang system_header64#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)65# pragma system_header66#endif // no system header67 68_LIBCUDACXX_BEGIN_NAMESPACE_STD69 70enum codecvt_mode71{72 consume_header = 4,73 generate_header = 2,74 little_endian = 175};76 77// codecvt_utf878 79template <class _Elem> class __codecvt_utf8;80 81template <>82class _LIBCUDACXX_TYPE_VIS __codecvt_utf8<wchar_t>83 : public codecvt<wchar_t, char, mbstate_t>84{85 unsigned long _Maxcode_;86 codecvt_mode _Mode_;87public:88 typedef wchar_t intern_type;89 typedef char extern_type;90 typedef mbstate_t state_type;91 92 _LIBCUDACXX_INLINE_VISIBILITY93 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,94 codecvt_mode _Mode)95 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),96 _Mode_(_Mode) {}97protected:98 virtual result99 do_out(state_type& __st,100 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,101 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;102 virtual result103 do_in(state_type& __st,104 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,105 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;106 virtual result107 do_unshift(state_type& __st,108 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;109 virtual int do_encoding() const throw();110 virtual bool do_always_noconv() const throw();111 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,112 size_t __mx) const;113 virtual int do_max_length() const throw();114};115 116template <>117class _LIBCUDACXX_TYPE_VIS __codecvt_utf8<char16_t>118 : public codecvt<char16_t, char, mbstate_t>119{120 unsigned long _Maxcode_;121 codecvt_mode _Mode_;122public:123 typedef char16_t intern_type;124 typedef char extern_type;125 typedef mbstate_t state_type;126 127 _LIBCUDACXX_INLINE_VISIBILITY128 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,129 codecvt_mode _Mode)130 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),131 _Mode_(_Mode) {}132protected:133 virtual result134 do_out(state_type& __st,135 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,136 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;137 virtual result138 do_in(state_type& __st,139 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,140 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;141 virtual result142 do_unshift(state_type& __st,143 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;144 virtual int do_encoding() const throw();145 virtual bool do_always_noconv() const throw();146 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,147 size_t __mx) const;148 virtual int do_max_length() const throw();149};150 151template <>152class _LIBCUDACXX_TYPE_VIS __codecvt_utf8<char32_t>153 : public codecvt<char32_t, char, mbstate_t>154{155 unsigned long _Maxcode_;156 codecvt_mode _Mode_;157public:158 typedef char32_t intern_type;159 typedef char extern_type;160 typedef mbstate_t state_type;161 162 _LIBCUDACXX_INLINE_VISIBILITY163 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,164 codecvt_mode _Mode)165 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),166 _Mode_(_Mode) {}167protected:168 virtual result169 do_out(state_type& __st,170 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,171 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;172 virtual result173 do_in(state_type& __st,174 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,175 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;176 virtual result177 do_unshift(state_type& __st,178 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;179 virtual int do_encoding() const throw();180 virtual bool do_always_noconv() const throw();181 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,182 size_t __mx) const;183 virtual int do_max_length() const throw();184};185 186template <class _Elem, unsigned long _Maxcode = 0x10ffff,187 codecvt_mode _Mode = (codecvt_mode)0>188class _LIBCUDACXX_TEMPLATE_VIS codecvt_utf8189 : public __codecvt_utf8<_Elem>190{191public:192 _LIBCUDACXX_INLINE_VISIBILITY193 explicit codecvt_utf8(size_t __refs = 0)194 : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {}195 196 _LIBCUDACXX_INLINE_VISIBILITY197 ~codecvt_utf8() {}198};199 200// codecvt_utf16201 202template <class _Elem, bool _LittleEndian> class __codecvt_utf16;203 204template <>205class _LIBCUDACXX_TYPE_VIS __codecvt_utf16<wchar_t, false>206 : public codecvt<wchar_t, char, mbstate_t>207{208 unsigned long _Maxcode_;209 codecvt_mode _Mode_;210public:211 typedef wchar_t intern_type;212 typedef char extern_type;213 typedef mbstate_t state_type;214 215 _LIBCUDACXX_INLINE_VISIBILITY216 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,217 codecvt_mode _Mode)218 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),219 _Mode_(_Mode) {}220protected:221 virtual result222 do_out(state_type& __st,223 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,224 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;225 virtual result226 do_in(state_type& __st,227 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,228 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;229 virtual result230 do_unshift(state_type& __st,231 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;232 virtual int do_encoding() const throw();233 virtual bool do_always_noconv() const throw();234 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,235 size_t __mx) const;236 virtual int do_max_length() const throw();237};238 239template <>240class _LIBCUDACXX_TYPE_VIS __codecvt_utf16<wchar_t, true>241 : public codecvt<wchar_t, char, mbstate_t>242{243 unsigned long _Maxcode_;244 codecvt_mode _Mode_;245public:246 typedef wchar_t intern_type;247 typedef char extern_type;248 typedef mbstate_t state_type;249 250 _LIBCUDACXX_INLINE_VISIBILITY251 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,252 codecvt_mode _Mode)253 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),254 _Mode_(_Mode) {}255protected:256 virtual result257 do_out(state_type& __st,258 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,259 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;260 virtual result261 do_in(state_type& __st,262 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,263 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;264 virtual result265 do_unshift(state_type& __st,266 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;267 virtual int do_encoding() const throw();268 virtual bool do_always_noconv() const throw();269 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,270 size_t __mx) const;271 virtual int do_max_length() const throw();272};273 274template <>275class _LIBCUDACXX_TYPE_VIS __codecvt_utf16<char16_t, false>276 : public codecvt<char16_t, char, mbstate_t>277{278 unsigned long _Maxcode_;279 codecvt_mode _Mode_;280public:281 typedef char16_t intern_type;282 typedef char extern_type;283 typedef mbstate_t state_type;284 285 _LIBCUDACXX_INLINE_VISIBILITY286 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,287 codecvt_mode _Mode)288 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),289 _Mode_(_Mode) {}290protected:291 virtual result292 do_out(state_type& __st,293 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,294 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;295 virtual result296 do_in(state_type& __st,297 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,298 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;299 virtual result300 do_unshift(state_type& __st,301 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;302 virtual int do_encoding() const throw();303 virtual bool do_always_noconv() const throw();304 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,305 size_t __mx) const;306 virtual int do_max_length() const throw();307};308 309template <>310class _LIBCUDACXX_TYPE_VIS __codecvt_utf16<char16_t, true>311 : public codecvt<char16_t, char, mbstate_t>312{313 unsigned long _Maxcode_;314 codecvt_mode _Mode_;315public:316 typedef char16_t intern_type;317 typedef char extern_type;318 typedef mbstate_t state_type;319 320 _LIBCUDACXX_INLINE_VISIBILITY321 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,322 codecvt_mode _Mode)323 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),324 _Mode_(_Mode) {}325protected:326 virtual result327 do_out(state_type& __st,328 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,329 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;330 virtual result331 do_in(state_type& __st,332 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,333 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;334 virtual result335 do_unshift(state_type& __st,336 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;337 virtual int do_encoding() const throw();338 virtual bool do_always_noconv() const throw();339 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,340 size_t __mx) const;341 virtual int do_max_length() const throw();342};343 344template <>345class _LIBCUDACXX_TYPE_VIS __codecvt_utf16<char32_t, false>346 : public codecvt<char32_t, char, mbstate_t>347{348 unsigned long _Maxcode_;349 codecvt_mode _Mode_;350public:351 typedef char32_t intern_type;352 typedef char extern_type;353 typedef mbstate_t state_type;354 355 _LIBCUDACXX_INLINE_VISIBILITY356 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,357 codecvt_mode _Mode)358 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),359 _Mode_(_Mode) {}360protected:361 virtual result362 do_out(state_type& __st,363 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,364 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;365 virtual result366 do_in(state_type& __st,367 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,368 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;369 virtual result370 do_unshift(state_type& __st,371 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;372 virtual int do_encoding() const throw();373 virtual bool do_always_noconv() const throw();374 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,375 size_t __mx) const;376 virtual int do_max_length() const throw();377};378 379template <>380class _LIBCUDACXX_TYPE_VIS __codecvt_utf16<char32_t, true>381 : public codecvt<char32_t, char, mbstate_t>382{383 unsigned long _Maxcode_;384 codecvt_mode _Mode_;385public:386 typedef char32_t intern_type;387 typedef char extern_type;388 typedef mbstate_t state_type;389 390 _LIBCUDACXX_INLINE_VISIBILITY391 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,392 codecvt_mode _Mode)393 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),394 _Mode_(_Mode) {}395protected:396 virtual result397 do_out(state_type& __st,398 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,399 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;400 virtual result401 do_in(state_type& __st,402 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,403 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;404 virtual result405 do_unshift(state_type& __st,406 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;407 virtual int do_encoding() const throw();408 virtual bool do_always_noconv() const throw();409 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,410 size_t __mx) const;411 virtual int do_max_length() const throw();412};413 414template <class _Elem, unsigned long _Maxcode = 0x10ffff,415 codecvt_mode _Mode = (codecvt_mode)0>416class _LIBCUDACXX_TEMPLATE_VIS codecvt_utf16417 : public __codecvt_utf16<_Elem, _Mode & little_endian>418{419public:420 _LIBCUDACXX_INLINE_VISIBILITY421 explicit codecvt_utf16(size_t __refs = 0)422 : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {}423 424 _LIBCUDACXX_INLINE_VISIBILITY425 ~codecvt_utf16() {}426};427 428// codecvt_utf8_utf16429 430template <class _Elem> class __codecvt_utf8_utf16;431 432template <>433class _LIBCUDACXX_TYPE_VIS __codecvt_utf8_utf16<wchar_t>434 : public codecvt<wchar_t, char, mbstate_t>435{436 unsigned long _Maxcode_;437 codecvt_mode _Mode_;438public:439 typedef wchar_t intern_type;440 typedef char extern_type;441 typedef mbstate_t state_type;442 443 _LIBCUDACXX_INLINE_VISIBILITY444 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,445 codecvt_mode _Mode)446 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),447 _Mode_(_Mode) {}448protected:449 virtual result450 do_out(state_type& __st,451 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,452 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;453 virtual result454 do_in(state_type& __st,455 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,456 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;457 virtual result458 do_unshift(state_type& __st,459 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;460 virtual int do_encoding() const throw();461 virtual bool do_always_noconv() const throw();462 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,463 size_t __mx) const;464 virtual int do_max_length() const throw();465};466 467template <>468class _LIBCUDACXX_TYPE_VIS __codecvt_utf8_utf16<char32_t>469 : public codecvt<char32_t, char, mbstate_t>470{471 unsigned long _Maxcode_;472 codecvt_mode _Mode_;473public:474 typedef char32_t intern_type;475 typedef char extern_type;476 typedef mbstate_t state_type;477 478 _LIBCUDACXX_INLINE_VISIBILITY479 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,480 codecvt_mode _Mode)481 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),482 _Mode_(_Mode) {}483protected:484 virtual result485 do_out(state_type& __st,486 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,487 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;488 virtual result489 do_in(state_type& __st,490 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,491 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;492 virtual result493 do_unshift(state_type& __st,494 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;495 virtual int do_encoding() const throw();496 virtual bool do_always_noconv() const throw();497 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,498 size_t __mx) const;499 virtual int do_max_length() const throw();500};501 502template <>503class _LIBCUDACXX_TYPE_VIS __codecvt_utf8_utf16<char16_t>504 : public codecvt<char16_t, char, mbstate_t>505{506 unsigned long _Maxcode_;507 codecvt_mode _Mode_;508public:509 typedef char16_t intern_type;510 typedef char extern_type;511 typedef mbstate_t state_type;512 513 _LIBCUDACXX_INLINE_VISIBILITY514 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,515 codecvt_mode _Mode)516 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),517 _Mode_(_Mode) {}518protected:519 virtual result520 do_out(state_type& __st,521 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,522 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;523 virtual result524 do_in(state_type& __st,525 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,526 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;527 virtual result528 do_unshift(state_type& __st,529 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;530 virtual int do_encoding() const throw();531 virtual bool do_always_noconv() const throw();532 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,533 size_t __mx) const;534 virtual int do_max_length() const throw();535};536 537template <class _Elem, unsigned long _Maxcode = 0x10ffff,538 codecvt_mode _Mode = (codecvt_mode)0>539class _LIBCUDACXX_TEMPLATE_VIS codecvt_utf8_utf16540 : public __codecvt_utf8_utf16<_Elem>541{542public:543 _LIBCUDACXX_INLINE_VISIBILITY544 explicit codecvt_utf8_utf16(size_t __refs = 0)545 : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {}546 547 _LIBCUDACXX_INLINE_VISIBILITY548 ~codecvt_utf8_utf16() {}549};550 551_LIBCUDACXX_END_NAMESPACE_STD552 553#endif // _LIBCUDACXX_CODECVT554 