在属性文件中同时使用 \u.... 和 html 实体?

发布于 2024-10-10 23:43:44 字数 241 浏览 5 评论 0原文

我偶然发现了一些 xxx_fr.properties、xxx_en.properties 等文件,我有点惊讶,因为它们同时包含 html 实体和 \uxxxx 转义。

我想只要这些资源提供给等待 HTML 的东西,HTML 实体就可以了,但是 \uxxxx 转义又如何呢?

Java 是否指定在 .properties 文件中可以进行 \uxxxx 转义?

I'm stumbling upon a few xxx_fr.properties, xxx_en.properties, etc. files and I'm a bit surprised for they contain both html entities and \uxxxx escapings.

I guess the HTML entities are fine as long as these resources are served to something awaiting HTML but what about the \uxxxx escaping?

Does Java specify that \uxxxx escaping are fine in .properties file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

灼痛 2024-10-17 23:43:44

是 - 请参阅 文档 了解 load(Reader),其中指出

键和元素中的字符可以是
以转义序列表示
类似于用于字符的那些
和字符串文字。

然后澄清

Unicode 转义序列中只允许使用单个“u”字符。

因此,绝对支持包含单个“u”字符的 Unicode 转义序列。

请注意,在加载 HTML 实体时没有发生任何特殊情况 - 例如,字符串 & 在 Java 中将被简单地视为包含 5 个字符的字符串。正如您所指出的,如果稍后将其输出到其他某个组件,则可能会以特殊方式进行解释。

另一方面,转义序列 \u0061 在 Java 中将被视为单字符字符串“a”,并且与包含该字符的文件无法区分。

Yes - see the documentation for load(Reader), which states

Characters in keys and elements can be
represented in escape sequences
similar to those used for character
and string literals.

and then clarifies that

Only a single 'u' character is allowed in a Unicode escape sequence.

Hence a Unicode escape sequence containing a single 'u' character is definitely supported.

Note that there's nothing special going on here at loading time with HTML entities - the String & for example would simply be seen within Java as a String containing 5 characters. As you point out, this might be interpreted in a special way if it were output to some other component later.

On the other hand, the escape sequence \u0061 would be seen within Java as the single-character string 'a', and would be indistinguishable from the file having contained that character instead.

寂寞笑我太脆弱 2024-10-17 23:43:44

\u 类型转义是表示 Unicode 字符的标准 Java 方式。您可以在 Java 国际化常见问题解答中阅读相关内容。对于“如何在属性文件中指定非 ASCII 字符串?”问题是您最感兴趣的问题:

http://java.sun.com/javase/technologies/core/basic/intl/faq.jsp#properties-escape

这不仅仅与属性相关;您也可以在典型的 Java 代码中使用它们。请参阅文本表示块:

http://java .sun.com/javase/technologies/core/basic/intl/faq.jsp#core-textrep

The \u type escaping is a standard Java way of representing Unicode characters. You can read about it in Java Internationalization FAQ. With "How do I specify non-ASCII strings in a properties file?" question being the one you're most interested in:

http://java.sun.com/javase/technologies/core/basic/intl/faq.jsp#properties-escape

And that's not Properties related only; you can use those in your typical Java code as well. See the Text Representation block:

http://java.sun.com/javase/technologies/core/basic/intl/faq.jsp#core-textrep

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文