简体   繁体   English

Java中的转义Unicode转义

[英]Escape unicode escaping in Java

I'm writing Javadoc for a class explaining proper unicode escaping: 我正在为解释正确的Unicode转义的类编写Javadoc:

 * String unitAbbrev = "μs"; //Best: perfectly clear even without a comment.
 * String unitAbbrev = "\u03bcs"; //Poor: the reader has no idea what this is.

Unfortunately they both render with "μs": 不幸的是,它们都使用“μs”进行渲染:

在此处输入图片说明

Is there any way to escape this unicode escape? 有什么办法可以逃脱这种unicode逃逸吗?

Double backslash ( "\\\μs" ) doesn't work: 双反斜杠( "\\\μs" )不起作用:

在此处输入图片说明

Try putting the escaped Unicode literal for the backslash itself, I think: 我想尝试将转义的Unicode文字放在反斜杠本身上,我认为:

\\ \\ u005c

You can alternatively use the HTML escape \ 您也可以使用HTML转义符\ , which still isn't great when read from source, but it's at least clearly not a unicode escape. ,从源代码读取时仍然不是很好 ,但是至少不是 unicode转义。

The only disadvantage of HTML escapes is they don't work inside {@code ...} blocks (they're rendered verbatim), so you need to use <pre> and <code> instead. HTML转义的唯一缺点是它们无法在{@code ...}块内工作(它们被逐字显示),因此您需要使用<pre><code>代替。

It seems like \\\\ should work as javac appears to handle it correctly, but javadoc isn't. 似乎\\\\ 应该可以正常工作,因为javac似乎可以正确处理它,但是javadoc却不能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM