This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: Use REPLACEMENT_CHARACTER as a test
authorKarl Williamson <khw@cpan.org>
Mon, 11 Sep 2017 23:41:57 +0000 (17:41 -0600)
committerKarl Williamson <khw@cpan.org>
Thu, 9 Nov 2017 03:52:52 +0000 (20:52 -0700)
commitb1d4925c105b6e865b16a8914b6819899889d639
tree9b475e098adb27ad07d3e53ab0b3a298fcc7f00c
parent51fc4b19eb5af1211f960bc49d322c020490bc61
locale.c: Use REPLACEMENT_CHARACTER as a test

This is trying to determine if the locale is UTF-8.  The easiest way to
tell is if the codeset returned by nl_langinfo says UTF-8, but if that
fails or nl_langinfo() is not present on the system, a fallback method
is to use the libc routines to convert a known byte string to code point
and see if that matches the expected Unicode code point.  Prior to this
patch, the byte string representing HYPHEN was used.  That's probably
good enough, but we can do better with no extra work.  This commit
changes to use the REPLACEMENT CHARACTER instead.  That is a Unicode
concept.  The chances of a non-UTF-8 locale taking the UTF-8 byte string
for the REPLACEMENT and evaluating to REPLACEMENT are vanishingly small.
locale.c