Now that I know for sure how to bind *out* to something else over
System/out, it's time to bring back my encoding issues into scope:
(import '(java.io PrintWriter PrintStream))
(defmacro with-out-encoded
[encoding & body]
`(binding [*out* (java.io.PrintWriter. (java.io.PrintStream.
System/out true ~encoding) true)]
~...@body
(flush)))
(def nc "ISO-8859-1")
;;; with a normal string
(def s "québécois français")
(print s)
; quÔøΩbÔøΩcois franÔøΩaisnil
(with-out-encoded nc (print s))
; qu?b?cois fran?aisnil
;;; with a correctly-encoded string
(def snc (String. (.getBytes s nc) nc))
(print snc)
; qu?b?cois fran?aisnil
(with-out-encoded nc (print snc))
; qu?b?cois fran?aisnil
I'm certainly missing something fundamental somewhere.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---