Created
March 22, 2020 15:14
-
-
Save ufcpp/8f0e557e79ea33327c908de1c1d26ae3 to your computer and use it in GitHub Desktop.
Java のサロゲートペアのエスケープ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
int a\u200Db = 1; // 識別子中の ZWJ は無視される。 | |
System.out.println(ab); // なので ab と a\u200Db は同じ識別子。 | |
System.out.println(\u0061\u0062); // a (U+0061) とか b (U+0062) とかのエスケープも可能。ab と \u0061\u0062 も同じ識別子。 | |
int 𩸽 = 1; | |
System.out.println(\uD867\uDE3D); // 追加面文字はサロゲートペア2つのでエスケープ可能。𩸽 と \uD867\uDE3D も同じ識別子。 | |
// ちなみに、U+10000 以上の符号点を直接指定するエスケープ手段はないらしい。常にサロゲートペアで表現。 | |
// さすがに以下の行はコンパイルエラーになる。 | |
//System.out.println(\uD867\u200D\uDE3D); // 有効なサロゲートペアの間に ZWJ 挟んでみる。 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment