summaryrefslogtreecommitdiff
path: root/include/llmr/util/utf.hpp
blob: fb9ab2048b6bb9518e68dba4c8ed58b5eb568329 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef LLMR_UTIL_UTF
#define LLMR_UTIL_UTF

#include <memory>

// g++/libstdc++ is missing c++11 codecvt support
#ifdef __linux__
#include <boost/locale.hpp>
#else
#include <codecvt>
#endif

namespace llmr {

namespace util {

#ifdef __linux__

class utf8_to_utf32 {
 public:
    explicit utf8_to_utf32()
        : utf32conv_() {}
    std::u32string convert(std::string const& utf8) {
        return boost::locale::conv::utf_to_utf<char32_t>(utf8)
    }
};
#else

class utf8_to_utf32 {
 public:
    explicit utf8_to_utf32()
        : utf32conv_() {}
    std::u32string convert(std::string const& utf8) {
        return utf32conv_.from_bytes(utf8);
    }
 private:
    std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv_;
};

#endif

}}

#endif