libstdc++: Fix Unicode property detection functions
commitea314ccd625aada7ed8a324ac07cfc3a8aa0f03f
authorJonathan Wakely <jwakely@redhat.com>
Tue, 9 Jan 2024 14:43:40 +0000 (9 14:43 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 9 Jan 2024 23:42:59 +0000 (9 23:42 +0000)
treeb03d717b348e1e57fc96a9a49cf0776d05132ec3
parent6002a3cd39c984423c59255ac780efb8b668b73a
libstdc++: Fix Unicode property detection functions

Fix some copy & pasted logic in __is_extended_pictographic. This
function should yield false for the values before the first edge, not
true. Also add a missing boundary condition check in __incb_property.

Also Fix an off-by-one error in _Utf_iterator::operator++() that would
make dereferencing a past-the-end iterator undefined (where the intended
design is that the iterator is always incrementable and dereferenceable,
for better memory safety).

Also simplify the grapheme view iterator, which still contained some
remnants of an earlier design I was experimenting with.

Slightly tweak the gen_libstdcxx_unicode_data.py script so that the
_Gcb_property enumerators are in the order we encounter them in the data
file, instead of sorting them alphabetically. Start with the "Other"
property at value 0, because that's the default property for anything
not in the file. This makes no practical difference, but seems cleaner.
It causes the values in the __gcb_edges table to change, so can only be
done now before anybody is using this code yet. The enumerator values
and table entries become ABI artefacts for the function using them.

contrib/ChangeLog:

* unicode/gen_libstdcxx_unicode_data.py: Print out Gcb_property
enumerators in the order they're seen, not alphabetical order.

libstdc++-v3/ChangeLog:

* include/bits/unicode-data.h: Regenerate.
* include/bits/unicode.h (_Utf_iterator::operator++()): Fix off
by one error.
(__incb_property): Add missing check for values before the
first edge.
(__is_extended_pictographic): Invert return values to fix
copy&pasted logic.
(_Grapheme_cluster_view::_Iterator): Remove second iterator
member and find end of cluster lazily.
* testsuite/ext/unicode/grapheme_view.cc: New test.
* testsuite/ext/unicode/properties.cc: New test.
* testsuite/ext/unicode/view.cc: New test.
contrib/unicode/gen_libstdcxx_unicode_data.py
libstdc++-v3/include/bits/unicode-data.h
libstdc++-v3/include/bits/unicode.h
libstdc++-v3/testsuite/ext/unicode/grapheme_view.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/unicode/properties.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/unicode/view.cc