Using both \u.... and html entities in properties file?
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?
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.
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
精彩评论