gpt4 book ai didi

c++ - C++ 编译器可以规范化 Unicode 标识符吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:27:36 26 4
gpt4 key购买 nike

在 C++ 中,我们可以在标识符中使用各种 Unicode 字符。例如,您可以将变量命名为 résumé

那些带重音的 e 可以用不同的方式表示:作为预组合字符或作为带有组合重音字符的普通 e。许多应用normalize这样的字符串,以便看似相同的字符串实际上匹配。

查看 C++ 标准,我没有看到任何要求编译器规范化标识符的内容,因此变量 résumé 可能不同于变量 résumé。 (在我的测试中,似乎 MSVC 和 clang 都没有规范化标识符。)

是否有什么禁止编译器选择范式?如果不是,在什么地方 phase of translation应该规范化吗?

[明确一点:我说的是标识符,而不是字符串文字。]

最佳答案

我相信编译器被允许在翻译阶段 1 中执行此规范化:

Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set (introducing new-line characters for end-of-line indicators) if necessary. The set of physical source file characters accepted is implementation-defined. Any source file character not in the basic source character set (5.3) is replaced by the universal-character-name that designates that character. An implementation may use any internal encoding, so long as an actual extended character encountered in the source file, and the same extended character expressed in the source file as a universal-character-name (e.g., using the \uXXXX notation), are handled equivalently except where this replacement is reverted (5.4) in a raw string literal.

由于源文件字符到基本源字符集和通用字符名称的映射是实现定义的,实现可以选择转换表示预组合或分解的小写字母 e-with-acute-accent 的任何字节序列相同的通用字符名称,但必须记录此选择。

关于c++ - C++ 编译器可以规范化 Unicode 标识符吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54715563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com