// Locale support (codecvt) -*- C++ -*-
-// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-// 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2000-2024 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
#pragma GCC system_header
+#include <bits/c++config.h>
+#include <bits/locale_classes.h> // locale::facet
+
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
* output, returns codecvt_base::partial. Otherwise the
* conversion failed and codecvt_base::error is returned.
*
- * @param state Persistent conversion state data.
- * @param from Start of input.
- * @param from_end End of input.
- * @param from_next Returns start of unconverted data.
- * @param to Start of output buffer.
- * @param to_end End of output buffer.
- * @param to_next Returns start of unused output area.
+ * @param __state Persistent conversion state data.
+ * @param __from Start of input.
+ * @param __from_end End of input.
+ * @param __from_next Returns start of unconverted data.
+ * @param __to Start of output buffer.
+ * @param __to_end End of output buffer.
+ * @param __to_next Returns start of unused output area.
* @return codecvt_base::result.
*/
result
* output has insufficient space, returns codecvt_base::partial.
* Otherwise the reset failed and codecvt_base::error is returned.
*
- * @param state Persistent conversion state data.
- * @param to Start of output buffer.
- * @param to_end End of output buffer.
- * @param to_next Returns start of unused output area.
+ * @param __state Persistent conversion state data.
+ * @param __to Start of output buffer.
+ * @param __to_end End of output buffer.
+ * @param __to_next Returns start of unused output area.
* @return codecvt_base::result.
*/
result
* output, returns codecvt_base::partial. Otherwise the
* conversion failed and codecvt_base::error is returned.
*
- * @param state Persistent conversion state data.
- * @param from Start of input.
- * @param from_end End of input.
- * @param from_next Returns start of unconverted data.
- * @param to Start of output buffer.
- * @param to_end End of output buffer.
- * @param to_next Returns start of unused output area.
+ * @param __state Persistent conversion state data.
+ * @param __from Start of input.
+ * @param __from_end End of input.
+ * @param __from_next Returns start of unconverted data.
+ * @param __to Start of output buffer.
+ * @param __to_end End of output buffer.
+ * @param __to_next Returns start of unused output area.
* @return codecvt_base::result.
*/
result
do_max_length() const throw() = 0;
};
-
-
/**
* @brief Primary class template codecvt.
* @ingroup locales
explicit
codecvt(size_t __refs = 0)
- : __codecvt_abstract_base<_InternT, _ExternT, _StateT> (__refs) { }
+ : __codecvt_abstract_base<_InternT, _ExternT, _StateT> (__refs),
+ _M_c_locale_codecvt(0)
+ { }
explicit
codecvt(__c_locale __cloc, size_t __refs = 0);
class codecvt<char, char, mbstate_t>
: public __codecvt_abstract_base<char, char, mbstate_t>
{
+ friend class messages<char>;
+
public:
// Types:
typedef char intern_type;
};
#ifdef _GLIBCXX_USE_WCHAR_T
- /// class codecvt<wchar_t, char, mbstate_t> specialization.
+ /** @brief Class codecvt<wchar_t, char, mbstate_t> specialization.
+ *
+ * Converts between narrow and wide characters in the native character set
+ */
template<>
class codecvt<wchar_t, char, mbstate_t>
: public __codecvt_abstract_base<wchar_t, char, mbstate_t>
{
+ friend class messages<wchar_t>;
+
public:
// Types:
typedef wchar_t intern_type;
};
#endif //_GLIBCXX_USE_WCHAR_T
+#if __cplusplus >= 201103L
+ /** @brief Class codecvt<char16_t, char, mbstate_t> specialization.
+ *
+ * Converts between UTF-16 and UTF-8.
+ */
+ template<>
+ class codecvt<char16_t, char, mbstate_t>
+ : public __codecvt_abstract_base<char16_t, char, mbstate_t>
+ {
+ public:
+ // Types:
+ typedef char16_t intern_type;
+ typedef char extern_type;
+ typedef mbstate_t state_type;
+
+ public:
+ static locale::id id;
+
+ explicit
+ codecvt(size_t __refs = 0)
+ : __codecvt_abstract_base<char16_t, char, mbstate_t>(__refs) { }
+
+ protected:
+ virtual
+ ~codecvt();
+
+ virtual result
+ do_out(state_type& __state, const intern_type* __from,
+ const intern_type* __from_end, const intern_type*& __from_next,
+ extern_type* __to, extern_type* __to_end,
+ extern_type*& __to_next) const;
+
+ virtual result
+ do_unshift(state_type& __state,
+ extern_type* __to, extern_type* __to_end,
+ extern_type*& __to_next) const;
+
+ virtual result
+ do_in(state_type& __state,
+ const extern_type* __from, const extern_type* __from_end,
+ const extern_type*& __from_next,
+ intern_type* __to, intern_type* __to_end,
+ intern_type*& __to_next) const;
+
+ virtual
+ int do_encoding() const throw();
+
+ virtual
+ bool do_always_noconv() const throw();
+
+ virtual
+ int do_length(state_type&, const extern_type* __from,
+ const extern_type* __end, size_t __max) const;
+
+ virtual int
+ do_max_length() const throw();
+ };
+
+ /** @brief Class codecvt<char32_t, char, mbstate_t> specialization.
+ *
+ * Converts between UTF-32 and UTF-8.
+ */
+ template<>
+ class codecvt<char32_t, char, mbstate_t>
+ : public __codecvt_abstract_base<char32_t, char, mbstate_t>
+ {
+ public:
+ // Types:
+ typedef char32_t intern_type;
+ typedef char extern_type;
+ typedef mbstate_t state_type;
+
+ public:
+ static locale::id id;
+
+ explicit
+ codecvt(size_t __refs = 0)
+ : __codecvt_abstract_base<char32_t, char, mbstate_t>(__refs) { }
+
+ protected:
+ virtual
+ ~codecvt();
+
+ virtual result
+ do_out(state_type& __state, const intern_type* __from,
+ const intern_type* __from_end, const intern_type*& __from_next,
+ extern_type* __to, extern_type* __to_end,
+ extern_type*& __to_next) const;
+
+ virtual result
+ do_unshift(state_type& __state,
+ extern_type* __to, extern_type* __to_end,
+ extern_type*& __to_next) const;
+
+ virtual result
+ do_in(state_type& __state,
+ const extern_type* __from, const extern_type* __from_end,
+ const extern_type*& __from_next,
+ intern_type* __to, intern_type* __to_end,
+ intern_type*& __to_next) const;
+
+ virtual
+ int do_encoding() const throw();
+
+ virtual
+ bool do_always_noconv() const throw();
+
+ virtual
+ int do_length(state_type&, const extern_type* __from,
+ const extern_type* __end, size_t __max) const;
+
+ virtual int
+ do_max_length() const throw();
+ };
+
+#ifdef _GLIBCXX_USE_CHAR8_T
+ /** @brief Class codecvt<char16_t, char8_t, mbstate_t> specialization.
+ *
+ * Converts between UTF-16 and UTF-8.
+ */
+ template<>
+ class codecvt<char16_t, char8_t, mbstate_t>
+ : public __codecvt_abstract_base<char16_t, char8_t, mbstate_t>
+ {
+ public:
+ // Types:
+ typedef char16_t intern_type;
+ typedef char8_t extern_type;
+ typedef mbstate_t state_type;
+
+ public:
+ static locale::id id;
+
+ explicit
+ codecvt(size_t __refs = 0)
+ : __codecvt_abstract_base<char16_t, char8_t, mbstate_t>(__refs) { }
+
+ protected:
+ virtual
+ ~codecvt();
+
+ virtual result
+ do_out(state_type& __state, const intern_type* __from,
+ const intern_type* __from_end, const intern_type*& __from_next,
+ extern_type* __to, extern_type* __to_end,
+ extern_type*& __to_next) const;
+
+ virtual result
+ do_unshift(state_type& __state,
+ extern_type* __to, extern_type* __to_end,
+ extern_type*& __to_next) const;
+
+ virtual result
+ do_in(state_type& __state,
+ const extern_type* __from, const extern_type* __from_end,
+ const extern_type*& __from_next,
+ intern_type* __to, intern_type* __to_end,
+ intern_type*& __to_next) const;
+
+ virtual
+ int do_encoding() const throw();
+
+ virtual
+ bool do_always_noconv() const throw();
+
+ virtual
+ int do_length(state_type&, const extern_type* __from,
+ const extern_type* __end, size_t __max) const;
+
+ virtual int
+ do_max_length() const throw();
+ };
+
+ /** @brief Class codecvt<char32_t, char8_t, mbstate_t> specialization.
+ *
+ * Converts between UTF-32 and UTF-8.
+ */
+ template<>
+ class codecvt<char32_t, char8_t, mbstate_t>
+ : public __codecvt_abstract_base<char32_t, char8_t, mbstate_t>
+ {
+ public:
+ // Types:
+ typedef char32_t intern_type;
+ typedef char8_t extern_type;
+ typedef mbstate_t state_type;
+
+ public:
+ static locale::id id;
+
+ explicit
+ codecvt(size_t __refs = 0)
+ : __codecvt_abstract_base<char32_t, char8_t, mbstate_t>(__refs) { }
+
+ protected:
+ virtual
+ ~codecvt();
+
+ virtual result
+ do_out(state_type& __state, const intern_type* __from,
+ const intern_type* __from_end, const intern_type*& __from_next,
+ extern_type* __to, extern_type* __to_end,
+ extern_type*& __to_next) const;
+
+ virtual result
+ do_unshift(state_type& __state,
+ extern_type* __to, extern_type* __to_end,
+ extern_type*& __to_next) const;
+
+ virtual result
+ do_in(state_type& __state,
+ const extern_type* __from, const extern_type* __from_end,
+ const extern_type*& __from_next,
+ intern_type* __to, intern_type* __to_end,
+ intern_type*& __to_next) const;
+
+ virtual
+ int do_encoding() const throw();
+
+ virtual
+ bool do_always_noconv() const throw();
+
+ virtual
+ int do_length(state_type&, const extern_type* __from,
+ const extern_type* __end, size_t __max) const;
+
+ virtual int
+ do_max_length() const throw();
+ };
+#endif // _GLIBCXX_USE_CHAR8_T
+
+#endif // C++11
+
/// class codecvt_byname [22.2.1.6].
template<typename _InternT, typename _ExternT, typename _StateT>
class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT>
}
}
+#if __cplusplus >= 201103L
+ explicit
+ codecvt_byname(const string& __s, size_t __refs = 0)
+ : codecvt_byname(__s.c_str(), __refs) { }
+#endif
+
+ protected:
+ virtual
+ ~codecvt_byname() { }
+ };
+
+#if __cplusplus >= 201103L
+ template<>
+ class codecvt_byname<char16_t, char, mbstate_t>
+ : public codecvt<char16_t, char, mbstate_t>
+ {
+ public:
+ explicit
+ codecvt_byname(const char*, size_t __refs = 0)
+ : codecvt<char16_t, char, mbstate_t>(__refs) { }
+
+ explicit
+ codecvt_byname(const string& __s, size_t __refs = 0)
+ : codecvt_byname(__s.c_str(), __refs) { }
+
+ protected:
+ virtual
+ ~codecvt_byname() { }
+ };
+
+ template<>
+ class codecvt_byname<char32_t, char, mbstate_t>
+ : public codecvt<char32_t, char, mbstate_t>
+ {
+ public:
+ explicit
+ codecvt_byname(const char*, size_t __refs = 0)
+ : codecvt<char32_t, char, mbstate_t>(__refs) { }
+
+ explicit
+ codecvt_byname(const string& __s, size_t __refs = 0)
+ : codecvt_byname(__s.c_str(), __refs) { }
+
protected:
virtual
~codecvt_byname() { }
};
+#if defined(_GLIBCXX_USE_CHAR8_T)
+ template<>
+ class codecvt_byname<char16_t, char8_t, mbstate_t>
+ : public codecvt<char16_t, char8_t, mbstate_t>
+ {
+ public:
+ explicit
+ codecvt_byname(const char*, size_t __refs = 0)
+ : codecvt<char16_t, char8_t, mbstate_t>(__refs) { }
+
+ explicit
+ codecvt_byname(const string& __s, size_t __refs = 0)
+ : codecvt_byname(__s.c_str(), __refs) { }
+
+ protected:
+ virtual
+ ~codecvt_byname() { }
+ };
+
+ template<>
+ class codecvt_byname<char32_t, char8_t, mbstate_t>
+ : public codecvt<char32_t, char8_t, mbstate_t>
+ {
+ public:
+ explicit
+ codecvt_byname(const char*, size_t __refs = 0)
+ : codecvt<char32_t, char8_t, mbstate_t>(__refs) { }
+
+ explicit
+ codecvt_byname(const string& __s, size_t __refs = 0)
+ : codecvt_byname(__s.c_str(), __refs) { }
+
+ protected:
+ virtual
+ ~codecvt_byname() { }
+ };
+#endif
+
+#endif // C++11
+
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
#if _GLIBCXX_EXTERN_TEMPLATE
bool
has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
#endif
+
+#if __cplusplus >= 201103L
+ extern template class codecvt_byname<char16_t, char, mbstate_t>;
+ extern template class codecvt_byname<char32_t, char, mbstate_t>;
+
+#if defined(_GLIBCXX_USE_CHAR8_T)
+ extern template class codecvt_byname<char16_t, char8_t, mbstate_t>;
+ extern template class codecvt_byname<char32_t, char8_t, mbstate_t>;
+#endif
+
+#endif
+
#endif
_GLIBCXX_END_NAMESPACE_VERSION