Make enum for valid case_mode values (for php_unicode_convert_case)

This commit is contained in:
Alex Dowad 2022-09-24 17:05:52 +09:00
parent 7eef2fb45e
commit 20769fb9ab
3 changed files with 17 additions and 15 deletions

View file

@ -2753,7 +2753,7 @@ PHP_FUNCTION(mb_convert_encoding)
}
/* }}} */
static zend_string *mbstring_convert_case(int case_mode, const char *str, size_t str_len, const mbfl_encoding *enc)
static zend_string *mbstring_convert_case(php_case_mode case_mode, const char *str, size_t str_len, const mbfl_encoding *enc)
{
return php_unicode_convert_case(case_mode, str, str_len, enc, MBSTRG(current_filter_illegal_mode), MBSTRG(current_filter_illegal_substchar));
}
@ -2775,7 +2775,7 @@ PHP_FUNCTION(mb_convert_case)
RETURN_THROWS();
}
if (case_mode < 0 || case_mode > PHP_UNICODE_CASE_MODE_MAX) {
if (case_mode < 0 || case_mode >= PHP_UNICODE_CASE_MODE_MAX) {
zend_argument_value_error(2, "must be one of the MB_CASE_* constants");
RETURN_THROWS();
}

View file

@ -238,7 +238,7 @@ static uint32_t *emit_special_casing_sequence(uint32_t w, uint32_t *out)
return out;
}
MBSTRING_API zend_string *php_unicode_convert_case(int case_mode, const char *srcstr, size_t in_len, const mbfl_encoding *src_encoding, int illegal_mode, int illegal_substchar)
MBSTRING_API zend_string *php_unicode_convert_case(php_case_mode case_mode, const char *srcstr, size_t in_len, const mbfl_encoding *src_encoding, int illegal_mode, int illegal_substchar)
{
/* A Unicode codepoint can expand out to up to 3 codepoints when uppercased, lowercased, or title cased
* See http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt */

View file

@ -77,19 +77,21 @@
MBSTRING_API bool php_unicode_is_prop(unsigned long code, ...);
MBSTRING_API bool php_unicode_is_prop1(unsigned long code, int prop);
MBSTRING_API zend_string *php_unicode_convert_case(
int case_mode, const char *srcstr, size_t srclen,
const mbfl_encoding *src_encoding, int illegal_mode, int illegal_substchar);
typedef enum {
PHP_UNICODE_CASE_UPPER = 0,
PHP_UNICODE_CASE_LOWER,
PHP_UNICODE_CASE_TITLE,
PHP_UNICODE_CASE_FOLD,
PHP_UNICODE_CASE_UPPER_SIMPLE,
PHP_UNICODE_CASE_LOWER_SIMPLE,
PHP_UNICODE_CASE_TITLE_SIMPLE,
PHP_UNICODE_CASE_FOLD_SIMPLE,
PHP_UNICODE_CASE_MODE_MAX
} php_case_mode;
#define PHP_UNICODE_CASE_UPPER 0
#define PHP_UNICODE_CASE_LOWER 1
#define PHP_UNICODE_CASE_TITLE 2
#define PHP_UNICODE_CASE_FOLD 3
#define PHP_UNICODE_CASE_UPPER_SIMPLE 4
#define PHP_UNICODE_CASE_LOWER_SIMPLE 5
#define PHP_UNICODE_CASE_TITLE_SIMPLE 6
#define PHP_UNICODE_CASE_FOLD_SIMPLE 7
#define PHP_UNICODE_CASE_MODE_MAX 7
MBSTRING_API zend_string *php_unicode_convert_case(
php_case_mode case_mode, const char *srcstr, size_t srclen,
const mbfl_encoding *src_encoding, int illegal_mode, int illegal_substchar);
/* Optimize the common ASCII case for lower/upper */