2011年3月10日木曜日

Erlang atom_to_binaryを訳す

atom_to_binary(Atom, Encoding) -> binary()
Types:
Atom = atom()
Encoding = latin1 | utf8 | unicode

実験結果:

1> atom_to_binary('Erlang',latin1).
<<"Erlang">>
2> atom_to_binary('Erlang',utf8).
<<"Erlang">>
3> atom_to_binary('Erlang',unicode).
<<"Erlang">>

4> atom_to_binary('»',latin1).
<<"»">>
5> atom_to_binary('ア',latin1).
* 1: illegal character
5> ',latin1).
5> atom_to_binary('ア',latin1).
* 2: illegal character
5> ',latin1).
5>


以下Erlangのドキュメントに書いてある文章の訳です。

Returns a binary which corresponds to the text representation of Atom.
(アトムのテキスト表現に一致したバイナリを返す)

If Encoding is latin1, there will be one byte for each character in the text representation.
(もし、latin1であれば、テキスト表現内の各文字は1バイト)

If Encoding is utf8 or unicode, the characters will encoded using UTF-8
 (meaning that characters from 16#80 up to 0xFF will be encode in two bytes).
(もし、utf8もしくはunicodeなら、utf8にエンコードされる。
つまり、各文字(ASCIIコード表参照)が16進数で80からFFまで(10進数表記で128から255まで)のものは2バイトでエンコードされる)


これにはNoteってやつがあるので、ここも訳す。


Note:
(参考)
Currently, atom_to_binary(Atom, latin1) can never fail because the text representation of an atom can only contain characters from 0 to 16#FF.
(現在、atom_to_binary(Atom, latin1)は落ちることがない。なぜなら、アトムのテキスト表現は16進数で0からFFの文字だけ含んでいるから)

 In a future release,
(将来的に)

the text representation of atoms might be allowed to
contain any Unicode character and atom_to_binary(Atom, latin1) will fail if the text representation
for the Atom contains a Unicode character greater than 16#FF.

(アトムのテキスト表現はUnicode文字が含まれても許容される。またatom_to_binary(Atom, latin1)は16進数表記でFF以上のUnicode文字が含まれても落ちないようになる。)

0 件のコメント:

コメントを投稿