com php-src: Add php_string_tolower/toupper which is locale depened: ext/standard/array.c ext/standard/php _string.h ext/standard/string.c
| From: | Xinchen Hui | Date: | Thu, 25 Dec 2014 03:29:11 +0000 |
| Subject: | com php-src: Add php_string_tolower/toupper which is locale depened: ext/standard/array.c ext/standard/php _string.h ext/standard/string.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-83857@lists.php.net to get a copy of this message | ||
Commit: 94d26ad4b923b453d55ab7f8fd904b4c145a5a13
Author: Xinchen Hui <laruence@php.net> Thu, 25 Dec 2014 11:28:54 +0800
Parents: f26c50e320c48ce07c8fc7c6f6b9a25983d883d0
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=94d26ad4b923b453d55ab7f8fd904b4c145a5a13
Log:
Add php_string_tolower/toupper which is locale depened
Changed paths:
M ext/standard/array.c
M ext/standard/php_string.h
M ext/standard/string.c
Diff:
diff --git a/ext/standard/array.c b/ext/standard/array.c
index e226b62..9d55ff6 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2848,6 +2848,7 @@ zend_bool array_column_param_helper(zval *param,
return 0;
}
}
+/* }}} */
/* {{{ proto array array_column(array input, mixed column_key[, mixed index_key])
Return the values from a single column in the input array, identified by the
@@ -3075,11 +3076,10 @@ PHP_FUNCTION(array_change_key_case)
if (!string_key) {
zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
} else {
- new_key = zend_string_init(string_key->val, string_key->len, 0);
if (change_to_upper) {
- php_strtoupper(new_key->val, new_key->len);
+ new_key = php_string_toupper(string_key);
} else {
- php_strtolower(new_key->val, new_key->len);
+ new_key = php_string_tolower(string_key);
}
zend_hash_update(Z_ARRVAL_P(return_value), new_key, entry);
zend_string_release(new_key);
diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h
index 8e0ad5c..cbcd39e 100644
--- a/ext/standard/php_string.h
+++ b/ext/standard/php_string.h
@@ -120,6 +120,8 @@ PHPAPI struct lconv *localeconv_r(struct lconv *out);
PHPAPI char *php_strtoupper(char *s, size_t len);
PHPAPI char *php_strtolower(char *s, size_t len);
+PHPAPI zend_string *php_string_toupper(zend_string *s);
+PHPAPI zend_string *php_string_tolower(zend_string *s);
PHPAPI char *php_strtr(char *str, size_t len, char *str_from, char *str_to, size_t trlen);
PHPAPI zend_string *php_addslashes(char *str, size_t length, int should_free);
PHPAPI zend_string *php_addcslashes(const char *str, size_t length, int freeit, char *what, size_t
wlength);
diff --git a/ext/standard/string.c b/ext/standard/string.c
index e275e64..477032d 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -1368,20 +1368,49 @@ PHPAPI char *php_strtoupper(char *s, size_t len)
}
/* }}} */
+/* {{{ php_string_toupper
+ */
+PHPAPI zend_string *php_string_toupper(zend_string *s)
+{
+ unsigned char *c, *e;
+
+ c = (unsigned char *)s->val;
+ e = c + s->len;
+
+ while (c < e) {
+ if (!isupper(*c)) {
+ register unsigned char *r;
+ zend_string *res = zend_string_alloc(s->len, 0);
+
+ if (c != (unsigned char*)s->val) {
+ memcpy(res->val, s->val, c - (unsigned char*)s->val);
+ }
+ r = c + (res->val - s->val);
+ while (c < e) {
+ *r = toupper(*c);
+ r++;
+ c++;
+ }
+ *r = '\0';
+ return res;
+ }
+ c++;
+ }
+ return zend_string_copy(s);
+}
+/* }}} */
+
/* {{{ proto string strtoupper(string str)
Makes a string uppercase */
PHP_FUNCTION(strtoupper)
{
zend_string *arg;
- zend_string *result;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &arg) == FAILURE) {
return;
}
- result = zend_string_init(arg->val, arg->len, 0);
- php_strtoupper(result->val, result->len);
- RETURN_NEW_STR(result);
+ RETURN_STR(php_string_toupper(arg));
}
/* }}} */
@@ -1402,12 +1431,43 @@ PHPAPI char *php_strtolower(char *s, size_t len)
}
/* }}} */
+/* {{{ php_string_tolower
+ */
+PHPAPI zend_string *php_string_tolower(zend_string *s)
+{
+ unsigned char *c, *e;
+
+ c = (unsigned char *)s->val;
+ e = c + s->len;
+
+ while (c < e) {
+ if (!islower(*c)) {
+ register unsigned char *r;
+ zend_string *res = zend_string_alloc(s->len, 0);
+
+ if (c != (unsigned char*)s->val) {
+ memcpy(res->val, s->val, c - (unsigned char*)s->val);
+ }
+ r = c + (res->val - s->val);
+ while (c < e) {
+ *r = tolower(*c);
+ r++;
+ c++;
+ }
+ *r = '\0';
+ return res;
+ }
+ c++;
+ }
+ return zend_string_copy(s);
+}
+/* }}} */
+
/* {{{ proto string strtolower(string str)
Makes a string lowercase */
PHP_FUNCTION(strtolower)
{
zend_string *str;
- zend_string *result;
#ifndef FAST_ZPP
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) {
@@ -1419,9 +1479,7 @@ PHP_FUNCTION(strtolower)
ZEND_PARSE_PARAMETERS_END();
#endif
- result = zend_string_init(str->val, str->len, 0);
- php_strtolower(result->val, result->len);
- RETURN_NEW_STR(result);
+ RETURN_STR(php_string_tolower(str));
}
/* }}} */