Am 06.03.2009 um 23:31 schrieb max3000:
> I'm trying to output accented characters from clojure. Actually, I'm
> trying to call setToolTipText on a JComponent with some unicode
> string. No problems doing so from Java, but with clojure I'm hitting a
> wall.
>
> In REPL:
> exmentis=> "àéôö"
> "&→∟↔"
> exmentis=> \u00f4
> \├┤
> exmentis=> \u00c0
> \À
Clojure
user=> "àéñî"
"àéñî"
Works For Me(tm).
> Ok, so the Reader doesn't read my input correctly, right?
No. I think it reads it correctly.
> jline.ConsoleRunner
I got a bit weird behaviour with jline.ConsoleRunner.
Try without it. That worked for me.
Sincerely
Meikel
Hi Max,
Please tell us a bit about your environment (locale settings, OS). It
looks to me like your settings are different from UTF-8 and the reason
why the above procedure works is because Java will use the default
character set when decoding your source file. Within Java (or Clojure)
you can get the default character set with:
(java.nio.charset.Charset/defaultCharset)
which in my case produces #<UTF_8 UTF-8>. If you are using a different
character set (e.g. ISO-8859-1), some characters can not be mapped
directly between this and UTF-8. While I am not aware of any explicit
requirements regarding Clojure source file encodings, it seems that de
facto UTF-8 is assumed. Try encoding your sources as UTF-8 and things
should work as expected.
Cheers,
Toralf
What happens if you do this:
;; untested
(binding [*in* (new LineNumberingPushbackReader (new InputStreamReader
System/in))
*out* (new OutputStreamWriter System/out)]
(your-code-here))
--
Michael Wood <esio...@gmail.com>
max3000 a écrit :
> The default character set on WinXP (which I use) is windows-1252
> (cp1252). Check out http://www.rgagnon.com/javadetails/java-0505.html.
>
> If I were to change my source file encodings to UTF-8 that would
> probably get me some mileage. Of course, I would have to use an editor
> that supports it and not all editors would (on windows). However, it
> wouldn't change anything in the REPL. Presumably, stdin in Java is
> tied to the platform's default encoding and there is probably no way
> to change that. My understanding is that clojure assumes reading a
> file and reading stdin is the same thing encoding-wise. That's a
> faulty assumption.
>
I think that forcing source files to be UTF-8 is a good thing when
sharing code.
On the subject of the REPL, what about adding a property (eg
"clojure.repl.encoding") to override the default? (I'm still ambivalent
on this subject: I don't know which default (utf-8 or plaftorm) is best.)
Christophe
--
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (en)