blob: 5453aeded5410e8f375e272721e40e2591d2fd57 (
plain) (
blame)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_CONV_IMPL_HPP
#define BOOST_LOCALE_CONV_IMPL_HPP
#include <boost/locale/config.hpp>
#include <boost/locale/encoding.hpp>
namespace boost {
namespace locale {
namespace conv {
namespace impl {
template<typename CharType>
char const *utf_name()
{
union {
char first;
uint16_t u16;
uint32_t u32;
} v;
if(sizeof(CharType) == 1) {
return "UTF-8";
}
else if(sizeof(CharType) == 2) {
v.u16 = 1;
if(v.first == 1) {
return "UTF-16LE";
}
else {
return "UTF-16BE";
}
}
else if(sizeof(CharType) == 4) {
v.u32 = 1;
if(v.first == 1) {
return "UTF-32LE";
}
else {
return "UTF-32BE";
}
}
else {
return "Unknown Character Encoding";
}
}
std::string normalize_encoding(char const *encoding);
inline int compare_encodings(char const *l,char const *r)
{
return normalize_encoding(l).compare(normalize_encoding(r));
}
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
int encoding_to_windows_codepage(char const *ccharset);
#endif
class converter_between {
public:
typedef char char_type;
typedef std::string string_type;
virtual bool open(char const *to_charset,char const *from_charset,method_type how) = 0;
virtual std::string convert(char const *begin,char const *end) = 0;
virtual ~converter_between()
{
}
};
template<typename CharType>
class converter_from_utf {
public:
typedef CharType char_type;
typedef std::basic_string<char_type> string_type;
virtual bool open(char const *charset,method_type how) = 0;
virtual std::string convert(CharType const *begin,CharType const *end) = 0;
virtual ~converter_from_utf()
{
}
};
template<typename CharType>
class converter_to_utf {
public:
typedef CharType char_type;
typedef std::basic_string<char_type> string_type;
virtual bool open(char const *charset,method_type how) = 0;
virtual string_type convert(char const *begin,char const *end) = 0;
virtual ~converter_to_utf()
{
}
};
}
}
}
}
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
#endif
|