Skip to content

Commit

Permalink
locale.c: Split a static function in two
Browse files Browse the repository at this point in the history
A future commit will want to use just the first part of the function.
  • Loading branch information
khwilliamson committed Feb 2, 2023
1 parent 845ff65 commit 2403c61
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -4277,6 +4277,8 @@ ST |const char *|save_to_buffer \
ST |unsigned int|get_category_index \
|const int category \
|NULLOK const char *locale
ST |int |get_category_index_nowarn \
|const int category
S |void |new_LC_ALL |NULLOK const char *unused \
|bool force
S |const char *|stdize_locale \
Expand Down
1 change: 1 addition & 0 deletions embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@
# endif /* defined(HAS_LOCALECONV) */
# if defined(USE_LOCALE)
# define get_category_index S_get_category_index
# define get_category_index_nowarn S_get_category_index_nowarn
# define mortalized_pv_copy(a) S_mortalized_pv_copy(aTHX_ a)
# define new_LC_ALL(a,b) S_new_LC_ALL(aTHX_ a,b)
# define save_to_buffer S_save_to_buffer
Expand Down
28 changes: 22 additions & 6 deletions locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,19 +468,16 @@ STATIC void (*update_functions[]) (pTHX_ const char *, bool force) = {
* checked for at compile time by using the #define LC_ALL_INDEX_ which is only
* defined if we do have LC_ALL. */

STATIC unsigned int
S_get_category_index(const int category, const char * locale)
STATIC int
S_get_category_index_nowarn(const int category)
{
/* Given a category, return the equivalent internal index we generally use
* instead.
*
* 'locale' is for use in any generated diagnostics, and may be NULL
* instead, or negative if not found.
*
* Some sort of hash could be used instead of this loop, but the number of
* elements is so far at most 12 */

unsigned int i;
const char * conditional_warn_text = "; can't set it to ";

PERL_ARGS_ASSERT_GET_CATEGORY_INDEX;

Expand All @@ -499,6 +496,25 @@ S_get_category_index(const int category, const char * locale)
}
}

return -1;
}

STATIC unsigned int
S_get_category_index(const int category, const char * locale)
{
/* Given a category, return the equivalent internal index we generally use
* instead.
*
* 'locale' is for use in any generated diagnostics, and may be NULL
*/

const char * conditional_warn_text = "; can't set it to ";
const int index = get_category_index_nowarn(category);

if (index >= 0) {
return index;
}

/* Here, we don't know about this category, so can't handle it. */

if (! locale) {
Expand Down
4 changes: 4 additions & 0 deletions proto.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2403c61

Please sign in to comment.