libstdc++: Avoid ASCII assumptions in floating_from_chars.cc
authorPatrick Palka <ppalka@redhat.com>
Thu, 21 Apr 2022 16:11:01 +0000 (12:11 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 21 Apr 2022 16:11:01 +0000 (12:11 -0400)
commit93dd7f36f2066ec52137178ee52052f293e5e743
tree391af3af100b83dfca4c6b38fdb1d3d1f39befda
parent605a80bb733b225e5e53db0f0298374213cdcd95
libstdc++: Avoid ASCII assumptions in floating_from_chars.cc

In starts_with_ci and in __floating_from_chars_hex's inf/nan handling,
we were assuming that the letters are contiguous and that 'A' + 32 == 'a'
which is true for ASCII but not for other character encodings.

This patch fixes starts_with_ci by using a constexpr lookup table that
maps uppercase letters to lowercase, and fixes __floating_from_chars_hex
by using __from_chars_alnum_to_val.

libstdc++-v3/ChangeLog:

* include/std/charconv (__from_chars_alnum_to_val_table):
Simplify initialization of __lower/__upper_letters.
(__from_chars_alnum_to_val): Default the template parameter to
false.
* src/c++17/floating_from_chars.cc (starts_with_ci): Don't
assume the uppercase and lowercase letters are contiguous.
(__floating_from_chars_hex): Likewise.
libstdc++-v3/include/std/charconv
libstdc++-v3/src/c++17/floating_from_chars.cc