Add 'codepoint_collation' support for LC_COLLATE.
commitf5117c6504888fab5423282a4607c552b90fd3f9
authorCarlos O'Donell <carlos@redhat.com>
Fri, 30 Jul 2021 02:45:39 +0000 (29 22:45 -0400)
committerCarlos O'Donell <carlos@redhat.com>
Mon, 6 Sep 2021 15:06:45 +0000 (6 11:06 -0400)
tree2961802e4e55a5669f9b224923955871524a33fd
parent1d9f99ce1b3788d1897cb53a76d57e973111b8fe
Add 'codepoint_collation' support for LC_COLLATE.

Support a new directive 'codepoint_collation' in the LC_COLLATE
section of a locale source file. This new directive causes all
collation rules to be dropped and instead STRCMP (strcmp or
wcscmp) is used for collation of the input character set. This
is required to allow for a C.UTF-8 that contains zero collation
rules (minimal size) and sorts using code point sorting.

To date the only implementation of a locale with zero collation
rules is the C/POSIX locale. The C/POSIX locale provides
identity tables for _NL_COLLATE_COLLSEQMB and
_NL_COLLATE_COLLSEQWC that map to ASCII even though it has zero
rules. This has lead to existing fnmatch, regexec, and regcomp
implementations that require these tables. It is not correct
to use these tables when nrules == 0, but the conservative fix
is to provide these tables when nrules == 0. This assures that
existing static applications using a new C.UTF-8 locale with
'codepoint_collation' at least have functional range expressions
with ASCII e.g. [0-9] or [a-z]. Such static applications would
not have the fixes to fnmatch, regexec and regcomp that avoid
the use of the tables when nrules == 0. Future fixes to fnmatch,
regexec, and regcomp would allow range expressions to use the
full set of code points for such ranges.

Tested on x86_64 and i686 without regression.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
locale/C-collate-seq.c [copied from locale/C-collate.c with 80% similarity]
locale/C-collate.c
locale/programs/ld-collate.c
locale/programs/locfile-kw.gperf
locale/programs/locfile-kw.h
locale/programs/locfile-token.h