函数文档


1
2
3
4
5
6
std::string boost::locale::conv::between	(	char const * 	begin,
char const * end,
std::string const & to_encoding,
std::string const & from_encoding,
method_type how = default_method
)

Convert a text in range [begin,end) to to_encoding from from_encoding

将范围[begin,end)中的文本从from_encoding转为to_encoding


1
2
3
4
5
std::string boost::locale::conv::between	(	char const * 	text,
std::string const & to_encoding,
std::string const & from_encoding,
method_type how = default_method
)

Convert a text to to_encoding from from_encoding
将文本从from_encoding转换为to_encoding


1
2
3
4
5
std::string boost::locale::conv::between	(	std::string const & 	text,
std::string const & to_encoding,
std::string const & from_encoding,
method_type how = default_method
)

Convert a text to to_encoding from from_encoding
将文本从from_encoding转换为to_encoding


1
2
3
4
5
6
template<typename CharType >
std::string boost::locale::conv::from_utf ( CharType const * begin,
CharType const * end,
std::string const & charset,
method_type how = default_method
)

convert UTF text in range [begin,end) to a text encoded with charset according to policy how
根据策略将范围[begin,end)中的UTF文本转换为使用字符集编码charset的文本


1
2
3
4
5
6
template<typename CharType >
std::string boost::locale::conv::from_utf ( CharType const * begin,
CharType const * end,
std::locale const & loc,
method_type how = default_method
)

convert UTF text in range [begin,end) to a text encoded according to locale loc according to policy how
将范围[begin,end)中的UTF文本转换为区域设置loc编码的文本

Note
throws std::bad_cast if the loc does not have info facet installed

throwsstd::bad_cast如果没有安装loc信息


1
2
3
4
5
template<typename CharType >
std::string boost::locale::conv::from_utf ( std::basic_string< CharType > const & text,
std::string const & charset,
method_type how = default_method
)

Convert a text from charset to UTF string
将文本从charset字符集转换为UTF字符串


1
2
3
4
5
template<typename CharType >
std::string boost::locale::conv::from_utf ( CharType const * text,
std::string const & charset,
method_type how = default_method
)

Convert a text from UTF to charset
将文本从UTF转换为charset字符集


1
2
3
4
5
template<typename CharType >
std::string boost::locale::conv::from_utf ( std::basic_string< CharType > const & text,
std::locale const & loc,
method_type how = default_method
)

Convert a text in UTF to locale encoding given by loc
将UTF格式的文本转换为loc给出的区域设置编码

Note
throws std::bad_cast if the loc does not have info facet installed
throws std::bad_cast如果loc没有安装


1
2
3
4
5
template<typename CharType >
std::string boost::locale::conv::from_utf ( CharType const * text,
std::locale const & loc,
method_type how = default_method
)

Convert a text in UTF to locale encoding given by loc
将UTF格式的文本转换为loc给出的区域设置编码

Note
throws std::bad_cast if the loc does not have info facet installed
throws std::bad_cast如果loc没有安装


1
2
3
4
5
6
template<typename CharType >
std::basic_string<CharType> boost::locale::conv::to_utf ( char const * begin,
char const * end,
std::string const & charset,
method_type how = default_method
)

convert string to UTF string from text in range [begin,end) encoded with charset according to policy how
将范围 [begin,end)中的字符串用charset字符集编码的文本转换为UTF字符串


1
2
3
4
5
6
template<typename CharType >
std::basic_string<CharType> boost::locale::conv::to_utf ( char const * begin,
char const * end,
std::locale const & loc,
method_type how = default_method
)

convert string to UTF string from text in range [begin,end) encoded according to locale loc according to policy how
将范围[begin,end)中的文本根据区域设置loc转换为换为UTF字符串

Note
throws std::bad_cast if the loc does not have info facet installed
throws std::bad_cast如果loc没有安装


1
2
3
4
5
template<typename CharType >
std::basic_string<CharType> boost::locale::conv::to_utf ( std::string const & text,
std::string const & charset,
method_type how = default_method
)

convert a string text encoded with charset to UTF string
将使用charset字符集编码的字符串文本转换为UTF字符串


1
2
3
4
5
template<typename CharType >
std::basic_string<CharType> boost::locale::conv::to_utf ( char const * text,
std::string const & charset,
method_type how = default_method
)

Convert a text from charset to UTF string
将文本从charset字符集转换为 UTF 字符串


1
2
3
4
5
template<typename CharType >
std::basic_string<CharType> boost::locale::conv::to_utf ( std::string const & text,
std::locale const & loc,
method_type how = default_method
)

Convert a text in locale encoding given by loc to UTF
loc区域设置编码中的文本转换为UTF
Note
throws std::bad_cast if the loc does not have info facet installed
throws std::bad_cast如果loc没有安装


1
2
3
4
5
template<typename CharType >
std::basic_string<CharType> boost::locale::conv::to_utf ( char const * text,
std::locale const & loc,
method_type how = default_method
)

Convert a text in locale encoding given by loc to UTF
loc区域设置编码中的文本转换为UTF
Note
throws std::bad_cast if the loc does not have info facet installed
throws std::bad_cast如果loc没有安装


1
2
3
4
5
template<typename CharOut , typename CharIn >
std::basic_string<CharOut> boost::locale::conv::utf_to_utf ( CharIn const * begin,
CharIn const * end,
method_type how = default_method
)

Convert a Unicode text in range [begin,end) to other Unicode encoding
将范围 [begin,end)中的Unicode文本转换为其他Unicode编码


1
2
3
4
template<typename CharOut , typename CharIn >
std::basic_string<CharOut> boost::locale::conv::utf_to_utf ( CharIn const * str,
method_type how = default_method
)

Convert a Unicode NUL terminated string str other Unicode encoding
将以NULL为终止字符的Unicode str转换到其他Unicode编码


1
2
3
4
template<typename CharOut , typename CharIn >
std::basic_string<CharOut> boost::locale::conv::utf_to_utf ( std::basic_string< CharIn > const & str,
method_type how = default_method
)

Convert a Unicode string str other Unicode encoding
转换Unicode字符串str到其他Unicode编码

例子

UTF8 <-> GBK

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <boost/locale.hpp>

int TestChangeCode()
{
std::cout << "TestChangeCode" << "\n";
auto name = "你好啊\\ AA BB CC 联通 鸡蛋灌饼 !()";
std::cout << "name:\t" << name << "\n";
// gbk -> utf8
auto utf8 = boost::locale::conv::between(name, "UTF-8", "GBK");
std::cout << "utf8 name:\t" << utf8 << "\n";
// utf8 -> gbk
auto gbk = boost::locale::conv::between(utf8, "GBK", "UTF-8");
std::cout << "gbk name:\t" << gbk << "\n";
return 0;
}