Boost.Locale 之字符转换 gbk utf8 big5 string wstring等
2014-07-07 16:33
155 查看
Boost.Locale是一个库,它提供高质量的本地化的设施在C + +的方式。它最初是设计的一部分CppCMS - C + +的Web框架的项目,然后促成了提升。
Boost.Locale提供强大的工具,跨平台的本地化软件开发 - 这会谈到用户在其语言的软件。
提供的功能:
正确的大小写转换,大小写和规范化。
整理(排序),其中包括4 Unicode排序规则层面的支持。
日期,时间,时区和日历操作,格式化和分析,包括对日历比公历其他透明的支持。
边界分析字,词,句和换行符。
数字格式,拼写和语法分析。
货币格式和解析。
强大的邮件格式(字符串翻译),包括多种格式,使用GNU目录的支持。
字符集转换。
8位字符透明支持集,如拉丁文
支持
对C + +0 x的实验性支持
Boost.Locale提高和统一了标准库的API,它变得非常有用和方便开发跨平台的和“跨文化”软件的方式。
相关字符集转换函数功能摘要:
Convert a text in range [begin,end) to to_encoding from from_encoding
Convert a text to to_encoding from from_encoding
Convert a text to to_encoding from from_encoding
template<typename CharType >
convert UTF text in range [begin,end) to a text encoded with charset according to policy how
template<typename CharType >
convert UTF text in range [begin,end) to a text encoded according to locale loc according to policy how
Note:throws std::bad_cast if the loc does not have info facet installed
template<typename CharType >
Convert a text from charset to UTF string
template<typename CharType >
Convert a text from UTF to charset
template<typename CharType >
Convert a text in UTF to locale encoding given by loc
Note:throws std::bad_cast if the loc does not have info facet installed
template<typename CharType >
Convert a text in UTF to locale encoding given by loc
Note:throws std::bad_cast if the loc does not have info facet installed
template<typename CharType >
convert string to UTF string from text in range [begin,end) encoded with charset according to policy how
template<typename CharType >
convert string to UTF string from text in range [begin,end) encoded according to locale loc according to policy how
Note:throws std::bad_cast if the loc does not have info facet installed
template<typename CharType >
convert a string text encoded with charset to UTF string
template<typename CharType >
Convert a text from charset to UTF string
template<typename CharType >
Convert a text in locale encoding given by loc to UTF
Note:throws std::bad_cast if the loc does not have info facet installed
template<typename CharType >
Convert a text in locale encoding given by loc to UTF
Note:throws std::bad_cast if the loc does not have info facet installed
template<typename CharOut , typename CharIn >
Convert a Unicode text in range [begin,end) to other Unicode encoding
template<typename CharOut , typename CharIn >
Convert a Unicode NUL terminated string str other Unicode encoding
template<typename CharOut , typename CharIn >
Convert a Unicode string str other Unicode encoding
简单示例:
1、between把 source 这个字串从BIG5 转换到 UTF-8:
[cpp] view
plaincopy
string source = "BIG5字符串";
string s = boost::locale::conv::between( source, "UTF-8", "BIG5" );
2、to_utf可以输出 string ,也可以输出成 wstring。像下面的例子,就是把 sSource 这个
BIG-5 编码的字串,依序转换成 wstring 和 string 的字串。
[cpp] view
plaincopy
string sSource = "BIG-5字符串";
wstring ws = boost::locale::conv::to_utf<wchar_t>( sSource, "BIG5" );
string ss = boost::locale::conv::to_utf<char>( sSource, "BIG5" );
3、from_utf 是把 UTF 字串(string 或wstring)、转换为特定编码的字串用的,他可以转换string或wstring 的字串,但是输出一定是string。
下面的例子,就是把 sSource 和 wSource 这两个 UTF 字串,都转换成 BIG-5 的 string 字串。
[cpp] view
plaincopy
string sSource = "字符串";
wstring wSource = L"...";
string ss1 = boost::locale::conv::from_utf( wSource, "BIG5" );
string ss2 = boost::locale::conv::from_utf( sSource, "BIG5" );
4、utf_to_utf的目的,是在 UTF 的 string 字串和 wstring 字串之间做转换,下面的例子,就是把类型是string 的 sSource 转换成 wstring、并把类型是 wstring 的 wSource 转换成 string
[cpp] view
plaincopy
string sSource = "...";
wstring wSource = L"...";
wstring wStr = boost::locale::conv::utf_to_utf<wchar_t>( sSource );
string sStr = boost::locale::conv::utf_to_utf<char>( wSource );
Boost.Locale提供强大的工具,跨平台的本地化软件开发 - 这会谈到用户在其语言的软件。
提供的功能:
正确的大小写转换,大小写和规范化。
整理(排序),其中包括4 Unicode排序规则层面的支持。
日期,时间,时区和日历操作,格式化和分析,包括对日历比公历其他透明的支持。
边界分析字,词,句和换行符。
数字格式,拼写和语法分析。
货币格式和解析。
强大的邮件格式(字符串翻译),包括多种格式,使用GNU目录的支持。
字符集转换。
8位字符透明支持集,如拉丁文
支持
的char和
wchar_t的
对C + +0 x的实验性支持
char16_t和
char32_t字符串和数据流。
Boost.Locale提高和统一了标准库的API,它变得非常有用和方便开发跨平台的和“跨文化”软件的方式。
相关字符集转换函数功能摘要:
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 | ||
) |
std::string boost::locale::conv::between | ( | char const * | text, |
std::string const & | to_encoding, | ||
std::string const & | from_encoding, | ||
method_type | how = default_method | ||
) | [inline] |
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 | ||
) | [inline] |
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 | ||
) |
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 | ||
) |
Note:throws std::bad_cast if the loc does not have info facet installed
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 | ||
) |
template<typename CharType >
std::string boost::locale::conv::from_utf | ( | CharType const * | text, |
std::string const & | charset, | ||
method_type | how = default_method | ||
) |
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 | ||
) |
Note:throws std::bad_cast if the loc does not have info facet installed
template<typename CharType >
std::string boost::locale::conv::from_utf | ( | CharType const * | text, |
std::locale const & | loc, | ||
method_type | how = default_method | ||
) |
Note:throws std::bad_cast if the loc does not have info facet installed
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 | ||
) |
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 | ||
) |
Note:throws std::bad_cast if the loc does not have info facet installed
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 | ||
) |
template<typename CharType >
std::basic_string<CharType> boost::locale::conv::to_utf | ( | char const * | text, |
std::string const & | charset, | ||
method_type | how = default_method | ||
) |
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 | ||
) |
Note:throws std::bad_cast if the loc does not have info facet installed
template<typename CharType >
std::basic_string<CharType> boost::locale::conv::to_utf | ( | char const * | text, |
std::locale const & | loc, | ||
method_type | how = default_method | ||
) |
Note:throws std::bad_cast if the loc does not have info facet installed
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 | ||
) |
template<typename CharOut , typename CharIn >
std::basic_string<CharOut> boost::locale::conv::utf_to_utf | ( | CharIn const * | str, |
method_type | how = default_method | ||
) |
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 | ||
) |
简单示例:
1、between把 source 这个字串从BIG5 转换到 UTF-8:
[cpp] view
plaincopy
string source = "BIG5字符串";
string s = boost::locale::conv::between( source, "UTF-8", "BIG5" );
2、to_utf可以输出 string ,也可以输出成 wstring。像下面的例子,就是把 sSource 这个
BIG-5 编码的字串,依序转换成 wstring 和 string 的字串。
[cpp] view
plaincopy
string sSource = "BIG-5字符串";
wstring ws = boost::locale::conv::to_utf<wchar_t>( sSource, "BIG5" );
string ss = boost::locale::conv::to_utf<char>( sSource, "BIG5" );
3、from_utf 是把 UTF 字串(string 或wstring)、转换为特定编码的字串用的,他可以转换string或wstring 的字串,但是输出一定是string。
下面的例子,就是把 sSource 和 wSource 这两个 UTF 字串,都转换成 BIG-5 的 string 字串。
[cpp] view
plaincopy
string sSource = "字符串";
wstring wSource = L"...";
string ss1 = boost::locale::conv::from_utf( wSource, "BIG5" );
string ss2 = boost::locale::conv::from_utf( sSource, "BIG5" );
4、utf_to_utf的目的,是在 UTF 的 string 字串和 wstring 字串之间做转换,下面的例子,就是把类型是string 的 sSource 转换成 wstring、并把类型是 wstring 的 wSource 转换成 string
[cpp] view
plaincopy
string sSource = "...";
wstring wSource = L"...";
wstring wStr = boost::locale::conv::utf_to_utf<wchar_t>( sSource );
string sStr = boost::locale::conv::utf_to_utf<char>( wSource );
相关文章推荐
- boost库学习随记五 Boost.Locale 之字符转换 gbk utf8 big5 string wstring等
- Boost.Locale 之字符转换 gbk utf8 big5 string wstring等
- 工具方法,将字符创由一种编码转换成另一种编码,UTF-8,GBK,ISO,BIG5。。。。。。
- BIG5 GBT字符转换
- boost::lexical_cast 字符类型转换 字符串算法和文字处理
- MySQL字符集设置及字符转换(latin1转utf8)
- Delphi 转换 UTF8 字符为 Unicode 字符
- CString string char等字符类型的相关知识和转换
- java学习之字符流与字节流的转换
- java把html标签字符转普通字符(反转换成html标签)
- PHP 中的类型强制转换 字符转数值
- PHP中实现中文字符进制转换原理分析
- SAP ABAP转换特殊字符乱码
- php全角字符转换为半角函数
- 将一串从标准输入的数字字符转换为整数
- acmore.cc|acmore.cc1021科学方面:计算能量1022科学方面:风寒温度1023打印表格1024字符转换1025几何方面:两点间的距离
- Java工具类——全角半角字符相互转换
- 单字符宽字符互相转换
- 数组-01. 字符转换(15)
- ubuntu-图形界面和字符界面转换、指定默认启动界面