注释非法 Unicode 序列

发布于 2024-09-27 14:04:17 字数 527 浏览 3 评论 0原文

我曾经开发过一个处理 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 技术交流群。

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

发布评论

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

评论(2

苍景流年 2024-10-04 14:04:17

您可以通过在反斜杠后插入空格字符来解决此问题:

//char someCharacter = "\ ux13d";

You could work around it by inserting a space char after the backslash:

//char someCharacter = "\ ux13d";
孤独陪着我 2024-10-04 14:04:17

当需要使用 PHP 代码将某些内容(例如整数值)嵌入到 Javascript 中时,有时会发生这种情况,并且需要临时注释一些非法值,但 PHP 仍然给出错误,因为 PHP 代码在 JS 代码生成之前运行并被视为注释。

通常我会做类似的事情

class UnicodeTester{
//char someCharacter = "\\ux13d";  // illegal
}

,以便稍后我仍然可以 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

class UnicodeTester{
//char someCharacter = "\\ux13d";  // illegal
}

so that I can still grep for \u later on or grep for illegal.

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