注释非法 Unicode 序列
我曾经开发过一个处理 unicode 处理的 Java 应用程序 - 像往常一样,我首先编写一些代码并对其进行测试,然后注释掉工作代码并添加一些新行。这个过程一直持续到我找到解决方案
我遇到的确切问题是注释掉非法的 Unicode 字符串。有些 unicode 不起作用,我想将其注释掉......令我大吃一惊的是,它不起作用。
示例代码:
class UnicodeTester{
//char someCharacter = "\ux13d";
}
javac UnicodeTester.java
UnicodeTester.java:2: illegal unicode escape
//char someCharacter = "\ux13d";
^
1 error
有没有办法可以注释掉非法的 unicode 序列?我阅读了 Java 语言规范 2.2 & 2.3、词汇语法先于句法语法执行。时期。但是除了从源代码中删除它们之外,最有效的解决方法是什么?
I was once working on a Java application dealing with unicode processing - and as usual to begin with, I write some code and test it, then comment out the working code and add some new lines., and this process goes on till I find the solution
The exact issue I had was commenting out illegal Unicode strings. Some unicode wasn't working and I wanted to just comment it out.. to my utter surprise, it wouldn't work.
Example Code:
class UnicodeTester{
//char someCharacter = "\ux13d";
}
javac UnicodeTester.java
UnicodeTester.java:2: illegal unicode escape
//char someCharacter = "\ux13d";
^
1 error
Is there a way where I can comment out illegal unicode sequences?? I read the Java Language Specification 2.2 & 2.3, The Lexical Grammar is enforced before the Syntactic Grammar. PERIOD. But what is the most effective workaround other than removing them from the source code??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过在反斜杠后插入空格字符来解决此问题:
You could work around it by inserting a space char after the backslash:
当需要使用 PHP 代码将某些内容(例如整数值)嵌入到 Javascript 中时,有时会发生这种情况,并且需要临时注释一些非法值,但 PHP 仍然给出错误,因为 PHP 代码在 JS 代码生成之前运行并被视为注释。
通常我会做类似的事情
,以便稍后我仍然可以 grep 查找
\u
或 grep 查找illegal
。This sometimes happens when needing to embed something using PHP code into Javascript, such as an integer value, and need to comment some illegal value temporarily but PHP still gives error because the PHP code is run before the JS code is generated and as treated as comment.
Usually I do something like
so that I can still grep for
\u
later on or grep forillegal
.