Sort text by the Unicode Collation Algorithm, in a zig-collate of its own #1
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
xsl:sortcompares text by code point. That is not merely unlocalized, it iswrong in a way users notice:
Muellersorts beforeMärtens, becauseuisU+0075andäisU+00E4.Fixing it properly means the Unicode Collation Algorithm, UTS #10, and
that belongs in a library of its own —
zig-collate— for the same reason thecalendar is zig-datetime's. A collation is the kind of thing
that is wrong in the same way in every project that reimplements one, and
nothing about it is XSLT's.
The four pieces
canonical combining class.
allkeys.txt, sometwenty-nine thousand entries, which wants fetching and generating at build
time the way zig-datetime handles tzdata rather than being checked in by
hand.
levels concatenated, so that a comparison becomes one
memcmponce the keyfor each node has been built.
per-language, and so the only part
xsl:sort lang=actually needs.What already exists
uucode exposes
canonical_combining_classanddecomposition_type/decomposition_mapping— exactly what step 1 runs on —along with case folding, general category and script, and it is configurable
at build time so a caller pays only for the fields it names. It has none of
the other three: no DUCET, no sort keys, no tailorings. So it is the right
dependency for the data layer and is not itself a collation.
Two things worth knowing before starting
REC/test-10-3needs none of step 4. Both glibc'sde_DEand UCA rootgive ä, ö and ü the same primary weights as a, o and u, and that alone orders
Märtens < Möller < Mueller. Strip
lang="de"from that stylesheet and libxsltfalls back to exactly the code-point order zxsl already produces, so the
attribute carries the whole difference.
Passing that case is not the reason to do this. libxslt has no collation of
its own:
libxslt/xsltlocale.ccallsnewlocale()andstrxfrm_l(), so itsanswer comes from the host C library's locale data, and the recorded output is
a property of the machine it was recorded on. Matching libxslt would mean
matching glibc, which is ISO 14651-derived and disagrees with CLDR in places.
The reason to do it is that sorting by code point is a poor default, and a
correct root collation is a better one for every stylesheet whether or not it
says
lang.Scope note
libxslt's
case-orderargument isATTRIBUTE_UNUSED— it accepts and ignoresthat attribute exactly as zxsl does, and no case in its corpus exercises it. So
case-orderis at parity today and is not part of this.