Erlang 的 unicode 半截子工程

來源:互聯網
上載者:User

下載了新版的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。

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.