]> granicus.if.org Git - php/commitdiff
- Reimplement SORT_LOCALE_STRING with ICU locales.
authorDerick Rethans <derick@php.net>
Mon, 12 Sep 2005 09:53:23 +0000 (09:53 +0000)
committerDerick Rethans <derick@php.net>
Mon, 12 Sep 2005 09:53:23 +0000 (09:53 +0000)
Zend/zend_operators.c
ext/standard/array.c
ext/standard/tests/array/locale_sort.phpt

index 5998453e5f567295eb7a975ca4a817fcd48f20e3..66b141610acafb5a916472bb7e6af408349c3992 100644 (file)
@@ -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)
 {
index 53251dc4c83ef4b947a2c0d1c32ee786536f0a6f..873f73eca65565da45e885ae3d0beb106b6cb545 100644 (file)
@@ -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:
index ba53f2c6c44854906cf2c78541dde3b9f3362b3c..b99017ce41462d75cb811f01deb6f30a9dbc95e4 100644 (file)
@@ -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--
 <?php
 setlocale(LC_ALL, 'fr_FR');
+i18n_loc_set_default('fr_FR');
 $table = array("AB" => "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"]=>