C++0x 中有哪些新的 Unicode 函数?
多个来源都提到 C++0x 将包含对 Unicode 更好的语言级支持(包括类型和文字)。
如果该语言要添加这些新功能,那么很自然地假设标准库也会添加这些新功能。 但是,我目前无法找到任何对新标准库的引用。我期望找到这些答案的答案:
- 新库是否提供将 UTF-8 转换为 UTF-16 等的标准方法?
- 新库是否允许将 UTF-8 写入文件、控制台(或从文件、控制台)。如果是这样,我们可以使用 cout 还是需要其他东西?
- 新库是否包含“基本”功能,例如:发现 UTF-8 字符串的字节数和长度、转换为大写/小写(这是否考虑区域设置的影响?
)函数在任何流行的编译器(例如 GCC 或 Visual Studio)中都可用吗?
我试图寻找信息,但似乎找不到任何东西。我实际上开始认为也许这些事情还没有决定(我知道 C++0x 是一项正在进行的工作)。
It has been mentioned in several sources that C++0x will include better language-level support for Unicode(including types and literals).
If the language is going to add these new features, it's only natural to assume that the standard library will as well.
However, I am currently unable to find any references to the new standard library. I expected to find out the answer for these answers:
- Does the new library provide standard methods to convert UTF-8 to UTF-16, etc.?
- Does the new library allowing writing UTF-8 to files, to the console (or from files, from the console). If so, can we use cout or will we need something else?
- Does the new library include "basic" functionality such as: discovering the byte count and length of a UTF-8 string, converting to upper-case/lower-case(does this consider the influence of locales?)
Finally, are any of these functions are available in any popular compilers such as GCC or Visual Studio?
I have tried to look for information, but I can't seem to find anything. I am actually starting to think that maybe these things aren't even decided yet(I am aware that C++0x is a work in progress).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
新库是否提供标准方法将UTF-8转换为UTF-16等?
不会。但是,新库确实提供了 std::codecvt 方面,可以在处理 iostream 时为您进行转换。 ISO/IEC TR 19769:2004(C Unicode 技术报告)几乎逐字包含在新标准中。
新库是否允许将 UTF-8 写入文件、控制台(或从文件、控制台)。如果是这样,我们可以使用 cout 还是需要其他东西?
是的,您只需为 cout 注入正确的
codecvt
方面即可。但请注意,控制台不需要正确显示这些字符新库是否包含“基本”功能,例如:发现 UTF-8 字符串的字节数和长度、转换为大写/小写(这是否考虑了地域的影响?)
AFAIK 该功能存在于现有的 C++03 标准中。
std::toupper
和std::towupper
当然功能与标准的早期版本一样。没有任何新函数专门为此在 unicode 上运行。如果您需要这些类型的东西,您仍然必须依赖外部库 -
是经过改造的主要部分。新标准中具体为 unicode 添加了哪些内容?
mbrtoc16
ISO/IEC TR 19769:2004std::codecvt
方面的c16rtomb
、mbrtoc32
和c32rtomb
std::char_traits
类,区域设置的 库std::wstring_convert
类模板(使用codecvt
机制进行代码集转换)std::wbuffer_convert
,执行相同的操作与wstring_convert
相同,但原始数组除外,而不是字符串。Does the new library provide standard methods to convert UTF-8 to UTF-16, etc.?
No. The new library does provide
std::codecvt
facets which do the conversion for you when dealing with iostream, however. ISO/IEC TR 19769:2004, the C Unicode Technical Report, is included almost verbatim in the new standard.Does the new library allowing writing UTF-8 to files, to the console (or from files, from the console). If so, can we use cout or will we need something else?
Yes, you'd just imbue cout with the correct
codecvt
facet. Note however that the console is not required to display those characters correctlyDoes the new library include "basic" functionality such as: discovering the byte count and length of a UTF-8 string, converting to upper-case/lower-case(does this consider the influence of locales?)
AFAIK that functionality exists with the existing C++03 standard.
std::toupper
andstd::towupper
of course function just as in previous versions of the standard. There aren't any new functions which specifically operate on unicode for this.If you need these kinds of things, you're still going to have to rely on an external library -- the
<iostream>
is the primary piece that was retrofitted.What, specifically, is added for unicode in the new standard?
std::char_traits
classes for UTF-8, UTF-16, and UTF-32mbrtoc16
,c16rtomb
,mbrtoc32
, andc32rtomb
from ISO/IEC TR 19769:2004std::codecvt
facets for the locale librarystd::wstring_convert
class template (which uses thecodecvt
mechanism for code set conversions)std::wbuffer_convert
, which does the same aswstring_convert
except for raw arrays, not strings.