From ec8343bec35fcb941712a22cc0b150c5d24be2df Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Wed, 2 Jan 2013 14:59:02 +0100 Subject: [stdlib] Update the Unicode examples in STDLIB User's Guide --- lib/stdlib/doc/src/io.xml | 7 +++++-- lib/stdlib/doc/src/unicode_usage.xml | 18 +++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/stdlib/doc/src/io.xml b/lib/stdlib/doc/src/io.xml index 22cd45a482..e904f0f0c8 100644 --- a/lib/stdlib/doc/src/io.xml +++ b/lib/stdlib/doc/src/io.xml @@ -440,9 +440,12 @@ ok s -

Prints the argument with the string syntax. The +

Prints the argument with the string syntax. The argument is, if no Unicode translation modifier is present, an - iolist(), a binary, or an atom. If the Unicode translation modifier (t) is in effect, the argument is unicode:chardata(), meaning that binaries are in UTF-8. The characters + iolist(), a binary(), or an atom(). + If the Unicode translation modifier (t) is in effect, + the argument is unicode:chardata(), meaning that + binaries are in UTF-8. The characters are printed without quotes. The string is first truncated by the given precision and then padded and justified to the given field width. The default precision is the field width.

diff --git a/lib/stdlib/doc/src/unicode_usage.xml b/lib/stdlib/doc/src/unicode_usage.xml index 320b5b2e84..0a75fbeec0 100644 --- a/lib/stdlib/doc/src/unicode_usage.xml +++ b/lib/stdlib/doc/src/unicode_usage.xml @@ -5,7 +5,7 @@
1999 - 2012 + 2013 Ericsson AB. All Rights Reserved. @@ -163,10 +163,10 @@ Erlang R16B (erts-5.10) [source] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.10 (abort with ^G) 1> lists:keyfind(encoding, 1, io:getopts()). {encoding,unicode} -2> "уницоде" -"уницоде" +2> "Юникод" +"Юникод" 3> io:format("~ts~n", [v(2)]). -уницоде +Юникод ok 4>

While strings can be input as Unicode characters, the language elements are still limited to the ISO-latin-1 character set. Only character constants and strings are allowed to be beyond that range:

@@ -177,7 +177,7 @@ Erlang R16B (erts-5.10) [source] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.10 (abort with ^G) 1> $ξ 958 -2> уницоде. +2> Юникод. * 1: illegal character 2> @@ -305,10 +305,10 @@ $ erl Erlang R16B (erts-5.10) [source] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.10 (abort with ^G) -1> io_lib:format("~ts~n", ["θνιψοδε"]). -["θνιψοδε","\n"] -2> io:put_chars(io_lib:format("~ts~n", ["θνιψοδε"])). -θνιψοδε +1> io_lib:format("~ts~n", ["Γιούνικοντ"]). +["Γιούνικοντ","\n"] +2> io:put_chars(io_lib:format("~ts~n", ["Γιούνικοντ"])). +Γιούνικοντ ok

The Unicode string is returned as a Unicode list, which is recognized as such since the Erlang shell uses the Unicode encoding. The Unicode list is valid input to the io:put_chars/2 function, so data can be output on any Unicode capable device. If the device is a terminal, characters will be output in the \x{H ...} format if encoding is latin1 otherwise in UTF-8 (for the non-interactive terminal - "oldshell" or "noshell") or whatever is suitable to show the character properly (for an interactive terminal - the regular shell). The bottom line is that you can always send Unicode data to the standard_io device. Files will however only accept Unicode codepoints beyond ISO-latin-1 if encoding is set to something else than latin1.

-- cgit v1.2.3