| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 | ////  Copyright (c) 2012 Artyom Beilis (Tonkikh)////  Distributed under 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)//#ifndef BOOST_NOWIDE_CONVERT_HPP_INCLUDED#define BOOST_NOWIDE_CONVERT_HPP_INCLUDED#include <boost/nowide/detail/convert.hpp>#include <string>namespace boost {namespace nowide {    ///    /// Convert wide string (UTF-16/32) in range [begin,end) to NULL terminated narrow string (UTF-8)    /// stored in \a output of size \a output_size (including NULL)    ///    /// If there is not enough room NULL is returned, else output is returned.    /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER    ///    inline char* narrow(char* output, size_t output_size, const wchar_t* begin, const wchar_t* end)    {        return detail::convert_buffer(output, output_size, begin, end);    }    ///    /// Convert NULL terminated wide string (UTF-16/32) to NULL terminated narrow string (UTF-8)    /// stored in \a output of size \a output_size (including NULL)    ///    /// If there is not enough room NULL is returned, else output is returned.    /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER    ///    inline char* narrow(char* output, size_t output_size, const wchar_t* source)    {        return narrow(output, output_size, source, source + detail::strlen(source));    }    ///    /// Convert narrow string (UTF-8) in range [begin,end) to NULL terminated wide string (UTF-16/32)    /// stored in \a output of size \a output_size (including NULL)    ///    /// If there is not enough room NULL is returned, else output is returned.    /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER    ///    inline wchar_t* widen(wchar_t* output, size_t output_size, const char* begin, const char* end)    {        return detail::convert_buffer(output, output_size, begin, end);    }    ///    /// Convert NULL terminated narrow string (UTF-8) to NULL terminated wide string (UTF-16/32)    /// most output_size (including NULL)    ///    /// If there is not enough room NULL is returned, else output is returned.    /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER    ///    inline wchar_t* widen(wchar_t* output, size_t output_size, const char* source)    {        return widen(output, output_size, source, source + detail::strlen(source));    }    ///    /// Convert wide string (UTF-16/32) to narrow string (UTF-8).    ///    /// \param s Input string    /// \param count Number of characters to convert    /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER    ///    inline std::string narrow(const wchar_t* s, size_t count)    {        return detail::convert_string<char>(s, s + count);    }    ///    /// Convert wide string (UTF-16/32) to narrow string (UTF-8).    ///    /// \param s NULL terminated input string    /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER    ///    inline std::string narrow(const wchar_t* s)    {        return narrow(s, detail::strlen(s));    }    ///    /// Convert wide string (UTF-16/32) to narrow string (UTF-8).    ///    /// \param s Input string    /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER    ///    inline std::string narrow(const std::wstring& s)    {        return narrow(s.c_str(), s.size());    }    ///    /// Convert narrow string (UTF-8) to wide string (UTF-16/32).    ///    /// \param s Input string    /// \param count Number of characters to convert    /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER    ///    inline std::wstring widen(const char* s, size_t count)    {        return detail::convert_string<wchar_t>(s, s + count);    }    ///    /// Convert narrow string (UTF-8) to wide string (UTF-16/32).    ///    /// \param s NULL terminated input string    /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER    ///    inline std::wstring widen(const char* s)    {        return widen(s, detail::strlen(s));    }    ///    /// Convert narrow string (UTF-8) to wide string (UTF-16/32).    ///    /// \param s Input string    /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER    ///    inline std::wstring widen(const std::string& s)    {        return widen(s.c_str(), s.size());    }} // namespace nowide} // namespace boost#endif
 |