문제

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