[erlang-questions] Unicode problems

eurekafag <>
Tue Nov 15 19:57:45 CET 2011


I'm trying to implement encoding detection and reencoding to utf-8
using erlang-iconv. Now I'm stuck with insane strings handling which
depends on -noinput parameter. Maybe it's a bug or I don't know
something. The code:

-module(test2).
-export([main/0]).

main() ->
    io:format("~ts~n",
[[1058,1077,1089,1090,1086,1074,1072,1103,32,1089,1090,1088,1086,1082,1072]]),
    io:format("~ts~n", ["Тестовая строка"]).

These lines should be the same but they don't. If I run this module like this:
erlc test2.erl; erl -run test2 main
I get:

Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:8:8] [rq:8]
[async-threads:0] [kernel-poll:false]

Тестовая строка
ТеÑÑÐ¾Ð²Ð°Ñ ÑÑÑока
Eshell V5.8.5  (abort with ^G)
1>
So the first line is displayed correctly but the second isn't. Then I
run the same compiled module like this:
erl -run test2 main -noinput
And suddenly it prints:
\x{422}\x{435}\x{441}\x{442}\x{43E}\x{432}\x{430}\x{44F}
\x{441}\x{442}\x{440}\x{43E}\x{43A}\x{430}
Тестовая строка
Now the second line worked as expected and the first failed. How
should I print unicode strings so they would look correctly with and
withount -noinput? What's the most correct way?



More information about the erlang-questions mailing list