Skip to content

Commit 20769fb

Browse files
committed
Make enum for valid case_mode values (for php_unicode_convert_case)
1 parent 7eef2fb commit 20769fb

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

ext/mbstring/mbstring.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,7 +2753,7 @@ PHP_FUNCTION(mb_convert_encoding)
27532753
}
27542754
/* }}} */
27552755

2756-
static zend_string *mbstring_convert_case(int case_mode, const char *str, size_t str_len, const mbfl_encoding *enc)
2756+
static zend_string *mbstring_convert_case(php_case_mode case_mode, const char *str, size_t str_len, const mbfl_encoding *enc)
27572757
{
27582758
return php_unicode_convert_case(case_mode, str, str_len, enc, MBSTRG(current_filter_illegal_mode), MBSTRG(current_filter_illegal_substchar));
27592759
}
@@ -2775,7 +2775,7 @@ PHP_FUNCTION(mb_convert_case)
27752775
RETURN_THROWS();
27762776
}
27772777

2778-
if (case_mode < 0 || case_mode > PHP_UNICODE_CASE_MODE_MAX) {
2778+
if (case_mode < 0 || case_mode >= PHP_UNICODE_CASE_MODE_MAX) {
27792779
zend_argument_value_error(2, "must be one of the MB_CASE_* constants");
27802780
RETURN_THROWS();
27812781
}

ext/mbstring/php_unicode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static uint32_t *emit_special_casing_sequence(uint32_t w, uint32_t *out)
238238
return out;
239239
}
240240

241-
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)
241+
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)
242242
{
243243
/* A Unicode codepoint can expand out to up to 3 codepoints when uppercased, lowercased, or title cased
244244
* See http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt */

ext/mbstring/php_unicode.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,22 @@
7777
MBSTRING_API bool php_unicode_is_prop(unsigned long code, ...);
7878
MBSTRING_API bool php_unicode_is_prop1(unsigned long code, int prop);
7979

80+
typedef enum {
81+
PHP_UNICODE_CASE_UPPER = 0,
82+
PHP_UNICODE_CASE_LOWER,
83+
PHP_UNICODE_CASE_TITLE,
84+
PHP_UNICODE_CASE_FOLD,
85+
PHP_UNICODE_CASE_UPPER_SIMPLE,
86+
PHP_UNICODE_CASE_LOWER_SIMPLE,
87+
PHP_UNICODE_CASE_TITLE_SIMPLE,
88+
PHP_UNICODE_CASE_FOLD_SIMPLE,
89+
PHP_UNICODE_CASE_MODE_MAX
90+
} php_case_mode;
91+
8092
MBSTRING_API zend_string *php_unicode_convert_case(
81-
int case_mode, const char *srcstr, size_t srclen,
93+
php_case_mode case_mode, const char *srcstr, size_t srclen,
8294
const mbfl_encoding *src_encoding, int illegal_mode, int illegal_substchar);
8395

84-
#define PHP_UNICODE_CASE_UPPER 0
85-
#define PHP_UNICODE_CASE_LOWER 1
86-
#define PHP_UNICODE_CASE_TITLE 2
87-
#define PHP_UNICODE_CASE_FOLD 3
88-
#define PHP_UNICODE_CASE_UPPER_SIMPLE 4
89-
#define PHP_UNICODE_CASE_LOWER_SIMPLE 5
90-
#define PHP_UNICODE_CASE_TITLE_SIMPLE 6
91-
#define PHP_UNICODE_CASE_FOLD_SIMPLE 7
92-
#define PHP_UNICODE_CASE_MODE_MAX 7
93-
9496
/* Optimize the common ASCII case for lower/upper */
9597

9698
static inline int php_unicode_is_lower(unsigned long code) {

0 commit comments

Comments
 (0)