Boost.Locale是一个库,它提供高质量的本地化的设施在C + +的方式。它最初是设计的一部分CppCMS - C + +的Web框架的项目,然后促成了提升。

Boost.Locale提供强大的工具,跨平台的本地化软件开发 - 这会谈到用户在其语言的软件。

提供的功能

  • 正确的大小写转换,大小写和规范化。
  • 整理(排序),其中包括4 Unicode排序规则层面的支持。
  • 日期,时间,时区和日历操作,格式化和分析,包括对日历比公历其他透明的支持。
  • 边界分析字,词,句和换行符。
  • 数字格式,拼写和语法分析。
  • 货币格式和解析。
  • 强大的邮件格式(字符串翻译),包括多种格式,使用GNU目录的支持。
  • 字符集转换。
  • 8位字符透明支持集,如拉丁文
  • 支持的charwchar_t的
  • 对C + +0 x的实验性支持char16_tchar32_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 
  )    

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

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]

Convert a text to to_encoding from from_encoding

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]

Convert a text to to_encoding from from_encoding

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

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

Note:
throws std::bad_cast if the loc does not haveinfofacet 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 
  )    

Convert a text from charset to UTF string

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

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

Note:
throws std::bad_cast if the loc does not haveinfofacet installed
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

Note:
throws std::bad_cast if the loc does not haveinfofacet 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 
  )    

convert string to UTF string from text in range [begin,end) encoded with charset according to policy how

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

Note:
throws std::bad_cast if the loc does not haveinfofacet 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 
  )    

convert a string text encoded with charset to UTF string

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

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

Note:
throws std::bad_cast if the loc does not haveinfofacet 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 
  )    

Convert a text in locale encoding given by loc to UTF

Note:
throws std::bad_cast if the loc does not haveinfofacet 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 
  )    

Convert a Unicode text in range [begin,end) to other Unicode encoding

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

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

简单示例:

1、between把 source 这个字串从BIG5 转换到 UTF-8:

    string source = "BIG5字符串";  string s = boost::locale::conv::between( source, "UTF-8", "BIG5" );  

2、to_utf可以输出 string ,也可以输出成 wstring。像下面的例子,就是把 sSource 这个 BIG-5 编码的字串,依序转换成 wstring 和 string 的字串。

    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 字串。

    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

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 之字符转换 gbk utf8 big5 string wstring等相关推荐

  1. boost库学习随记五 Boost.Locale 之字符转换 gbk utf8 big5 string wstring等

    Boost.Locale是一个库,它提供高质量的本地化的设施在C + +的方式.它最初是设计的一部分CppCMS - C + +的Web框架的项目,然后促成了提升. Boost.Locale提供强大的 ...

  2. 深入理解字符,字符集,gbk,utf8

    原创博客地址:深入理解字符,字符集,gbk,utf8 字符,字符集,字符编码概念 字节 1 字节(Byte)是计算机中数据存储的基本单元,一字节等于一个8位的比特,计算机中的所有数据,不论是保存在磁盘 ...

  3. 下载论坛源码GBK UTF8 BIG5分别是什么意思

    下载论坛源码GBK UTF8 BIG5分别是什么意思? 提问者:ly1987520 | 浏览次数:4010次 下载论坛源码简体中文GBK 简体中文UTF8 繁体中文BIG5 分别是什么意思?他们的区别 ...

  4. ASP字符转换:UTF-8与GB2312互转

    UTF-8转GB2312函数 <% '用途:將UTF-8編碼漢字轉換為GB2312碼,兼容英文和數字 '版權:雖說是原創,其實也參考了別人的部分算法 '用法:Response.write UTF ...

  5. 修改mysql默认字符集为latin1_MySQL字符集设置及字符转换(latin1转utf8)

    在生成环境中,会经常碰到Mysql字符的设置问题,个人也总结下. 如果在应用开始阶段没有正确的设置字符集,在运行一段时间以后才发现存在不能满足要求需要调整,那么就需要进行字符集的修改.字符集的修改不能 ...

  6. [mysql][ MySQL字符集设置及字符转换]

    [mysql][ MySQL字符集设置及字符转换] 标签(空格分隔): 未分类 在生成环境中,会经常碰到Mysql字符的设置问题,CU很多牛人都说过N次了,个人也总结下. 如果在应用开始阶段没有正确的 ...

  7. Qt中的字符编码转换:UTF8、Unicode、GBK、ASCII、16进制字符、16进制数值

    文章目录 前言 简述 ASCII GBK Unicode UTF-8 应用场景 开发环境 编码转换 16进制数值转换为16进制字符 16进制数值转化为字符串 16进制字符串转换为Unicode字符串 ...

  8. Linux C++ 乱码字符转换问题 GBK转UTF8

    本例来源于CSDN的另一篇博客,但并非是复读机.原博客使用char类型作为输入,需要传递src_len和dst_len,用起来比较难受.本文使用std::string做了封装,不需要传递src_len ...

  9. ASCII,unicode, utf8 ,big5 ,gb2312,gbk,gb18030等几种常用编码区别

    ASCII,unicode, utf8 ,big5 ,gb2312,gbk,gb18030等几种常用编码区别 最近老为编码问题而烦燥,下定决心一定要将其弄明白!本文主要总 结网上一些朋友提供的 asc ...

最新文章

  1. 与旷视、商汤等上百家企业同台竞技?AI Top 30+案例评选等你来秀!
  2. 超分辨率(super-resolution)VS解模糊(deblur)
  3. MYSQL 的 MASTER到MASTER的主主循环同步
  4. Oracle Enterprise Manager 11g: Empowering IT to Drive Business Value
  5. 见贤思齐焉,见不贤而内自省也
  6. C++对象内存模型学习
  7. MySQL基于SSL协议的主从复制
  8. java db类_Java-jdbc-DBUtils工具类介绍
  9. NYOJ 927 The partial sum problem 【DFS】+【剪枝】
  10. Python爬虫开发:requests库的使用--发送带参数get请求
  11. HDU-5119 Happy Matt Friends
  12. 【C语言】输入一个正整数,判断其是否为素数
  13. 对 Web 应用程序进行性能调优
  14. 分拆素数和【筛选法】
  15. 【转】VS2017的VSIX插件开发
  16. 编译C++11/14方法
  17. SSM SpringBoot vue教务排课系统
  18. jsp 展示服务器pdf文件,jsp实现pdf在线预览功能
  19. [附源码]计算机毕业设计Python新能源汽车租赁(程序+源码+LW文档)
  20. 优化算法系列-模拟退火算法(1)——基本原理枯燥版本

热门文章

  1. osg学习(四十八)Windows Error #2000
  2. 【25】数据可视化:基于 Echarts + Python Flask框架动态实时大屏范例 - 企业宣传
  3. AutoCAD.Net开发问题之:层表事件的响应(续)
  4. 树芯计划-ASIC数字IC设计讲解(1)连载中......
  5. css实现仿element ui配色的小圆圈状态标记
  6. 网页html通过隐藏域传送数据给web服务器
  7. 【Tomcat】tomcat9使用tomcat7-maven-plugin插件配置及其他一系列配置问题解决
  8. C语言数据结构【手抄版】第五章 树和二叉树【上篇】
  9. C++高阶 RAII机制(以对象管理资源)
  10. 天使的分裂【NOIP2016提高A组模拟9.24】