Index: libcxx/include/codecvt =================================================================== --- libcxx/include/codecvt +++ libcxx/include/codecvt @@ -73,9 +73,10 @@ // codecvt_utf8 template class __codecvt_utf8; +template class __codecvt_utf8_imp; template <> -class _LIBCPP_TYPE_VIS __codecvt_utf8 +class _LIBCPP_TYPE_VIS __codecvt_utf8_imp : public codecvt { unsigned long _Maxcode_; @@ -86,7 +87,42 @@ typedef mbstate_t state_type; _LIBCPP_INLINE_VISIBILITY - explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, + explicit __codecvt_utf8_imp(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf8_imp + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf8_imp(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) {} @@ -110,6 +146,19 @@ }; _LIBCPP_SUPPRESS_DEPRECATED_PUSH +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf8 + : public __codecvt_utf8_imp +{ +public: + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) + : __codecvt_utf8_imp(__refs, _Maxcode, _Mode) {} + + _LIBCPP_INLINE_VISIBILITY + ~__codecvt_utf8() {} +}; + template <> class _LIBCPP_TYPE_VIS __codecvt_utf8 : public codecvt @@ -202,9 +251,10 @@ // codecvt_utf16 template class __codecvt_utf16; +template class __codecvt_utf16_imp; template <> -class _LIBCPP_TYPE_VIS __codecvt_utf16 +class _LIBCPP_TYPE_VIS __codecvt_utf16_imp : public codecvt { unsigned long _Maxcode_; @@ -215,7 +265,7 @@ typedef mbstate_t state_type; _LIBCPP_INLINE_VISIBILITY - explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + explicit __codecvt_utf16_imp(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) {} @@ -239,7 +289,7 @@ }; template <> -class _LIBCPP_TYPE_VIS __codecvt_utf16 +class _LIBCPP_TYPE_VIS __codecvt_utf16_imp : public codecvt { unsigned long _Maxcode_; @@ -250,7 +300,77 @@ typedef mbstate_t state_type; _LIBCPP_INLINE_VISIBILITY - explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + explicit __codecvt_utf16_imp(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf16_imp + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf16_imp(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf16_imp + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf16_imp(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) {} @@ -274,6 +394,36 @@ }; _LIBCPP_SUPPRESS_DEPRECATED_PUSH +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf16 + : public __codecvt_utf16_imp +{ +public: + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode + _Mode) + : __codecvt_utf16_imp(__refs, _Maxcode, _Mode) + {} + + _LIBCPP_INLINE_VISIBILITY + ~__codecvt_utf16() {} +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf16 + : public __codecvt_utf16_imp +{ +public: + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode + _Mode) + : __codecvt_utf16_imp(__refs, _Maxcode, _Mode) + {} + + _LIBCPP_INLINE_VISIBILITY + ~__codecvt_utf16() {} +}; + template <> class _LIBCPP_TYPE_VIS __codecvt_utf16 : public codecvt @@ -442,9 +592,10 @@ // codecvt_utf8_utf16 template class __codecvt_utf8_utf16; +template class __codecvt_utf8_utf16_imp; template <> -class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16 +class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16_imp : public codecvt { unsigned long _Maxcode_; @@ -455,7 +606,42 @@ typedef mbstate_t state_type; _LIBCPP_INLINE_VISIBILITY - explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, + explicit __codecvt_utf8_utf16_imp(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16_imp + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf8_utf16_imp(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) {} @@ -479,6 +665,19 @@ }; _LIBCPP_SUPPRESS_DEPRECATED_PUSH +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16 + : public __codecvt_utf8_utf16_imp +{ +public: + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) + : __codecvt_utf8_utf16_imp(__refs, _Maxcode, _Mode) {} + + _LIBCPP_INLINE_VISIBILITY + ~__codecvt_utf8_utf16() {} +}; + template <> class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16 : public codecvt Index: libcxx/src/locale.cpp =================================================================== --- libcxx/src/locale.cpp +++ libcxx/src/locale.cpp @@ -3434,65 +3434,121 @@ #endif -// __codecvt_utf8 +// __codecvt_utf8_imp -__codecvt_utf8::result -__codecvt_utf8::do_out(state_type&, +__codecvt_utf8_imp::result +__codecvt_utf8_imp::do_out(state_type&, const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt, extern_type* to, extern_type* to_end, extern_type*& to_nxt) const { -#if defined(_LIBCPP_SHORT_WCHAR) const uint16_t* _frm = reinterpret_cast(frm); const uint16_t* _frm_end = reinterpret_cast(frm_end); const uint16_t* _frm_nxt = _frm; -#else - const uint32_t* _frm = reinterpret_cast(frm); - const uint32_t* _frm_end = reinterpret_cast(frm_end); - const uint32_t* _frm_nxt = _frm; -#endif uint8_t* _to = reinterpret_cast(to); uint8_t* _to_end = reinterpret_cast(to_end); uint8_t* _to_nxt = _to; -#if defined(_LIBCPP_SHORT_WCHAR) result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, _Maxcode_, _Mode_); -#else - result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, - _Maxcode_, _Mode_); -#endif frm_nxt = frm + (_frm_nxt - _frm); to_nxt = to + (_to_nxt - _to); return r; } -__codecvt_utf8::result -__codecvt_utf8::do_in(state_type&, +__codecvt_utf8_imp::result +__codecvt_utf8_imp::do_in(state_type&, const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt, intern_type* to, intern_type* to_end, intern_type*& to_nxt) const { const uint8_t* _frm = reinterpret_cast(frm); const uint8_t* _frm_end = reinterpret_cast(frm_end); const uint8_t* _frm_nxt = _frm; -#if defined(_LIBCPP_SHORT_WCHAR) uint16_t* _to = reinterpret_cast(to); uint16_t* _to_end = reinterpret_cast(to_end); uint16_t* _to_nxt = _to; result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, _Maxcode_, _Mode_); -#else + frm_nxt = frm + (_frm_nxt - _frm); + to_nxt = to + (_to_nxt - _to); + return r; +} + +__codecvt_utf8_imp::result +__codecvt_utf8_imp::do_unshift(state_type&, + extern_type* to, extern_type*, extern_type*& to_nxt) const +{ + to_nxt = to; + return noconv; +} + +int +__codecvt_utf8_imp::do_encoding() const noexcept +{ + return 0; +} + +bool +__codecvt_utf8_imp::do_always_noconv() const noexcept +{ + return false; +} + +int +__codecvt_utf8_imp::do_length(state_type&, + const extern_type* frm, const extern_type* frm_end, size_t mx) const +{ + const uint8_t* _frm = reinterpret_cast(frm); + const uint8_t* _frm_end = reinterpret_cast(frm_end); + return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_); +} + +int +__codecvt_utf8_imp::do_max_length() const noexcept +{ + if (_Mode_ & consume_header) + return 6; + return 3; +} + +// __codecvt_utf8_imp + +__codecvt_utf8_imp::result +__codecvt_utf8_imp::do_out(state_type&, + const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt, + extern_type* to, extern_type* to_end, extern_type*& to_nxt) const +{ + const uint32_t* _frm = reinterpret_cast(frm); + const uint32_t* _frm_end = reinterpret_cast(frm_end); + const uint32_t* _frm_nxt = _frm; + uint8_t* _to = reinterpret_cast(to); + uint8_t* _to_end = reinterpret_cast(to_end); + uint8_t* _to_nxt = _to; + result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, + _Maxcode_, _Mode_); + frm_nxt = frm + (_frm_nxt - _frm); + to_nxt = to + (_to_nxt - _to); + return r; +} + +__codecvt_utf8_imp::result +__codecvt_utf8_imp::do_in(state_type&, + const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt, + intern_type* to, intern_type* to_end, intern_type*& to_nxt) const +{ + const uint8_t* _frm = reinterpret_cast(frm); + const uint8_t* _frm_end = reinterpret_cast(frm_end); + const uint8_t* _frm_nxt = _frm; uint32_t* _to = reinterpret_cast(to); uint32_t* _to_end = reinterpret_cast(to_end); uint32_t* _to_nxt = _to; result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, _Maxcode_, _Mode_); -#endif frm_nxt = frm + (_frm_nxt - _frm); to_nxt = to + (_to_nxt - _to); return r; } -__codecvt_utf8::result -__codecvt_utf8::do_unshift(state_type&, +__codecvt_utf8_imp::result +__codecvt_utf8_imp::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const { to_nxt = to; @@ -3500,19 +3556,19 @@ } int -__codecvt_utf8::do_encoding() const noexcept +__codecvt_utf8_imp::do_encoding() const noexcept { return 0; } bool -__codecvt_utf8::do_always_noconv() const noexcept +__codecvt_utf8_imp::do_always_noconv() const noexcept { return false; } int -__codecvt_utf8::do_length(state_type&, +__codecvt_utf8_imp::do_length(state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const { const uint8_t* _frm = reinterpret_cast(frm); @@ -3521,7 +3577,7 @@ } int -__codecvt_utf8::do_max_length() const noexcept +__codecvt_utf8_imp::do_max_length() const noexcept { if (_Mode_ & consume_header) return 7; @@ -3678,10 +3734,161 @@ return 4; } -// __codecvt_utf16 +// __codecvt_utf16_imp + + +__codecvt_utf16_imp::result +__codecvt_utf16_imp::do_out(state_type&, + const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt, + extern_type* to, extern_type* to_end, extern_type*& to_nxt) const +{ + const uint16_t* _frm = reinterpret_cast(frm); + const uint16_t* _frm_end = reinterpret_cast(frm_end); + const uint16_t* _frm_nxt = _frm; + uint8_t* _to = reinterpret_cast(to); + uint8_t* _to_end = reinterpret_cast(to_end); + uint8_t* _to_nxt = _to; + result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, + _Maxcode_, _Mode_); + frm_nxt = frm + (_frm_nxt - _frm); + to_nxt = to + (_to_nxt - _to); + return r; +} + +__codecvt_utf16_imp::result +__codecvt_utf16_imp::do_in(state_type&, + const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt, + intern_type* to, intern_type* to_end, intern_type*& to_nxt) const +{ + const uint8_t* _frm = reinterpret_cast(frm); + const uint8_t* _frm_end = reinterpret_cast(frm_end); + const uint8_t* _frm_nxt = _frm; + uint16_t* _to = reinterpret_cast(to); + uint16_t* _to_end = reinterpret_cast(to_end); + uint16_t* _to_nxt = _to; + result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, + _Maxcode_, _Mode_); + frm_nxt = frm + (_frm_nxt - _frm); + to_nxt = to + (_to_nxt - _to); + return r; +} + +__codecvt_utf16_imp::result +__codecvt_utf16_imp::do_unshift(state_type&, + extern_type* to, extern_type*, extern_type*& to_nxt) const +{ + to_nxt = to; + return noconv; +} + +int +__codecvt_utf16_imp::do_encoding() const noexcept +{ + return 0; +} + +bool +__codecvt_utf16_imp::do_always_noconv() const noexcept +{ + return false; +} + +int +__codecvt_utf16_imp::do_length(state_type&, + const extern_type* frm, const extern_type* frm_end, size_t mx) const +{ + const uint8_t* _frm = reinterpret_cast(frm); + const uint8_t* _frm_end = reinterpret_cast(frm_end); + return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_); +} + +int +__codecvt_utf16_imp::do_max_length() const noexcept +{ + if (_Mode_ & consume_header) + return 4; + return 2; +} + +// __codecvt_utf16_imp + +__codecvt_utf16_imp::result +__codecvt_utf16_imp::do_out(state_type&, + const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt, + extern_type* to, extern_type* to_end, extern_type*& to_nxt) const +{ + const uint16_t* _frm = reinterpret_cast(frm); + const uint16_t* _frm_end = reinterpret_cast(frm_end); + const uint16_t* _frm_nxt = _frm; + uint8_t* _to = reinterpret_cast(to); + uint8_t* _to_end = reinterpret_cast(to_end); + uint8_t* _to_nxt = _to; + result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, + _Maxcode_, _Mode_); + frm_nxt = frm + (_frm_nxt - _frm); + to_nxt = to + (_to_nxt - _to); + return r; +} + +__codecvt_utf16_imp::result +__codecvt_utf16_imp::do_in(state_type&, + const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt, + intern_type* to, intern_type* to_end, intern_type*& to_nxt) const +{ + const uint8_t* _frm = reinterpret_cast(frm); + const uint8_t* _frm_end = reinterpret_cast(frm_end); + const uint8_t* _frm_nxt = _frm; + uint16_t* _to = reinterpret_cast(to); + uint16_t* _to_end = reinterpret_cast(to_end); + uint16_t* _to_nxt = _to; + result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, + _Maxcode_, _Mode_); + frm_nxt = frm + (_frm_nxt - _frm); + to_nxt = to + (_to_nxt - _to); + return r; +} + +__codecvt_utf16_imp::result +__codecvt_utf16_imp::do_unshift(state_type&, + extern_type* to, extern_type*, extern_type*& to_nxt) const +{ + to_nxt = to; + return noconv; +} + +int +__codecvt_utf16_imp::do_encoding() const noexcept +{ + return 0; +} + +bool +__codecvt_utf16_imp::do_always_noconv() const noexcept +{ + return false; +} + +int +__codecvt_utf16_imp::do_length(state_type&, + const extern_type* frm, const extern_type* frm_end, size_t mx) const +{ + const uint8_t* _frm = reinterpret_cast(frm); + const uint8_t* _frm_end = reinterpret_cast(frm_end); + return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_); +} + +int +__codecvt_utf16_imp::do_max_length() const noexcept +{ + if (_Mode_ & consume_header) + return 4; + return 2; +} + +// __codecvt_utf16_imp -__codecvt_utf16::result -__codecvt_utf16::do_out(state_type&, +__codecvt_utf16_imp::result +__codecvt_utf16_imp::do_out(state_type&, const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt, extern_type* to, extern_type* to_end, extern_type*& to_nxt) const { @@ -3698,8 +3905,8 @@ return r; } -__codecvt_utf16::result -__codecvt_utf16::do_in(state_type&, +__codecvt_utf16_imp::result +__codecvt_utf16_imp::do_in(state_type&, const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt, intern_type* to, intern_type* to_end, intern_type*& to_nxt) const { @@ -3716,8 +3923,8 @@ return r; } -__codecvt_utf16::result -__codecvt_utf16::do_unshift(state_type&, +__codecvt_utf16_imp::result +__codecvt_utf16_imp::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const { to_nxt = to; @@ -3725,19 +3932,19 @@ } int -__codecvt_utf16::do_encoding() const noexcept +__codecvt_utf16_imp::do_encoding() const noexcept { return 0; } bool -__codecvt_utf16::do_always_noconv() const noexcept +__codecvt_utf16_imp::do_always_noconv() const noexcept { return false; } int -__codecvt_utf16::do_length(state_type&, +__codecvt_utf16_imp::do_length(state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const { const uint8_t* _frm = reinterpret_cast(frm); @@ -3746,17 +3953,17 @@ } int -__codecvt_utf16::do_max_length() const noexcept +__codecvt_utf16_imp::do_max_length() const noexcept { if (_Mode_ & consume_header) return 6; return 4; } -// __codecvt_utf16 +// __codecvt_utf16_imp -__codecvt_utf16::result -__codecvt_utf16::do_out(state_type&, +__codecvt_utf16_imp::result +__codecvt_utf16_imp::do_out(state_type&, const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt, extern_type* to, extern_type* to_end, extern_type*& to_nxt) const { @@ -3773,8 +3980,8 @@ return r; } -__codecvt_utf16::result -__codecvt_utf16::do_in(state_type&, +__codecvt_utf16_imp::result +__codecvt_utf16_imp::do_in(state_type&, const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt, intern_type* to, intern_type* to_end, intern_type*& to_nxt) const { @@ -3791,8 +3998,8 @@ return r; } -__codecvt_utf16::result -__codecvt_utf16::do_unshift(state_type&, +__codecvt_utf16_imp::result +__codecvt_utf16_imp::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const { to_nxt = to; @@ -3800,19 +4007,19 @@ } int -__codecvt_utf16::do_encoding() const noexcept +__codecvt_utf16_imp::do_encoding() const noexcept { return 0; } bool -__codecvt_utf16::do_always_noconv() const noexcept +__codecvt_utf16_imp::do_always_noconv() const noexcept { return false; } int -__codecvt_utf16::do_length(state_type&, +__codecvt_utf16_imp::do_length(state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const { const uint8_t* _frm = reinterpret_cast(frm); @@ -3821,7 +4028,7 @@ } int -__codecvt_utf16::do_max_length() const noexcept +__codecvt_utf16_imp::do_max_length() const noexcept { if (_Mode_ & consume_header) return 6; @@ -4128,10 +4335,86 @@ return 4; } -// __codecvt_utf8_utf16 +// __codecvt_utf8_utf16_imp + +__codecvt_utf8_utf16_imp::result +__codecvt_utf8_utf16_imp::do_out(state_type&, + const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt, + extern_type* to, extern_type* to_end, extern_type*& to_nxt) const +{ + const uint16_t* _frm = reinterpret_cast(frm); + const uint16_t* _frm_end = reinterpret_cast(frm_end); + const uint16_t* _frm_nxt = _frm; + uint8_t* _to = reinterpret_cast(to); + uint8_t* _to_end = reinterpret_cast(to_end); + uint8_t* _to_nxt = _to; + result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, + _Maxcode_, _Mode_); + frm_nxt = frm + (_frm_nxt - _frm); + to_nxt = to + (_to_nxt - _to); + return r; +} + +__codecvt_utf8_utf16_imp::result +__codecvt_utf8_utf16_imp::do_in(state_type&, + const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt, + intern_type* to, intern_type* to_end, intern_type*& to_nxt) const +{ + const uint8_t* _frm = reinterpret_cast(frm); + const uint8_t* _frm_end = reinterpret_cast(frm_end); + const uint8_t* _frm_nxt = _frm; + uint16_t* _to = reinterpret_cast(to); + uint16_t* _to_end = reinterpret_cast(to_end); + uint16_t* _to_nxt = _to; + result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, + _Maxcode_, _Mode_); + frm_nxt = frm + (_frm_nxt - _frm); + to_nxt = to + (_to_nxt - _to); + return r; +} + +__codecvt_utf8_utf16_imp::result +__codecvt_utf8_utf16_imp::do_unshift(state_type&, + extern_type* to, extern_type*, extern_type*& to_nxt) const +{ + to_nxt = to; + return noconv; +} + +int +__codecvt_utf8_utf16_imp::do_encoding() const noexcept +{ + return 0; +} + +bool +__codecvt_utf8_utf16_imp::do_always_noconv() const noexcept +{ + return false; +} + +int +__codecvt_utf8_utf16_imp::do_length(state_type&, + const extern_type* frm, const extern_type* frm_end, size_t mx) const +{ + const uint8_t* _frm = reinterpret_cast(frm); + const uint8_t* _frm_end = reinterpret_cast(frm_end); + return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_); +} + +int +__codecvt_utf8_utf16_imp::do_max_length() const noexcept +{ + if (_Mode_ & consume_header) + return 7; + return 4; +} + +// __codecvt_utf8_utf16_imp + -__codecvt_utf8_utf16::result -__codecvt_utf8_utf16::do_out(state_type&, +__codecvt_utf8_utf16_imp::result +__codecvt_utf8_utf16_imp::do_out(state_type&, const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt, extern_type* to, extern_type* to_end, extern_type*& to_nxt) const { @@ -4148,8 +4431,8 @@ return r; } -__codecvt_utf8_utf16::result -__codecvt_utf8_utf16::do_in(state_type&, +__codecvt_utf8_utf16_imp::result +__codecvt_utf8_utf16_imp::do_in(state_type&, const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt, intern_type* to, intern_type* to_end, intern_type*& to_nxt) const { @@ -4166,8 +4449,8 @@ return r; } -__codecvt_utf8_utf16::result -__codecvt_utf8_utf16::do_unshift(state_type&, +__codecvt_utf8_utf16_imp::result +__codecvt_utf8_utf16_imp::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const { to_nxt = to; @@ -4175,19 +4458,19 @@ } int -__codecvt_utf8_utf16::do_encoding() const noexcept +__codecvt_utf8_utf16_imp::do_encoding() const noexcept { return 0; } bool -__codecvt_utf8_utf16::do_always_noconv() const noexcept +__codecvt_utf8_utf16_imp::do_always_noconv() const noexcept { return false; } int -__codecvt_utf8_utf16::do_length(state_type&, +__codecvt_utf8_utf16_imp::do_length(state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const { const uint8_t* _frm = reinterpret_cast(frm); @@ -4196,7 +4479,7 @@ } int -__codecvt_utf8_utf16::do_max_length() const noexcept +__codecvt_utf8_utf16_imp::do_max_length() const noexcept { if (_Mode_ & consume_header) return 7;