From: Derick Rethans Date: Mon, 12 Sep 2005 09:53:23 +0000 (+0000) Subject: - Reimplement SORT_LOCALE_STRING with ICU locales. X-Git-Tag: RELEASE_0_9_0~235 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=161777af261381556d698f679db88e336d2701ec;p=php - Reimplement SORT_LOCALE_STRING with ICU locales. --- diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 5998453e5f..66b141610a 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -32,6 +32,7 @@ #include "zend_strtod.h" #include "unicode/uchar.h" +#include "unicode/ucol.h" #define LONG_SIGN_MASK (1L << (8*sizeof(long)-1)) @@ -1508,14 +1509,17 @@ 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; + UErrorCode status = U_ZERO_ERROR; + UCollator *col; - zend_make_printable_zval(op1, &op1_copy, &use_copy1); - zend_make_printable_zval(op2, &op2_copy, &use_copy2); + col = ucol_open(UG(default_locale), &status); + + zend_make_unicode_zval(op1, &op1_copy, &use_copy1); + zend_make_unicode_zval(op2, &op2_copy, &use_copy2); if (use_copy1) { op1 = &op1_copy; @@ -1524,7 +1528,7 @@ ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 T op2 = &op2_copy; } - result->value.lval = strcoll(op1->value.str.val, op2->value.str.val); + result->value.lval = ucol_strcoll(col, op1->value.str.val, op1->value.str.len, op2->value.str.val, op2->value.str.len); result->type = IS_LONG; if (use_copy1) { @@ -1533,9 +1537,11 @@ ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 T if (use_copy2) { zval_dtor(op2); } + + ucol_close(col); + return SUCCESS; } -#endif ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) { diff --git a/ext/standard/array.c b/ext/standard/array.c index 53251dc4c8..873f73eca6 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -163,11 +163,9 @@ 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: diff --git a/ext/standard/tests/array/locale_sort.phpt b/ext/standard/tests/array/locale_sort.phpt index ba53f2c6c4..b99017ce41 100644 --- a/ext/standard/tests/array/locale_sort.phpt +++ b/ext/standard/tests/array/locale_sort.phpt @@ -7,20 +7,21 @@ if ("fr_FR" != setlocale(LC_CTYPE, "fr_FR")) { } ?> --INI-- -unicode.script_encoding=ISO-8859-1 -unicode.output_encoding=ISO-8859-1 +unicode.script_encoding=UTF-8 +unicode.output_encoding=UTF-8 --FILE-- "Alberta", "BC" => "Colombie-Britannique", "MB" => "Manitoba", "NB" => "Nouveau-Brunswick", "NL" => "Terre-Neuve-et-Labrador", -"NS" => "Nouvelle-Écosse", +"NS" => "Nouvelle-Écosse", "ON" => "Ontario", -"PE" => "Île-du-Prince-Édouard", -"QC" => "Québec", +"PE" => "Île-du-Prince-Édouard", +"QC" => "Québec", "SK" => "Saskatchewan", "NT" => "Territoires du Nord-Ouest", "NU" => "Nunavut", @@ -35,19 +36,19 @@ array(13) { ["BC"]=> string(20) "Colombie-Britannique" ["PE"]=> - string(21) "Île-du-Prince-Édouard" + string(21) "Île-du-Prince-Édouard" ["MB"]=> string(8) "Manitoba" ["NB"]=> string(17) "Nouveau-Brunswick" ["NS"]=> - string(15) "Nouvelle-Écosse" + string(15) "Nouvelle-Écosse" ["NU"]=> string(7) "Nunavut" ["ON"]=> string(7) "Ontario" ["QC"]=> - string(6) "Québec" + string(6) "Québec" ["SK"]=> string(12) "Saskatchewan" ["NL"]=> @@ -64,19 +65,19 @@ array(13) { [u"BC"]=> unicode(20) "Colombie-Britannique" [u"PE"]=> - unicode(21) "Île-du-Prince-Édouard" + unicode(21) "Île-du-Prince-Édouard" [u"MB"]=> unicode(8) "Manitoba" [u"NB"]=> unicode(17) "Nouveau-Brunswick" [u"NS"]=> - unicode(15) "Nouvelle-Écosse" + unicode(15) "Nouvelle-Écosse" [u"NU"]=> unicode(7) "Nunavut" [u"ON"]=> unicode(7) "Ontario" [u"QC"]=> - unicode(6) "Québec" + unicode(6) "Québec" [u"SK"]=> unicode(12) "Saskatchewan" [u"NL"]=>