From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/filesystem/example/mbpath.cpp | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/boost/libs/filesystem/example/mbpath.cpp (limited to 'src/boost/libs/filesystem/example/mbpath.cpp') diff --git a/src/boost/libs/filesystem/example/mbpath.cpp b/src/boost/libs/filesystem/example/mbpath.cpp new file mode 100644 index 00000000..43590010 --- /dev/null +++ b/src/boost/libs/filesystem/example/mbpath.cpp @@ -0,0 +1,80 @@ +// Boost.Filesystem mbpath.cpp ---------------------------------------------// + +// (c) Copyright Beman Dawes 2005 + +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See Boost.Filesystem home page at http://www.boost.org/libs/filesystem + +#include +# ifdef BOOST_FILESYSTEM_NARROW_ONLY +# error This compiler or standard library does not support wide-character strings or paths +# endif + +#include "mbpath.hpp" +#include +#include + +namespace fs = boost::filesystem; + +namespace +{ + // ISO C calls this "the locale-specific native environment": + std::locale loc(""); + + const std::codecvt * + cvt( &std::use_facet > + ( loc ) ); +} + +namespace user +{ + mbpath_traits::external_string_type + mbpath_traits::to_external( const mbpath & ph, + const internal_string_type & src ) + { + std::size_t work_size( cvt->max_length() * (src.size()+1) ); + boost::scoped_array work( new char[ work_size ] ); + std::mbstate_t state; + const internal_string_type::value_type * from_next; + external_string_type::value_type * to_next; + if ( cvt->out( + state, src.c_str(), src.c_str()+src.size(), from_next, work.get(), + work.get()+work_size, to_next ) != std::codecvt_base::ok ) + boost::throw_exception >( + fs::basic_filesystem_error( + "user::mbpath::to_external conversion error", + ph, boost::system::error_code( EINVAL, boost::system::errno_ecat ) ) ); + *to_next = '\0'; + return external_string_type( work.get() ); + } + + mbpath_traits::internal_string_type + mbpath_traits::to_internal( const external_string_type & src ) + { + std::size_t work_size( src.size()+1 ); + boost::scoped_array work( new wchar_t[ work_size ] ); + std::mbstate_t state; + const external_string_type::value_type * from_next; + internal_string_type::value_type * to_next; + if ( cvt->in( + state, src.c_str(), src.c_str()+src.size(), from_next, work.get(), + work.get()+work_size, to_next ) != std::codecvt_base::ok ) + boost::throw_exception >( + fs::basic_filesystem_error( + "user::mbpath::to_internal conversion error", + boost::system::error_code( EINVAL, boost::system::errno_ecat ) ) ); + *to_next = L'\0'; + return internal_string_type( work.get() ); + } + + void mbpath_traits::imbue( const std::locale & new_loc ) + { + loc = new_loc; + cvt = &std::use_facet + >( loc ); + } + +} // namespace user -- cgit v1.2.3