]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/src/native_text.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / tools / quickbook / src / native_text.cpp
1 /*=============================================================================
2 Copyright (c) 2009 Daniel James
3
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 =============================================================================*/
8
9 #include <boost/program_options.hpp>
10 #include <iostream>
11 #include "native_text.hpp"
12 #include "utils.hpp"
13
14 #if QUICKBOOK_WIDE_PATHS || QUICKBOOK_WIDE_STREAMS
15 #include <boost/scoped_ptr.hpp>
16 #include <windows.h>
17 #endif
18
19 namespace quickbook {
20 namespace detail {
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)
25 {
26 int buffer_count = WideCharToMultiByte(CP_UTF8, 0, x.c_str(), -1, 0, 0, 0, 0);
27
28 if (!buffer_count)
29 throw conversion_error("Error converting wide string to utf-8.");
30
31 boost::scoped_ptr<char> buffer(new char[buffer_count]);
32
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.");
35
36 return std::string(buffer.get());
37 }
38
39 std::wstring from_utf8(quickbook::string_view text)
40 {
41 std::string x(text.begin(), text.end());
42 int buffer_count = MultiByteToWideChar(CP_UTF8, 0, x.c_str(), -1, 0, 0);
43
44 if (!buffer_count)
45 throw conversion_error("Error converting utf-8 to wide string.");
46
47 boost::scoped_ptr<wchar_t> buffer(new wchar_t[buffer_count]);
48
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.");
51
52 return std::wstring(buffer.get());
53 }
54 #endif
55 }}