[
Lists Home |
Date Index |
Thread Index
]
John Cowan wrote:
>Amelia A Lewis scripsit:
>
>
>
>>It was an interesting argument. I found myself in the position of
>>arguing that *all* character streams in Java have encodings (including
>>java.lang.String). The counter to this is a filter stream, such as a
>>TeeWriter (I was arguing that the problem was that Java did not provide
>>a getEncoding() method on all streams).
>>
>>
>
>I think you have a hold of the right stick, but at the wrong end.
>Byte streams have encodings if they represent text, but at the level of
>character streams, encodings have been abstracted away.
>
>
>
They have *almost* been abstracted away: a Java "character" is UTF-16.
Some Unicode
characters require more than one Java "character" to represent then.
All *implementations*
of characters have one (or more) underlying encoding. A nominal
getEncoding() method
on a Java 1.n character stream even TeeWriter should always produce
"UTF-16".
This should upset no-one, because some real characters may require more
than one
Unicode "character" to represent them, anyway. Take Vietnamese, please:
if I have
a u with a horn accent above plus a dot underneath [1], that is one real
character
(according to what people think of as characters) but three Unicode
characters,
3 UTF-16 characters, 6 bytes of storage.
It is just a fact of life that there are edge cases that are not neat to
represent. The only
way that software will adequately support "edge cases" (which is a
euphemism for
writing systems of economically unimportant nations, to some extent) is
for
libraries to support it: take it out of the hands of Joe Programmer and
let the
API writers do it. XML's spin on simplicity (that Joe Programmer can fairly
easily write a minimal parser) sets wrong expectations: that anything that
is not in a minimal parser is part of the conspiracy of fluff.
We are all taught about shorts, longs, doubles and floats at University
(if we
studied programming), and the idea that numbers exist in different encodings
which each have different properties is no surprise to anyone (except
perhaps
LISPers with BIGNUMS). That strings also exist in different encodings
with different properties should also be taught.
Cheers
Rick Jelliffe
[1] accepting for argument's sake
http://leb.net/archives/reader/csi/0352.html
|