3

I'm having a heck of a time trying to figure out how to use the Java interop in Clojure to normalize Unicode. I've been trying to to use java.text.Normalizer, but I keep getting ClassNotFoundException when trying to call the enum Normalizer.Form.NFD. Essentially, I'm just trying to do something like this in Java:

java.text.Normalizer.normalize("Ἑλλάς", java.text.Normalizer.Form.NFD);

I've been trying to do something like this in Clojure, but to no avail:

(import java.text.Normalizer)
(java.text.Normalizer/normalize "Ἑλλάς" java.text.Normalizer.Form/NFD)

Normalizer/normalize seems to be found ok, but getting at Normalizer.Form.NFD seems to be the problem as I keep getting the error:

Caused by java.lang.ClassNotFoundException java.text.Normalizer.Form

I'm working on Windows using: Clojure 1.8.0 and Java HotSpot(TM) 64-Bit Server VM 1.8.0_112-b15

I went ahead and tested it in regular Java and it works fine. So the class is installed on the system. Can anyone show me what I'm doing wrong here? Am I calling it incorrectly? Is there something else I need to import perhaps? Any advice is greatly appreciated.

file13
  • 71
  • 5

1 Answers1

5

This gives you trouble because Form is an inner class. In bytecode, a class outer.inner is actually represented as outer$inner. See more in this SO question, and this google group post.

(import java.text.Normalizer
        java.text.Normalizer$Form)
(java.text.Normalizer/normalize "Ἑλλάς" java.text.Normalizer$Form/NFD) ;; "Ἑλλάς"
Community
  • 1
  • 1
Shlomi
  • 4,708
  • 1
  • 23
  • 32
  • Thank you so much! Yes, this works exactly as needed. Unfortunately, I didn't think to search for "static inner java class" after banging my head against this. But in any case, thank you for the quick and clear response! – file13 Dec 19 '16 at 02:56
  • Glad I could help! if this answered your question, you should accept the answer :) – Shlomi Dec 19 '16 at 02:58
  • Done. Thank you again! – file13 Dec 19 '16 at 03:06