]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/src/native_text.cpp
1 /*=============================================================================
2 Copyright (c) 2009 Daniel James
4 Use, modification and distribution is subject to the Boost Software
5 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
9 #include <boost/program_options.hpp>
11 #include "native_text.hpp"
14 #if QUICKBOOK_WIDE_PATHS || QUICKBOOK_WIDE_STREAMS
15 #include <boost/scoped_ptr.hpp>
21 // This is used for converting paths to UTF-8 on cygin.
22 // Might be better not to use a windows
23 #if QUICKBOOK_WIDE_PATHS || QUICKBOOK_WIDE_STREAMS
24 std::string
to_utf8(std::wstring
const& x
)
26 int buffer_count
= WideCharToMultiByte(CP_UTF8
, 0, x
.c_str(), -1, 0, 0, 0, 0);
29 throw conversion_error("Error converting wide string to utf-8.");
31 boost::scoped_ptr
<char> buffer(new char[buffer_count
]);
33 if (!WideCharToMultiByte(CP_UTF8
, 0, x
.c_str(), -1, buffer
.get(), buffer_count
, 0, 0))
34 throw conversion_error("Error converting wide string to utf-8.");
36 return std::string(buffer
.get());
39 std::wstring
from_utf8(quickbook::string_view text
)
41 std::string
x(text
.begin(), text
.end());
42 int buffer_count
= MultiByteToWideChar(CP_UTF8
, 0, x
.c_str(), -1, 0, 0);
45 throw conversion_error("Error converting utf-8 to wide string.");
47 boost::scoped_ptr
<wchar_t> buffer(new wchar_t[buffer_count
]);
49 if (!MultiByteToWideChar(CP_UTF8
, 0, x
.c_str(), -1, buffer
.get(), buffer_count
))
50 throw conversion_error("Error converting utf-8 to wide string.");
52 return std::wstring(buffer
.get());