remove dependency on <codecvt>

This header seems to have errors in some environments.
It has been deprecated by the C++ committe.
For these reasons, we'll rely solely on Ron Garcia's code convert facet for utf.
This commit is contained in:
Robert Ramey
2017-10-17 10:55:47 -07:00
parent 40314f94df
commit 64dc620992
9 changed files with 58 additions and 50 deletions

View File

@@ -13,27 +13,17 @@
#error "wide char i/o not supported on this platform"
#endif
// std::codecvt_utf8 doesn't seem to work for any versions of msvc
// use boost's utf8 codecvt facet
#include <boost/archive/detail/decl.hpp>
#define BOOST_UTF8_BEGIN_NAMESPACE \
namespace boost { namespace archive { namespace detail {
#define BOOST_UTF8_DECL BOOST_ARCHIVE_DECL
#define BOOST_UTF8_END_NAMESPACE }}}
#if defined(_MSC_VER) || defined(BOOST_NO_CXX11_HDR_CODECVT)
// use boost's utf8 codecvt facet
#include <boost/archive/detail/decl.hpp>
#define BOOST_UTF8_BEGIN_NAMESPACE \
namespace boost { namespace archive { namespace detail {
#define BOOST_UTF8_DECL BOOST_ARCHIVE_DECL
#define BOOST_UTF8_END_NAMESPACE }}}
#include <boost/detail/utf8_codecvt_facet.hpp>
#include <boost/detail/utf8_codecvt_facet.hpp>
#undef BOOST_UTF8_END_NAMESPACE
#undef BOOST_UTF8_DECL
#undef BOOST_UTF8_BEGIN_NAMESPACE
#else
// use the standard vendor supplied facet
#include <codecvt>
namespace boost { namespace archive { namespace detail {
typedef std::codecvt_utf8<wchar_t> utf8_codecvt_facet;
} } }
#endif
#undef BOOST_UTF8_END_NAMESPACE
#undef BOOST_UTF8_DECL
#undef BOOST_UTF8_BEGIN_NAMESPACE
#endif // BOOST_ARCHIVE_DETAIL_UTF8_CODECVT_FACET_HPP

View File

@@ -161,13 +161,13 @@ xml_wiarchive_impl<Archive>::xml_wiarchive_impl(
gimpl(new xml_wgrammar())
{
if(0 == (flags & no_codecvt)){
std::locale l = std::locale(
archive_locale = std::locale(
is_.getloc(),
new boost::archive::detail::utf8_codecvt_facet
);
// libstdc++ crashes without this
is_.sync();
is_.imbue(l);
is_.imbue(archive_locale);
}
if(0 == (flags & no_header))
init();

View File

@@ -103,7 +103,6 @@ xml_woarchive_impl<Archive>::save(const char * s){
template<class Archive>
BOOST_WARCHIVE_DECL void
xml_woarchive_impl<Archive>::save(const wchar_t * ws){
os << ws;
typedef iterators::xml_escape<const wchar_t *> xmbtows;
std::copy(
xmbtows(ws),
@@ -126,12 +125,12 @@ xml_woarchive_impl<Archive>::xml_woarchive_impl(
basic_xml_oarchive<Archive>(flags)
{
if(0 == (flags & no_codecvt)){
std::locale l = std::locale(
archive_locale = std::locale(
os_.getloc(),
new boost::archive::detail::utf8_codecvt_facet
);
os_.flush();
os_.imbue(l);
os_.imbue(archive_locale);
}
if(0 == (flags & no_header))
this->init();
@@ -143,7 +142,7 @@ xml_woarchive_impl<Archive>::~xml_woarchive_impl(){
if(std::uncaught_exception())
return;
if(0 == (this->get_flags() & no_header)){
save(L"</boost_serialization>\n");
os << L"</boost_serialization>";
}
}

View File

@@ -62,6 +62,7 @@ protected:
friend class basic_xml_iarchive<Archive>;
friend class load_access;
#endif
std::locale archive_locale;
boost::scoped_ptr<xml_wgrammar> gimpl;
std::wistream & get_is(){
return is;