]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/include/boost/spirit/home/x3/support/utility/utf8.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / spirit / include / boost / spirit / home / x3 / support / utility / utf8.hpp
CommitLineData
7c673cae
FG
1/*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6==============================================================================*/
7#if !defined(BOOST_SPIRIT_X3_UC_TYPES_NOVEMBER_23_2008_0840PM)
8#define BOOST_SPIRIT_X3_UC_TYPES_NOVEMBER_23_2008_0840PM
9
10#include <boost/cstdint.hpp>
11#include <boost/regex/pending/unicode_iterator.hpp>
12#include <boost/type_traits/make_unsigned.hpp>
13#include <string>
14
15namespace boost { namespace spirit { namespace x3
16{
17 typedef ::boost::uint32_t ucs4_char;
18 typedef char utf8_char;
19 typedef std::basic_string<ucs4_char> ucs4_string;
20 typedef std::basic_string<utf8_char> utf8_string;
21
22 template <typename Char>
23 inline utf8_string to_utf8(Char value)
24 {
25 // always store as UTF8
26 utf8_string result;
27 typedef std::back_insert_iterator<utf8_string> insert_iter;
28 insert_iter out_iter(result);
29 utf8_output_iterator<insert_iter> utf8_iter(out_iter);
30 typedef typename make_unsigned<Char>::type UChar;
31 *utf8_iter = (UChar)value;
32 return result;
33 }
34
35 template <typename Char>
36 inline utf8_string to_utf8(Char const* str)
37 {
38 // always store as UTF8
39 utf8_string result;
40 typedef std::back_insert_iterator<utf8_string> insert_iter;
41 insert_iter out_iter(result);
42 utf8_output_iterator<insert_iter> utf8_iter(out_iter);
43 typedef typename make_unsigned<Char>::type UChar;
44 while (*str)
45 *utf8_iter++ = (UChar)*str++;
46 return result;
47 }
48
49 template <typename Char, typename Traits, typename Allocator>
50 inline utf8_string
51 to_utf8(std::basic_string<Char, Traits, Allocator> const& str)
52 {
53 // always store as UTF8
54 utf8_string result;
55 typedef std::back_insert_iterator<utf8_string> insert_iter;
56 insert_iter out_iter(result);
57 utf8_output_iterator<insert_iter> utf8_iter(out_iter);
58 typedef typename make_unsigned<Char>::type UChar;
59 for (Char ch : str)
60 {
61 *utf8_iter++ = (UChar)ch;
62 }
63 return result;
64 }
65}}}
66
67#endif