diff options
author | Karl Williamson <public@khwilliamson.com> | 2013-07-13 13:43:31 -0600 |
---|---|---|
committer | Karl Williamson <public@khwilliamson.com> | 2013-08-12 13:51:22 -0600 |
commit | 751e9426ac9719a828f41c692bdf0d27bad3331c (patch) | |
tree | 540dd44c2f3ea059a75ecfddd270273630b1668c /locale.c | |
parent | d6f12d5f25eef8816a05b107f9102453bf52e2a1 (diff) | |
download | perl-751e9426ac9719a828f41c692bdf0d27bad3331c.tar.gz |
Assume UTF-8 locale if that string occurs anywhere in name
When a platform doesn't have nl_langinfo(), heuristics are employed
to see if a locale is UTF-8 . The first heuristic is looking at the
return value of setlocale(), which generally is the locale name.
However, in actuality the return value is opaque and can't be relied on
to signify the locale. Nevertheless if it contains the string UTF-8
(ignoring case, and with the hyphen optional), it is a safe bet that the
locale is indeed UTF-8. Prior to this patch, we only looked at the end
of the name for "UTF-8". This patch makes it not have to be
right-anchored. There are UTF-8 locales on our dromedary machine with
UTF-8 in the middle of their names.
Diffstat (limited to 'locale.c')
-rw-r--r-- | locale.c | 34 |
1 files changed, 23 insertions, 11 deletions
@@ -688,20 +688,32 @@ S_is_cur_LC_category_utf8(pTHX_ int category) #endif /* HAS_NL_LANGINFO etc */ /* nl_langinfo not available or failed somehow. Look at the locale name to - * see if it matches qr/UTF -? 8 $ /ix */ + * see if it matches qr/UTF -? 8 /ix */ final_pos = strlen(save_input_locale) - 1; - if (final_pos >= 3 - && *(save_input_locale + final_pos) == '8') - { - has_hyphen = *(save_input_locale + final_pos - 1 ) == '-'; - if ((! has_hyphen || final_pos >= 4) - && toFOLD(*(save_input_locale + final_pos - has_hyphen - 1)) == 'f' - && toFOLD(*(save_input_locale + final_pos - has_hyphen - 2)) == 't' - && toFOLD(*(save_input_locale + final_pos - has_hyphen - 3)) == 'u') + if (final_pos >= 3) { + char *name = save_input_locale; + + /* Find next 'U' or 'u' and look from there */ + while ((name += strcspn(name, "Uu") + 1) + <= save_input_locale + final_pos - 2) { - Safefree(save_input_locale); - return TRUE; + if (toFOLD(*(name)) != 't' + || toFOLD(*(name + 1)) != 'f') + { + continue; + } + name += 2; + if (*(name) == '-') { + if ((name > save_input_locale + final_pos - 1)) { + break; + } + name++; + } + if (*(name) == '8') { + Safefree(save_input_locale); + return TRUE; + } } } |