C++0x 中有哪些新的 Unicode 函数?

发布于 2024-09-02 08:33:01 字数 445 浏览 3 评论 0原文

多个来源都提到 C++0x 将包含对 Unicode 更好的语言级支持(包括类型和文字)。

如果该语言要添加这些新功能,那么很自然地假设标准库也会添加这些新功能。 但是,我目前无法找到任何对新标准库的引用。我期望找到这些答案的答案:

  1. 新库是否提供将 UTF-8 转换为 UTF-16 等的标准方法?
  2. 新库是否允许将 UTF-8 写入文件、控制台(或从文件、控制台)。如果是这样,我们可以使用 cout 还是需要其他东西?
  3. 新库是否包含“基本”功能,例如:发现 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:

  1. Does the new library provide standard methods to convert UTF-8 to UTF-16, etc.?
  2. 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?
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月朦胧 2024-09-09 08:33:02

新库是否提供标准方法将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::toupperstd::towupper 当然功能与标准的早期版本一样。没有任何新函数专门为此在 unicode 上运行。

如果您需要这些类型的东西,您仍然必须依赖外部库 - 是经过改造的主要部分。

新标准中具体为 unicode 添加了哪些内容?

  • 的 u8""、u"" 和 U""
  • Unicode 文字,通过 UTF-8、UTF-16 和 UTF-32
  • mbrtoc16 ISO/IEC TR 19769:2004 std::codecvt 方面的 c16rtombmbrtoc32c32rtomb
  • 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 correctly

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?)
AFAIK that functionality exists with the existing C++03 standard. std::toupper and std::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?

  • Unicode literals, via u8"", u"", and U""
  • std::char_traits classes for UTF-8, UTF-16, and UTF-32
  • mbrtoc16, c16rtomb, mbrtoc32, and c32rtomb from ISO/IEC TR 19769:2004
  • std::codecvt facets for the locale library
  • The std::wstring_convert class template (which uses the codecvt mechanism for code set conversions)
  • The std::wbuffer_convert, which does the same as wstring_convert except for raw arrays, not strings.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文