質問

Is there a library that is able to parse Unicode domain name into IDNA? Like שלום.com ==> http://xn--9dbne9b.com/ ?

役に立ちましたか?

解決

java.net.IDN seems to do the trick. From my Scala console:

scala> java.net.IDN.toUnicode("xn--9dbne9b.com")
res0: java.lang.String = שלום.com

Note that it works on the hostname, not the URL. So you'll have to strip/extract the http:// protocol first.

A quick glance at the documentation reveals it works in the opposite direction too. From above (my Unicode hostname in the variable res0)

scala> java.net.IDN.toASCII(res0)
res3: java.lang.String = xn--9dbne9b.com
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top