在属性文件中同时使用 \u.... 和 html 实体?
我偶然发现了一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是 - 请参阅 文档 了解
load(Reader)
,其中指出然后澄清
因此,绝对支持包含单个“u”字符的 Unicode 转义序列。
请注意,在加载 HTML 实体时没有发生任何特殊情况 - 例如,字符串
&
在 Java 中将被简单地视为包含 5 个字符的字符串。正如您所指出的,如果稍后将其输出到其他某个组件,则可能会以特殊方式进行解释。另一方面,转义序列
\u0061
在 Java 中将被视为单字符字符串“a”,并且与包含该字符的文件无法区分。Yes - see the documentation for
load(Reader)
, which statesand then clarifies that
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.\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