下載了新版的Erlang/OTP R13B,重點試了試新增的unicode支援和wxErlang。
不象一些中文介紹說的那樣樂觀,我的測試結果不太好。
unicode的支援,只解決了eshell裡的問題,即在erl和werl這兩個工具中,已經能夠正確解碼,io:format已經支援多位元組編碼。
編譯器erlc仍然不支援多位元組unicode,使用者程式編譯後,無法簡便地顯示多位元組unicode。
測試結果如下:
一、eshell的表現
Eshell V5.7.1 (abort with ^G)
1> unicode:characters_to_list("中文視窗").
[20013,25991,31383,21475]
2>
2> S = unicode:characters_to_list("中文視窗").
[20013,25991,31383,21475]
3>
3> io:format("~ts~n",[S]).
中文視窗
ok
4> io:write(S).
[20013,25991,31383,21475]ok
5>
二、erlc編譯器的表現
先看個簡單的。
%% chinese.erl
-module(chinese).-export([start/0]).
start() ->
Title=unicode:characters_to_list("中文視窗"),
io:write(Title),
io:format("~n~n~s~n~n",[Title]),
1> c(chinese).
2> chinese:start().
[214,208,206,196,180,176,191,218]
中文視窗
這裡,雖然顯示出了“中文視窗”四個字,但沒有正確解碼成多位元組編碼[20013,25991,31383,21475],當使用GUI介面時,中文還是顯示成亂碼。
三、在wxErlang中的表現
將erl5.7.1/lib/wx-0.98.1/examples/simple/hello.erl稍作改動:
create_window(Wx) ->
Title=unicode:characters_to_list("中文視窗"),
io:write(Title),
io:format("~n~n~s~n~n",[Title]),
T=[20013,25991,31383,21475],
Frame = wxFrame:new(Wx,
-1, % window id
T, % window title
[{size, {600,400}}]),
……
在eshell中顯示的是:
[214,208,206,196,180,176,191,218]
ÖÐÎÄ´°¿Ú
而在程式視窗的標題上,將unicode [20013,25991,31383,21475] 正確顯示為“中文視窗”。
總之,在eshell中,可用unicode:characters_to_list("中文視窗"),解析成[20013,25991,31383,21475],這是GUI顯示時所需要的。
但是,程式經erlc編譯後,將其解析成[214,208,206,196,180,176,191,218],無法正確顯示。
Erlang的程式編譯器erlc需要改進,以全面支援unicode。