mirror of
https://github.com/php/php-src.git
synced 2025-01-27 14:13:41 +08:00
- MFB: Added the sorting flag SORT_LOCALE_STRING to the sort() functions which
makes them sort based on the current locale. (Derick)
This commit is contained in:
parent
b3a32e6d21
commit
4bae5cb4d0
@ -1222,6 +1222,35 @@ ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_D
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
#if HAVE_STRCOLL
|
||||
ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
|
||||
{
|
||||
zval op1_copy, op2_copy;
|
||||
int use_copy1, use_copy2;
|
||||
|
||||
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
|
||||
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
|
||||
|
||||
if (use_copy1) {
|
||||
op1 = &op1_copy;
|
||||
}
|
||||
if (use_copy2) {
|
||||
op2 = &op2_copy;
|
||||
}
|
||||
|
||||
result->value.lval = strcoll(op1->value.str.val, op2->value.str.val);
|
||||
result->type = IS_LONG;
|
||||
|
||||
if (use_copy1) {
|
||||
zval_dtor(op1);
|
||||
}
|
||||
if (use_copy2) {
|
||||
zval_dtor(op2);
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
|
||||
{
|
||||
zval op1_copy, op2_copy;
|
||||
|
@ -179,6 +179,9 @@ ZEND_API int zval_is_true(zval *op);
|
||||
ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
||||
ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
||||
ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
||||
#if HAVE_STRCOLL
|
||||
ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
||||
#endif
|
||||
|
||||
ZEND_API void zend_str_tolower(char *str, unsigned int length);
|
||||
ZEND_API char *zend_str_tolower_copy(char *dest, const char *source, unsigned int length);
|
||||
|
@ -65,6 +65,7 @@ php_array_globals array_globals;
|
||||
#define SORT_REGULAR 0
|
||||
#define SORT_NUMERIC 1
|
||||
#define SORT_STRING 2
|
||||
#define SORT_LOCALE_STRING 5
|
||||
|
||||
#define SORT_DESC 3
|
||||
#define SORT_ASC 4
|
||||
@ -114,6 +115,8 @@ PHP_MINIT_FUNCTION(array)
|
||||
REGISTER_LONG_CONSTANT("SORT_REGULAR", SORT_REGULAR, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("SORT_NUMERIC", SORT_NUMERIC, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("SORT_STRING", SORT_STRING, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("SORT_LOCALE_STRING", SORT_LOCALE_STRING, CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("CASE_LOWER", CASE_LOWER, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("CASE_UPPER", CASE_UPPER, CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
@ -143,6 +146,12 @@ static void set_compare_func(int sort_type TSRMLS_DC)
|
||||
ARRAYG(compare_func) = string_compare_function;
|
||||
break;
|
||||
|
||||
#if HAVE_STRCOLL
|
||||
case SORT_LOCALE_STRING:
|
||||
ARRAYG(compare_func) = string_locale_compare_function;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SORT_REGULAR:
|
||||
default:
|
||||
ARRAYG(compare_func) = compare_function;
|
||||
|
Loading…
Reference in New Issue
Block a user