From 4b42bf9358eca2c4597837e87dd10e49c1b60bc7 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Fri, 28 Dec 2012 10:28:16 +0100 Subject: Clean up some of the Unicode documentation --- lib/stdlib/doc/src/unicode.xml | 71 ++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 34 deletions(-) (limited to 'lib/stdlib/doc/src/unicode.xml') diff --git a/lib/stdlib/doc/src/unicode.xml b/lib/stdlib/doc/src/unicode.xml index 1f6cbaccd7..d235f3e180 100644 --- a/lib/stdlib/doc/src/unicode.xml +++ b/lib/stdlib/doc/src/unicode.xml @@ -32,9 +32,9 @@ unicode Functions for converting Unicode characters -

This module contains functions for converting between different character representations. Basically it converts between iso-latin-1 characters and Unicode ditto, but it can also convert between different Unicode encodings (like UTF-8, UTF-16 and UTF-32).

+

This module contains functions for converting between different character representations. Basically it converts between ISO-latin-1 characters and Unicode ditto, but it can also convert between different Unicode encodings (like UTF-8, UTF-16 and UTF-32).

The default Unicode encoding in Erlang is in binaries UTF-8, which is also the format in which built in functions and libraries in OTP expect to find binary Unicode data. In lists, Unicode data is encoded as integers, each integer representing one character and encoded simply as the Unicode codepoint for the character.

-

Other Unicode encodings than integers representing codepoints or UTF-8 in binaries are referred to as "external encodings". The iso-latin-1 encoding is in binaries and lists referred to as latin1-encoding.

+

Other Unicode encodings than integers representing codepoints or UTF-8 in binaries are referred to as "external encodings". The ISO-latin-1 encoding is in binaries and lists referred to as latin1-encoding.

It is recommended to only use external encodings for communication with external entities where this is required. When working inside the Erlang/OTP environment, it is recommended to keep binaries in UTF-8 when representing Unicode characters. Latin1 encoding is supported both for backward compatibility and for communication with external entities not supporting Unicode character sets.

@@ -48,13 +48,13 @@ -

A binary() with characters encoded in the UTF-8 coding standard.

+

A binary() with characters encoded in the UTF-8 coding standard.

-

An integer() representing a valid unicode codepoint.

+

An integer() representing a valid Unicode codepoint.

@@ -63,7 +63,7 @@ -

A unicode_binary is allowed as the tail of the list.

+

A unicode_binary() is allowed as the tail of the list.

@@ -85,7 +85,7 @@ -

A binary() with characters coded in iso-latin-1.

+

A binary() with characters coded in ISO-latin-1.

@@ -110,7 +110,9 @@ Identify UTF byte order marks in a binary. - A binary() of byte_size 4 or more. + + A binary() such that byte_size(Bin) >= 4. +

Check for a UTF byte order mark (BOM) in the beginning of a @@ -126,7 +128,7 @@ Convert a collection of characters to list of Unicode characters -

Same as characters_to_list(Data,unicode).

+

Same as characters_to_list(Data, unicode).

@@ -134,8 +136,8 @@ Convert a collection of characters to list of Unicode characters -

This function converts a possibly deep list of integers and - binaries into a list of integers representing unicode +

Converts a possibly deep list of integers and + binaries into a list of integers representing Unicode characters. The binaries in the input may have characters encoded as latin1 (0 - 255, one character per byte), in which case the InEncoding parameter should be given as @@ -148,18 +150,18 @@

If InEncoding is latin1, the Data parameter corresponds to the iodata() type, but for unicode, the Data parameter can contain integers greater than 255 - (unicode characters beyond the iso-latin-1 range), which would + (Unicode characters beyond the ISO-latin-1 range), which would make it invalid as iodata().

The purpose of the function is mainly to be able to convert - combinations of unicode characters into a pure unicode + combinations of Unicode characters into a pure Unicode string in list representation for further processing. For writing the data to an external entity, the reverse function characters_to_binary/3 + marker="#characters_to_binary/3">characters_to_binary/3 comes in handy.

-

The option unicode is an alias for utf8, as this is the +

The option unicode is an alias for utf8, as this is the preferred encoding for Unicode characters in binaries. utf16 is an alias for {utf16,big} and utf32 is an alias for {utf32,big}. The big @@ -167,7 +169,7 @@ encoding.

If for some reason, the data cannot be converted, either - because of illegal unicode/latin1 characters in the list, or + because of illegal Unicode/latin1 characters in the list, or because of invalid UTF encoding in any binaries, an error tuple is returned. The error tuple contains the tag error, a list representing the characters that could be @@ -176,7 +178,7 @@ last part is mostly for debugging as it still constitutes a possibly deep and/or mixed list, not necessarily of the same depth as the original data. The error occurs when traversing the - list and whatever's left to decode is simply returned as is.

+ list and whatever is left to decode is simply returned as is.

However, if the input Data is a pure binary, the third part of the error tuple is guaranteed to be a binary as @@ -191,7 +193,7 @@ of a Unicode type, an error occurs whenever an integer greater than 16#10FFFF - (the maximum unicode character), + (the maximum Unicode character), in the range 16#D800 to 16#DFFF (invalid range reserved for UTF-16 surrogate pairs) @@ -205,14 +207,14 @@ (like the upper bits of the bytes being wrong), the bytes are decoded to a too large number, the bytes are decoded to a code-point in the - invalid unicode - range or encoding is "overlong", meaning that a + invalid Unicode + range, or encoding is "overlong", meaning that a number should have been encoded in fewer bytes. The case of a truncated UTF is handled specially, see the paragraph about incomplete binaries below. If InEncoding is latin1, binaries are always valid as long as they contain whole bytes, - as each byte falls into the valid iso-latin-1 range. + as each byte falls into the valid ISO-latin-1 range. @@ -250,7 +252,7 @@ ever be decoded.

If any parameters are of the wrong type, the list structure - is invalid (a number as tail) or the binaries does not contain + is invalid (a number as tail) or the binaries do not contain whole bytes (bit-strings), a badarg exception is thrown.

@@ -258,28 +260,27 @@
- Convert a collection of characters to an UTF-8 binary + Convert a collection of characters to a UTF-8 binary -

Same as characters_to_binary(Data, unicode, unicode).

+

Same as characters_to_binary(Data, unicode, unicode).

- Convert a collection of characters to an UTF-8 binary + Convert a collection of characters to a UTF-8 binary -

Same as characters_to_binary(Data, InEncoding, unicode).

+

Same as characters_to_binary(Data, InEncoding, unicode).

- Convert a collection of characters to an UTF-8 binary + Convert a collection of characters to a UTF-8 binary -

This function behaves as - characters_to_list/2, but produces an binary - instead of a unicode list. The +

Behaves as + characters_to_list/2, but produces an binary + instead of a Unicode list. The InEncoding defines how input is to be interpreted if binaries are present in the Data, while OutEncoding defines in what format output is to be @@ -294,7 +295,7 @@

Errors and exceptions occur as in - characters_to_list/2, but the second element + characters_to_list/2, but the second element in the error or incomplete tuple will be a binary() and not a list().

@@ -304,16 +305,18 @@ Create a binary UTF byte order mark from encoding. - A binary() of byte_size 4 or more. + + A binary() such that byte_size(Bin) >= 4. + -

Create an UTF byte order mark (BOM) as a binary from the +

Create a UTF byte order mark (BOM) as a binary from the supplied InEncoding. The BOM is, if supported at all, expected to be placed first in UTF encoded files or messages.

The function returns <<>> for the - latin1 encoding, there is no BOM for ISO-latin-1.

+ latin1 encoding as there is no BOM for ISO-latin-1.

It can be noted that the BOM for UTF-8 is seldom used, and it is really not a byte order mark. There are obviously no -- cgit v1.2.3