diff options
author | Karl Williamson <public@khwilliamson.com> | 2011-11-08 18:55:09 -0700 |
---|---|---|
committer | Karl Williamson <public@khwilliamson.com> | 2011-11-08 22:38:38 -0700 |
commit | afc16117342e69d725e9609816ad29f611edb5a5 (patch) | |
tree | 33fe89eea3edaaf70b06a7b01c47dc75d19d59d9 /utf8.c | |
parent | 50bda2c32d66573a5367b7d0d5a1d287d766b811 (diff) | |
download | perl-afc16117342e69d725e9609816ad29f611edb5a5.tar.gz |
utf8.c: Refactor to_uni_lower()
The portion that deals with Latin1 range characters is refactored into a
separate (static) function, so that it can be called from more than one place.
Diffstat (limited to 'utf8.c')
-rw-r--r-- | utf8.c | 43 |
1 files changed, 27 insertions, 16 deletions
@@ -1357,29 +1357,40 @@ Perl_to_uni_title(pTHX_ UV c, U8* p, STRLEN *lenp) return to_utf8_title(p, p, lenp); } +STATIC U8 +S_to_lower_latin1(pTHX_ const U8 c, U8* p, STRLEN *lenp) +{ + /* We have the latin1-range values compiled into the core, so just use + * those, converting the result to utf8. Since the result is always just + * one character, we allow p to be NULL */ + + U8 converted = toLOWER_LATIN1(c); + + if (p != NULL) { + if (UNI_IS_INVARIANT(converted)) { + *p = converted; + *lenp = 1; + } + else { + *p = UTF8_TWO_BYTE_HI(converted); + *(p+1) = UTF8_TWO_BYTE_LO(converted); + *lenp = 2; + } + } + return converted; +} + UV Perl_to_uni_lower(pTHX_ UV c, U8* p, STRLEN *lenp) { PERL_ARGS_ASSERT_TO_UNI_LOWER; - if (c > 255) { - uvchr_to_utf8(p, c); - return to_utf8_lower(p, p, lenp); + if (c < 256) { + return to_lower_latin1((U8) c, p, lenp); } - /* We have the latin1-range values compiled into the core, so just use - * those, converting the result to utf8 */ - c = toLOWER_LATIN1(c); - if (UNI_IS_INVARIANT(c)) { - *p = c; - *lenp = 1; - } - else { - *p = UTF8_TWO_BYTE_HI(c); - *(p+1) = UTF8_TWO_BYTE_LO(c); - *lenp = 2; - } - return c; + uvchr_to_utf8(p, c); + return to_utf8_lower(p, p, lenp); } UV |