]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/tools/quickbook/src/native_text.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / tools / quickbook / src / native_text.cpp
CommitLineData
7c673cae
FG
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
7c673cae 9#include "native_text.hpp"
11fdf7f2
TL
10#include <iostream>
11#include <boost/program_options.hpp>
7c673cae 12#include "utils.hpp"
7c673cae
FG
13
14#if QUICKBOOK_WIDE_PATHS || QUICKBOOK_WIDE_STREAMS
7c673cae 15#include <windows.h>
11fdf7f2 16#include <boost/scoped_array.hpp>
7c673cae
FG
17#endif
18
11fdf7f2
TL
19namespace quickbook
20{
21 namespace detail
22 {
7c673cae 23// This is used for converting paths to UTF-8 on cygin.
11fdf7f2 24// Might be better not to use a windows
7c673cae 25#if QUICKBOOK_WIDE_PATHS || QUICKBOOK_WIDE_STREAMS
11fdf7f2
TL
26 std::string to_utf8(std::wstring const& x)
27 {
28 int buffer_count =
29 WideCharToMultiByte(CP_UTF8, 0, x.c_str(), -1, 0, 0, 0, 0);
7c673cae 30
11fdf7f2
TL
31 if (!buffer_count)
32 throw conversion_error(
33 "Error converting wide string to utf-8.");
7c673cae 34
11fdf7f2 35 boost::scoped_array<char> buffer(new char[buffer_count]);
7c673cae 36
11fdf7f2
TL
37 if (!WideCharToMultiByte(
38 CP_UTF8, 0, x.c_str(), -1, buffer.get(), buffer_count, 0,
39 0))
40 throw conversion_error(
41 "Error converting wide string to utf-8.");
7c673cae 42
11fdf7f2
TL
43 return std::string(buffer.get());
44 }
7c673cae 45
11fdf7f2
TL
46 std::wstring from_utf8(quickbook::string_view text)
47 {
48 std::string x(text.begin(), text.end());
49 int buffer_count =
50 MultiByteToWideChar(CP_UTF8, 0, x.c_str(), -1, 0, 0);
7c673cae 51
11fdf7f2
TL
52 if (!buffer_count)
53 throw conversion_error(
54 "Error converting utf-8 to wide string.");
55
56 boost::scoped_array<wchar_t> buffer(new wchar_t[buffer_count]);
57
58 if (!MultiByteToWideChar(
59 CP_UTF8, 0, x.c_str(), -1, buffer.get(), buffer_count))
60 throw conversion_error(
61 "Error converting utf-8 to wide string.");
62
63 return std::wstring(buffer.get());
64 }
7c673cae 65#endif
11fdf7f2
TL
66 }
67}