- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在新的 C++ 标准中找到
2.11 Identifiers [lex.name]
identifier:
identifier-nondigit
identifier identifier-nondigit
identifier digit
identifier-nondigit:
nondigit
universal-character-name
other implementation-defined character
附加文本
An identifier is an arbitrarily long sequence of letters and digits. Each universal-character-name in an identifier shall designate a character whose encoding in ISO 10646 falls into one of the ranges specified in E.1. [...]
我不太明白这是什么意思。例如,从我习惯的旧标准中,“通用字符名称”被写成 \u89ab
。但是在标识符中使用那些......?真的吗?
新标准是否对 Unicode 更开放?而且我没有提到新的文字类型 "uHello\u89ab thing"u32
,我想我理解了那些。但是:
\u1234
的标识符吗 myfu\u1234ntion
(无论什么目的)或者我可以使用 unicode 在 ICU 中定义的“字符名称”,即
const auto x = "German Braunb\U{LOWERCASE LETTER A WITH DIARESIS}r."u32;
或者甚至在源本身的标识符中?那将是一种享受……咳嗽……
我认为所有这些问题的答案都是否,但我无法将其可靠地映射到标准中的措辞...:-)
编辑:我找到“2.2 翻译阶段 [lex.phases]”,第 1 阶段:
Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set [...] if necessary. The set of physical source file characters accepted is implementation-defined. [...] Any source file character not in the basic source character set (2.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 (i.e., using the \uXXXX notation), are handled equivalently except where this replacement is reverted in a raw string literal.)
通过阅读本文,我现在认为,编译器可以选择接受 UTF-8、UTF-16 或它希望的任何代码页(通过元信息或用户配置)。在第 1 阶段,它将其转换为 ASCII 形式(“基本源字符集”),然后 Unicode 字符被其 \uNNNN
符号替换(或者编译器可以选择继续工作它的 Unicode 表示,但必须确保它以相同的方式处理其他 \uNNNN
。
你怎么看?
最佳答案
Is the new standard more open w.r.t to Unicode?
关于允许在标识符中使用通用字符名称,答案是否定的;在 C99 和 C++98 中,标识符中允许使用 UCN。然而,编译器直到最近才实现该特定要求。我认为 Clang 3.3 引入了对此的支持,并且 GCC 已经为此提供了一段时间的实验性功能。 Herb Sutter 在他的 Build 2013 演讲“C++ 的 future ”中也提到,此功能也将在某个时候出现在 VC++ 中。 (虽然 IIRC Herb 将其称为 C++11 功能;但实际上它是 C++98 功能。)
预计不会使用 UCN 编写标识符。相反,预期的行为是使用源编码写入所需的字符。例如,源将如下所示:
long pörk;
不是:
long p\u00F6rk;
然而,UCN 也可用于其他用途;并非所有编译器都需要接受相同的源代码编码,但现代编译器都支持一些编码方案,其中至少基本源字符具有相同的编码(也就是说,现代编译器都支持一些 ASCII 兼容编码)。
UCN 允许您编写仅包含基本字符的源代码,但仍然命名扩展字符。例如,这在将被编译为 CP1252 和 UTF-8 的源代码中写入字符串文字“°”时很有用:
char const *degree_sign = "\u00b0";
此字符串文字在多个编译器上被编码为适当的执行编码,即使源编码不同,只要编译器至少对基本字符共享相同的编码。
Can (portable) source code be in any unicode encoding, like UTF-8, UTF-16 or any (how-ever-defined) codepage?
标准没有要求,但大多数编译器会接受 UTF-8 源代码。 Clang 仅支持 UTF-8 源(尽管它对字符和字符串文字中的非 UTF-8 数据有一定的兼容性),gcc 允许指定源编码并包括对 UTF-8 的支持,而 VC++ 将猜测编码并可以猜测 UTF-8。
(更新:VS2015 现在提供一个 option 来强制源和执行字符集为 UTF-8。)
Can I write an identifier with \u1234 in it myfu\u1234ntion (for whatever purpose)
是的,规范规定了这一点,尽管正如我所说,并非所有编译器都实现了这一要求。
Or can i use the "character names" that unicode defines like in the ICU, i.e.
const auto x = "German Braunb\U{LOWERCASE LETTER A WITH DIARESIS}r."u32;
不,您不能使用 Unicode 长名称。
or even in an identifier in the source itself? That would be a treat... cough...
如果编译器支持包含您想要的扩展字符的源代码编码,那么在源代码中逐字写入的字符必须与等效的 UCN 完全相同。所以是的,如果您使用支持 C++ 规范这一要求的编译器,那么您可以直接在源代码中写入其源字符集中的任何字符,而无需费心编写 UCN。
关于C++11 中的 Unicode 标识符和源代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34526432/
我正在编写一个 Java 应用程序,该应用程序检查网页的源代码,并在满足源代码中的条件时在我的默认浏览器中向我显示该网页。我通过以下方式获取源代码: String source = getUrlSou
数周以来,我一直在为 Android 上的蓝牙项目而苦苦挣扎。有谁知道我可以去哪里查看 Google 用于使其蓝牙配对和连接逻辑正常工作的实际代码? 我浏览了所有的文档、BluetoothChat 应
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
Android 源代码有多个目录,其中包含针对不同设备的代码。此外,在特定目录中,存在显示不同分支和标签的路径。举个例子,在“android/platform/external/iptables”目录
在哪里可以找到 SQLMembershipProvider (.NET2.0) 的源代码? 是可用的么? 最佳答案 源代码已经发布。 See ScottGu's blog for further de
我只想知道如何下载特定版本的 Android 源代码。我已经尝试过以下命令 repo init -u https://android.googlesource.com/platform/manifes
我想看看OpenCL框架是如何实现的。我发现的只是已经编译好的可供下载的库。 当然,OpenCL 可以有许多不同的实现,但我想看看其中的一个来了解它是如何完成的。 为了确保我自己清楚,OpenCL 框
latex 源代码列表应该是什么样子才能产生像已知书籍中那样的输出,例如 Spring 框架的输出?我尝试过使用 latex 列表包,但无法生成看起来像下面一样好的东西。因此,我主要对生成类似以下示例
PHP 是用 C 语言编写的吗?我在哪里可以在线找到 PHP 源代码而无需下载全部内容? 最佳答案 PHP 函数是用 C 编写的 - 您可以在 lxr.php.net 找到可浏览的源代码. 例如:ht
我正在使用Elasticsearch OSS的官方Docker镜像(docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4),似乎完全无法使用s
我试图在Cython中同时编译C和C++源代码。这是我当前的设置: -setup.py from distutils.core import setup from Cython.Build impor
好吧,事情是这样的:你们所有人可能都在想同样的事情:您可以使用 driver.getPageSource(); 这部分是正确的。唯一的问题是源代码以一种相当奇怪的方式编译,所有代码都在其中 \&quo
由于 TwoLineListItem 自 API 17 起已被弃用,因此我已采取措施将其替换为自定义 XML 和 ViewHolder。但是,我真的希望我的应用程序看起来与使用 TwoLineList
要从 HttpURLConnection 获取 InputStream,我们的代码如下 urlConnection.getInputStream(); 如果InputStream是一个Abstract
我刚刚开始学习更多关于 C/C++ 的知识,我正在使用 Visual Studio 2013 来管理代码。 我正在使用 Tobii EyeX 眼睛注视系统的项目要求我能够稍微调整此代码,但是我不明白如
我在按钮上有一个IBAction,其中包含以下代码,我尝试使用它来检索 UIWebView 的源代码: - (IBAction)loadInAWebView:(id)sender { [self
我正在 asp.net 中创建一个网站,我只是想知道有什么方法可以使用 JavaScript 从图像生成调色板吗?类似于 1) http://www.cssdrive.com/imagepalette
有人可以分享 WinKill() from AutoIt 的源代码吗? ? 我想知道它如何处理消息(是/否/取消)以确保它得到正确处理。我想用它来清理桌面上的意外弹出窗口。 最佳答案 正如我们在下面的
我的问题与 Opencv 的源代码有关。在我看来不同的平台the Opencv website提供不同的代码结构。我只是想知道是否有可能为所有不同的平台提供一个源代码。使用相同的源代码,我可以针对不同
这个问题在这里已经有了答案: Convert Python program to C/C++ code? [closed] (8 个答案) 关闭 3 年前。 我一直在努力寻找一种方法将 .py 源文
我是一名优秀的程序员,十分优秀!