MBSTRG(current_filter_illegal_mode), MBSTRG(current_filter_illegal_substchar));
}
-/* {{{ proto string mb_convert_case(string sourcestring, int mode [, string encoding])
- Returns a case-folded version of sourcestring */
+/* {{{ proto string mb_convert_case(string source_string, int mode [, string encoding])
+ Returns a case-folded version of source_string */
PHP_FUNCTION(mb_convert_case)
{
zend_string *from_encoding = NULL;
size_t ret_len;
const mbfl_encoding *enc;
- RETVAL_FALSE;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|S!", &str, &str_len,
- &case_mode, &from_encoding) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|S!", &str, &str_len, &case_mode, &from_encoding) == FAILURE) {
RETURN_THROWS();
}
}
if (case_mode < 0 || case_mode > PHP_UNICODE_CASE_MODE_MAX) {
- php_error_docref(NULL, E_WARNING, "Invalid case mode");
- return;
+ zend_argument_value_error(2, "must be one of MB_CASE_UPPER, MB_CASE_LOWER, MB_CASE_TITLE, MB_CASE_FOLD,"
+ " MB_CASE_UPPER_SIMPLE, MB_CASE_LOWER_SIMPLE, MB_CASE_TITLE_SIMPLE, or MB_CASE_FOLD_SIMPLE");
+ RETURN_THROWS();
}
newstr = mbstring_convert_case(case_mode, str, str_len, &ret_len, enc);
+ /* If newstr is NULL something went wrong in mbfl and this is a bug */
+ ZEND_ASSERT(newstr != NULL);
- if (newstr) {
- // TODO: avoid reallocation ???
- RETVAL_STRINGL(newstr, ret_len);
- efree(newstr);
- }
+ // TODO: avoid reallocation ???
+ RETVAL_STRINGL(newstr, ret_len);
+ efree(newstr);
}
/* }}} */
-/* {{{ proto string mb_strtoupper(string sourcestring [, string encoding])
- * Returns a uppercased version of sourcestring
+/* {{{ proto string mb_strtoupper(string source_string [, string encoding])
+ * Returns a upper cased version of source_string
*/
PHP_FUNCTION(mb_strtoupper)
{
size_t ret_len;
const mbfl_encoding *enc;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|S!", &str, &str_len,
- &from_encoding) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|S!", &str, &str_len, &from_encoding) == FAILURE) {
RETURN_THROWS();
}
}
newstr = mbstring_convert_case(PHP_UNICODE_CASE_UPPER, str, str_len, &ret_len, enc);
+ /* If newstr is NULL something went wrong in mbfl and this is a bug */
+ ZEND_ASSERT(newstr != NULL);
- if (newstr) {
- // TODO: avoid reallocation ???
- RETVAL_STRINGL(newstr, ret_len);
- efree(newstr);
- return;
- }
- RETURN_FALSE;
+ // TODO: avoid reallocation ???
+ RETVAL_STRINGL(newstr, ret_len);
+ efree(newstr);
}
/* }}} */
-/* {{{ proto string mb_strtolower(string sourcestring [, string encoding])
- * Returns a lowercased version of sourcestring
+/* {{{ proto string mb_strtolower(string source_string [, string encoding])
+ * Returns a lower cased version of source_string
*/
PHP_FUNCTION(mb_strtolower)
{
size_t ret_len;
const mbfl_encoding *enc;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|S!", &str, &str_len,
- &from_encoding) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|S!", &str, &str_len, &from_encoding) == FAILURE) {
RETURN_THROWS();
}
}
newstr = mbstring_convert_case(PHP_UNICODE_CASE_LOWER, str, str_len, &ret_len, enc);
+ /* If newstr is NULL something went wrong in mbfl and this is a bug */
+ ZEND_ASSERT(newstr != NULL);
- if (newstr) {
- // TODO: avoid reallocation ???
- RETVAL_STRINGL(newstr, ret_len);
- efree(newstr);
- return;
- }
- RETURN_FALSE;
+ // TODO: avoid reallocation ???
+ RETVAL_STRINGL(newstr, ret_len);
+ efree(newstr);
}
/* }}} */
ZEND_ARG_TYPE_MASK(0, from, MAY_BE_ARRAY|MAY_BE_STRING)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_convert_case, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
- ZEND_ARG_TYPE_INFO(0, sourcestring, IS_STRING, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_convert_case, 0, 2, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO(0, source_string, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 1)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_strtoupper, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
- ZEND_ARG_TYPE_INFO(0, sourcestring, IS_STRING, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_strtoupper, 0, 1, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO(0, source_string, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 1)
ZEND_END_ARG_INFO()
--- /dev/null
+--TEST--
+Calling mb_convert_case() with an invalid casing mode
+--SKIPIF--
+<?php require 'skipif.inc'; ?>
+--FILE--
+<?php
+
+var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_UPPER));
+var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_LOWER));
+var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_TITLE));
+var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_FOLD));
+var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_UPPER_SIMPLE));
+var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_LOWER_SIMPLE));
+var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_TITLE_SIMPLE));
+var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_FOLD_SIMPLE));
+
+// Invalid mode
+try {
+ var_dump(mb_convert_case('foo BAR Spaß', 100));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+?>
+--EXPECT--
+string(13) "FOO BAR SPASS"
+string(13) "foo bar spaß"
+string(13) "Foo Bar Spaß"
+string(13) "foo bar spass"
+string(13) "FOO BAR SPAß"
+string(13) "foo bar spaß"
+string(13) "Foo Bar Spaß"
+string(13) "foo bar spaß"
+mb_convert_case(): Argument #2 ($mode) must be one of MB_CASE_UPPER, MB_CASE_LOWER, MB_CASE_TITLE, MB_CASE_FOLD, MB_CASE_UPPER_SIMPLE, MB_CASE_LOWER_SIMPLE, MB_CASE_TITLE_SIMPLE, or MB_CASE_FOLD_SIMPLE