[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ddlm-group] options/text vs binary/end-of-line. .. .. .. .

Here is an issue to consider:

If we impose a non-text canonical UTF-8 encoding that does not contain an
internal encoding signature, and that file is transmitted as text and
not binary from a machine for which, say, ASCII with code pages for, say,
western europe, is the native encoding, and the transmission converts
the UTF-8 charcaters as if they were accented characters in Latin-1,
then what is received may appear plausible at the receiving end, just 
wrong.

Therefore, I would suggest that we be very careful to make such a 
canonical UTF-8 cif self identifying, by including not only a BOM,
but by adding some text in the range of #x128-#x254 to the magic
number to help in detecting such unintended transmission conversions.

In addition, I would suggest that, just as the first line of an XML
document specifies its encoding in plain text, that we add the same
information to our magic number.

I would suggest carefully reading the XML specification on this subject
and that we try to follow the approach taken.  It is well-supported
by a great deal of existing software.  If we follow a similar approach,
we should avoid any offense in what is clearly a very touchy issue.

4.3.3 Character Encoding in Entities

Each external parsed entity in an XML document may use a different 
encoding for its characters. All XML processors MUST be able to read 
entities in both the UTF-8 and UTF-16 encodings. The terms "UTF-8" and 
"UTF-16" in this specification do not apply to related character 
encodings, including but not limited to UTF-16BE, UTF-16LE, or CESU-8.

Entities encoded in UTF-16 MUST and entities encoded in UTF-8 MAY begin 
with the Byte Order Mark described by Annex H of [ISO/IEC 10646:2000], 
section 16.8 of [Unicode] (the ZERO WIDTH NO-BREAK SPACE character, 
#xFEFF). This is an encoding signature, not part of either the markup or 
the character data of the XML document. XML processors MUST be able to use 
this character to differentiate between UTF-8 and UTF-16 encoded 
documents.

If the replacement text of an external entity is to begin with the 
character U+FEFF, and no text declaration is present, then a Byte Order 
Mark MUST be present, whether the entity is encoded in UTF-8 or UTF-16.

Although an XML processor is required to read only entities in the UTF-8 
and UTF-16 encodings, it is recognized that other encodings are used 
around the world, and it may be desired for XML processors to read 
entities that use them. In the absence of external character encoding 
information (such as MIME headers), parsed entities which are stored in an 
encoding other than UTF-8 or UTF-16 MUST begin with a text declaration 
(see 4.3.1 The Text Declaration) containing an encoding declaration:
Encoding Declaration
[80]   	EncodingDecl	   ::=   	S 'encoding' Eq ('"' EncName '"' | 
"'" EncName "'" )
[81]   	EncName	   ::=   	[A-Za-z] ([A-Za-z0-9._] | '-')*	/* 
Encoding name contains only Latin characters */

In the document entity, the encoding declaration is part of the XML 
declaration. The EncName is the name of the encoding used.

In an encoding declaration, the values " UTF-8 ", " UTF-16 ", " 
ISO-10646-UCS-2 ", and " ISO-10646-UCS-4 " SHOULD be used for the various 
encodings and transformations of Unicode / ISO/IEC 10646, the values " 
ISO-8859-1 ", " ISO-8859-2 ", ... " ISO-8859- n " (where n is the part 
number) SHOULD be used for the parts of ISO 8859, and the values " 
ISO-2022-JP ", " Shift_JIS ", and " EUC-JP " SHOULD be used for the 
various encoded forms of JIS X-0208-1997. It is RECOMMENDED that character 
encodings registered (as charsets) with the Internet Assigned Numbers 
Authority [IANA-CHARSETS], other than those just listed, be referred to 
using their registered names; other encodings SHOULD use names starting 
with an "x-" prefix. XML processors SHOULD match character encoding names 
in a case-insensitive way and SHOULD either interpret an IANA-registered 
name as the encoding registered at IANA for that name or treat it as 
unknown (processors are, of course, not required to support all 
IANA-registered encodings).

In the absence of information provided by an external transport protocol 
(e.g. HTTP or MIME), it is a fatal error for an entity including an 
encoding declaration to be presented to the XML processor in an encoding 
other than that named in the declaration, or for an entity which begins 
with neither a Byte Order Mark nor an encoding declaration to use an 
encoding other than UTF-8. Note that since ASCII is a subset of UTF-8, 
ordinary ASCII entities do not strictly need an encoding declaration.

It is a fatal error for a TextDecl to occur other than at the beginning of 
an external entity.

It is a fatal error when an XML processor encounters an entity with an 
encoding that it is unable to process. It is a fatal error if an XML 
entity is determined (via default, encoding declaration, or higher-level 
protocol) to be in a certain encoding but contains byte sequences that are 
not legal in that encoding. Specifically, it is a fatal error if an entity 
encoded in UTF-8 contains any ill-formed code unit sequences, as defined 
in section 3.9 of Unicode [Unicode]. Unless an encoding is determined by a 
higher-level protocol, it is also a fatal error if an XML entity contains 
no encoding declaration and its content is not legal UTF-8 or UTF-16.

Examples of text declarations containing encoding declarations:

<?xml encoding='UTF-8'?>
<?xml encoding='EUC-JP'?>



=====================================================
  Herbert J. Bernstein, Professor of Computer Science
    Dowling College, Kramer Science Center, KSC 121
         Idle Hour Blvd, Oakdale, NY, 11769

                  +1-631-244-3035
                  yaya@dowling.edu
=====================================================

On Wed, 23 Jun 2010, Bollinger, John C wrote:

>
> On Wednesday, June 23, 2010 5:33 AM, Brian McMahon wrote:
>
> [...]
>
>> Expecting every CIF application to be robustly able to handle every
>> conceivable - or even every reasonable - encoding is (what's the
>> word?) "optimistic", and places a heavy burden on application
>> developers.
>
> I thought you were an optimist?  :-)
>
> Indeed, I agree that such an expectation would be optimistic in the extreme, and I don't think anyone has been advocating such a requirement.
>
>> Consider instead the approach of defining the CIF standard as a
>> text file and using UTF-8 for a "canonical" description of low-level
>> representations. Supply a set of such canonical CIFs in the
>> next-generation trip test suite. Require a "compliant" CIF
>> application to handle the trip tests with the canonical encoding.
>> Permit - indeed encourage - applications developers to accommodate
>> other encodings to the extent they can easily do with their standard
>> text-processing libraries/utilities/tools. Encourage or perhaps
>> commission a "canonicalisation" suite for use in contexts where
>> an application cannot natively handle a submitted encoding.
>
> [...]
>
>> This isn't a radical new suggestion; it seems to me to encapsulate
>> many of the points of common ground around which we're still
>> negotiating our points of principle or philosophy, but I would hope it
>> can help us to move forward.
>
> That satisfactorily captures the key points I have been pursuing.  With only a bit of tweaking, the "CIF Interchange Format" proposal I floated would serve this end nicely.  Alternatively, the same end could be reached by couching the requirement in terms of a "canonical" encoding, more along the lines of Brian's text above:
>
> 1. In "TERMINOLOGY", insert a new first paragraph:
> ====
> Reference to characters means numeric code points in the Unicode code space.  Where Unicode has assigned 'abstract characters' to specific code points, those code points may sometimes be referred to by the Unicode-assigned name or a colloquial equivalent.  Otherwise, they are referred to according to Unicode convention, U+[[x]x]xxxx, where [[x]x]xxxx is the four- to six-digit hexadecimal representation of the code point value.
> ====
>
> 2. Change the heading "CHANGE 2 - NEW (ENCODING)" to "CHANGE 2 - NEW (CHARACTER SET)".
>
> 3. Replace the first paragraph in the CHANGE 2 section with:
> ====
> CIF2 files are variable-length Unicode text files, but for historical reasons will have a maximum record length of 2048 characters.  As described in detail below, CIF2 imposes restrictions on the characters allowed in data names, block codes, and save frame codes, and it disregards the Unicode-defined separating and delimiting functions of all but a few characters.
> ====
>
> 4. Change the format of the explicit included character set to use Unicode convention.  (A few weeks ago I provided James a proposed draft update that does this.)
>
> 5. Delete all remaining appearances of the text "UTF-8" in that section and those following, without replacement (the definition of "character(s)" obviates these).
>
> 6. Add a new section at the end:
> ====
> CHANGE 10 - NEW (ENCODING)
>
> Many alternative encodings are available for recording and exchanging Unicode text (such as CIF2 data) via byte-oriented media.  This specification does not forbid the use of any particular encoding for storing and exchanging CIF2 data, but UTF-8 is the canonical encoding for CIF2.  All CIF2 readers conformant with this specification are prepared to accept CIF2 input encoded in UTF-8.  They may in addition accept CIF2 input encoded via other schemes, but they are not required to do so.  CIF2 writers may produce output in any encoding, but they are strongly encouraged to use UTF-8 unless environment- or purpose-specific circumstances direct otherwise.
>
> As used with CIF2, UTF-8 encoding includes an optional initial UTF-8 encoded byte-order mark (character U+FEFF).  Such a code is accepted and ignored if present, but it is considered part of the encoding, not part of the encoded CIF2 data.
>
> Reasoning: A canonical encoding is chosen to standardize one means of exchanging CIF data without data corruption or loss.  UTF-8 in particular is chosen because of its widespread and growing acceptance and implementation, its coverage of the entire Unicode code space, and its congruence with 7-bit ASCII over the entire ASCII range.
> ====
>
>
> Regards,
>
> John
> --
> John C. Bollinger, Ph.D.
> Department of Structural Biology
> St. Jude Children's Research Hospital
>
>
> Email Disclaimer:  www.stjude.org/emaildisclaimer
>
> _______________________________________________
> ddlm-group mailing list
> ddlm-group@iucr.org
> http://scripts.iucr.org/mailman/listinfo/ddlm-group
>
_______________________________________________
ddlm-group mailing list
ddlm-group@iucr.org
http://scripts.iucr.org/mailman/listinfo/ddlm-group

Reply to: [list | sender only]