diff options
author | Karl Williamson <khw@cpan.org> | 2021-05-10 10:41:28 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2021-08-23 08:02:36 -0600 |
commit | 57aed1261ee10ab88320d81a57790e0402be8873 (patch) | |
tree | c3909ef4a0ac2b86c478058cc99e30f7d89e2e6d | |
parent | 265ec34504a94be951392fbafdb653fb6db13ce8 (diff) | |
download | perl-57aed1261ee10ab88320d81a57790e0402be8873.tar.gz |
utf8.c: Make new static fcn more flexible
This commit allows this function to be called with NULL parameters when
the result of these is not needed.
-rw-r--r-- | embed.fnc | 4 | ||||
-rw-r--r-- | proto.h | 2 | ||||
-rw-r--r-- | utf8.c | 28 |
3 files changed, 25 insertions, 9 deletions
@@ -2500,8 +2500,8 @@ S |void |warn_on_first_deprecated_use \ |const unsigned line #endif S |UV |to_case_cp_list|const UV original \ - |NN const U32 ** const remaining_list \ - |NN Size_t * remaining_count \ + |NULLOK const U32 ** const remaining_list \ + |NULLOK Size_t * remaining_count \ |NN SV *invlist \ |NN const I32 * const invmap \ |NULLOK const U32 * const * const aux_tables \ @@ -6666,7 +6666,7 @@ STATIC HV * S_new_msg_hv(pTHX_ const char * const message, U32 categories, U32 f STATIC UV S_to_case_cp_list(pTHX_ const UV original, const U32 ** const remaining_list, Size_t * remaining_count, SV *invlist, const I32 * const invmap, const U32 * const * const aux_tables, const U8 * const aux_table_lengths, const char * const normal); #define PERL_ARGS_ASSERT_TO_CASE_CP_LIST \ - assert(remaining_list); assert(remaining_count); assert(invlist); assert(invmap); assert(normal) + assert(invlist); assert(invmap); assert(normal) STATIC U8 S_to_lower_latin1(const U8 c, U8 *p, STRLEN *lenp, const char dummy) __attribute__warn_unused_result__; #define PERL_ARGS_ASSERT_TO_LOWER_LATIN1 @@ -3178,10 +3178,16 @@ S_to_case_cp_list(pTHX_ const UV original, I32 base; /* Return the changed case of code point 'original'. The first code point of - * the changed case is returned; *remaining_count will be set to how many - * other code points are in the changed case. If it is non-zero, - * *remaining_list will point to a non-modifiable array containing them; - * if zero, *remaining_list is undefined. + * the changed case is returned. + * + * If 'remaining_count' is not NULL, *remaining_count will be set to how + * many other code points are in the changed case. If non-zero and + * 'remaining_list' is also not NULL, *remaining_list will be set to point + * to a non-modifiable array containing the second and potentially third + * code points in the changed case. (Unicode guarantees a maximum of 3.) + * Note that this means that *remaining_list is undefined unless there are + * multiple code points, and the caller has chosen to find out how many by + * making 'remaining_count' not NULL. * * 'normal' is a string to use to name the new case in any generated * messages, as a fallback if the operation being used is not available. @@ -3197,6 +3203,11 @@ S_to_case_cp_list(pTHX_ const UV original, index = _invlist_search(invlist, original); base = invmap[index]; + /* Most likely, the case change will contain just a single code point */ + if (remaining_count) { + *remaining_count = 0; + } + if (LIKELY(base == 0)) { /* 0 => original was unchanged by casing */ /* At this bottom level routine is where we warn about illegal code @@ -3243,8 +3254,13 @@ S_to_case_cp_list(pTHX_ const UV original, * the first entry in the *remaining returns, as it is returned by the * function. */ base = -base; - *remaining_list = aux_tables[base] + 1; - *remaining_count = (Size_t) (aux_table_lengths[base] - 1); + if (remaining_count) { + *remaining_count = (Size_t) (aux_table_lengths[base] - 1); + + if (remaining_list) { + *remaining_list = aux_tables[base] + 1; + } + } return (UV) aux_tables[base][0]; } |