Skip to content

Commit f45231a

Browse files
author
Moriyoshi Koizumi
committed
Added mb_strtolower() and mb_strtoupper()
@- Added mb_strtolower() and mb_strtoupper(). (Moriyoshi)
1 parent 890aee5 commit f45231a

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

ext/mbstring/mbstring.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ static const struct mb_overload_def mb_ovld[] = {
162162
{MB_OVERLOAD_STRING, "strpos", "mb_strpos", "mb_orig_strrpos"},
163163
{MB_OVERLOAD_STRING, "strrpos", "mb_strrpos", "mb_orig_strrpos"},
164164
{MB_OVERLOAD_STRING, "substr", "mb_substr", "mb_orig_substr"},
165+
{MB_OVERLOAD_STRING, "strtolower", "mb_strtolower", "mb_orig_strtolower"},
166+
{MB_OVERLOAD_STRING, "strtoupper", "mb_strtoupper", "mb_orig_strtoupper"},
165167
#if HAVE_MBREGEX
166168
{MB_OVERLOAD_REGEX, "ereg", "mb_ereg", "mb_orig_ereg"},
167169
{MB_OVERLOAD_REGEX, "eregi", "mb_eregi", "mb_orig_eregi"},
@@ -189,6 +191,8 @@ const struct def_mbctype_tbl mbctype_tbl[] = {
189191

190192
function_entry mbstring_functions[] = {
191193
PHP_FE(mb_convert_case, NULL)
194+
PHP_FE(mb_strtoupper, NULL)
195+
PHP_FE(mb_strtolower, NULL)
192196
PHP_FE(mb_language, NULL)
193197
PHP_FE(mb_internal_encoding, NULL)
194198
PHP_FE(mb_http_input, NULL)
@@ -2580,6 +2584,55 @@ PHP_FUNCTION(mb_convert_case)
25802584
}
25812585
/* }}} */
25822586

2587+
/* {{{ proto string mb_strtoupper(string sourcestring, [, string encoding])
2588+
* Returns a uppercased version of sourcestring
2589+
*/
2590+
PHP_FUNCTION(mb_strtoupper)
2591+
{
2592+
char *str, *from_encoding = (char*)mbfl_no2preferred_mime_name(MBSTRG(current_internal_encoding));
2593+
long str_len, from_encoding_len;
2594+
long case_mode = 0;
2595+
char *newstr;
2596+
size_t ret_len;
2597+
2598+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &str, &str_len,
2599+
&from_encoding, &from_encoding_len) == FAILURE) {
2600+
RETURN_FALSE;
2601+
}
2602+
newstr = php_unicode_convert_case(PHP_UNICODE_CASE_UPPER, str, str_len, &ret_len, from_encoding TSRMLS_CC);
2603+
2604+
if (newstr)
2605+
RETURN_STRINGL(newstr, ret_len, 0);
2606+
2607+
RETURN_FALSE;
2608+
}
2609+
/* }}} */
2610+
2611+
/* {{{ proto string mb_strtolower(string sourcestring, [, string encoding])
2612+
* Returns a lowercased version of sourcestring
2613+
*/
2614+
PHP_FUNCTION(mb_strtolower)
2615+
{
2616+
char *str, *from_encoding = (char*)mbfl_no2preferred_mime_name(MBSTRG(current_internal_encoding));
2617+
long str_len, from_encoding_len;
2618+
long case_mode = 0;
2619+
char *newstr;
2620+
size_t ret_len;
2621+
2622+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &str, &str_len,
2623+
&from_encoding, &from_encoding_len) == FAILURE) {
2624+
RETURN_FALSE;
2625+
}
2626+
newstr = php_unicode_convert_case(PHP_UNICODE_CASE_LOWER, str, str_len, &ret_len, from_encoding TSRMLS_CC);
2627+
2628+
if (newstr)
2629+
RETURN_STRINGL(newstr, ret_len, 0);
2630+
2631+
RETURN_FALSE;
2632+
}
2633+
/* }}} */
2634+
2635+
25832636
/* {{{ proto string mb_detect_encoding(string str [, mixed encoding_list])
25842637
Encodings of the given string is returned (as a string) */
25852638
PHP_FUNCTION(mb_detect_encoding)

ext/mbstring/mbstring.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ PHP_MINFO_FUNCTION(mbstring);
7878

7979
/* functions in php_unicode.c */
8080
PHP_FUNCTION(mb_convert_case);
81+
PHP_FUNCTION(mb_strtoupper);
82+
PHP_FUNCTION(mb_strtolower);
8183

8284
/* php function registration */
8385
PHP_FUNCTION(mb_language);

ext/mbstring/tests/026.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
print mb_strtolower( "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" );
3+
print mb_strtoupper( mb_strtolower( "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" ) );
4+
?>

ext/mbstring/tests/026.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
mb_strtoupper() / mb_strtolower()
3+
--SKIPIF--
4+
<?php include('skipif.inc'); ?>
5+
function_exists('mb_strtolower') or die("SKIP");
6+
--POST--
7+
--GET--
8+
--FILE--
9+
<?php include('026.inc'); ?>
10+
--EXPECT--
11+
abcdefghijklmnopqrstuvwxyz
12+
ABCDEFGHIJKLMNOPQRSTUVWXYZ

0 commit comments

Comments
 (0)