[PHP-CVS] cvs: php-src /ext/standard array.c /ext/standard/tests/array locale_sort.phpt ZendEngine2 zend_operators.c

2005-09-12 Thread Derick Rethans
derick  Mon Sep 12 05:53:23 2005 EDT

  Modified files:  
/ZendEngine2zend_operators.c 
/php-src/ext/standard   array.c 
/php-src/ext/standard/tests/array   locale_sort.phpt 
  Log:
  - Reimplement SORT_LOCALE_STRING with ICU locales.
  
  
http://cvs.php.net/diff.php/ZendEngine2/zend_operators.c?r1=1.219r2=1.220ty=u
Index: ZendEngine2/zend_operators.c
diff -u ZendEngine2/zend_operators.c:1.219 ZendEngine2/zend_operators.c:1.220
--- ZendEngine2/zend_operators.c:1.219  Tue Aug 23 18:05:22 2005
+++ ZendEngine2/zend_operators.cMon Sep 12 05:53:20 2005
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: zend_operators.c,v 1.219 2005/08/23 22:05:22 andrei Exp $ */
+/* $Id: zend_operators.c,v 1.220 2005/09/12 09:53:20 derick Exp $ */
 
 #include ctype.h
 
@@ -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 @@
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 @@
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 @@
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)
 {
http://cvs.php.net/diff.php/php-src/ext/standard/array.c?r1=1.323r2=1.324ty=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.323 php-src/ext/standard/array.c:1.324
--- php-src/ext/standard/array.c:1.323  Thu Sep  1 07:58:39 2005
+++ php-src/ext/standard/array.cMon Sep 12 05:53:22 2005
@@ -21,7 +21,7 @@
+--+
 */
 
-/* $Id: array.c,v 1.323 2005/09/01 11:58:39 dmitry Exp $ */
+/* $Id: array.c,v 1.324 2005/09/12 09:53:22 derick Exp $ */
 
 #include php.h
 #include php_ini.h
@@ -163,11 +163,9 @@
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:
http://cvs.php.net/diff.php/php-src/ext/standard/tests/array/locale_sort.phpt?r1=1.3r2=1.4ty=u
Index: php-src/ext/standard/tests/array/locale_sort.phpt
diff -u php-src/ext/standard/tests/array/locale_sort.phpt:1.3 
php-src/ext/standard/tests/array/locale_sort.phpt:1.4
--- php-src/ext/standard/tests/array/locale_sort.phpt:1.3   Wed Aug 17 
10:01:06 2005
+++ php-src/ext/standard/tests/array/locale_sort.phpt   Mon Sep 12 05:53:23 2005
@@ -7,20 +7,21 @@
 }
 ?
 --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 @@
   [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 @@
   [uBC]=
   unicode(20) Colombie-Britannique
   [uPE]=
-  unicode(21) Île-du-Prince-Édouard
+  unicode(21) Île-du-Prince-Édouard
   [uMB]=
   unicode(8) Manitoba
   [uNB]=
   unicode(17) Nouveau-Brunswick
   [uNS]=
-  unicode(15) Nouvelle-Écosse
+  unicode(15) Nouvelle-Écosse
   [uNU]=
   unicode(7) Nunavut
   

Re: [PHP-CVS] cvs: php-src /ext/standard array.c /ext/standard/tests/array locale_sort.phpt ZendEngine2 zend_operators.c

2005-09-12 Thread Andrei Zmievski

Perhaps we should cache the locale object somewhere..

-Andrei

On Sep 12, 2005, at 2:53 AM, Derick Rethans wrote:


derick  Mon Sep 12 05:53:23 2005 EDT

  Modified files:
/ZendEngine2zend_operators.c
/php-src/ext/standard   array.c
/php-src/ext/standard/tests/array   locale_sort.phpt
  Log:
  - Reimplement SORT_LOCALE_STRING with ICU locales.


http://cvs.php.net/diff.php/ZendEngine2/zend_operators.c? 
r1=1.219r2=1.220ty=u

Index: ZendEngine2/zend_operators.c
diff -u ZendEngine2/zend_operators.c:1.219  
ZendEngine2/zend_operators.c:1.220

--- ZendEngine2/zend_operators.c:1.219  Tue Aug 23 18:05:22 2005
+++ ZendEngine2/zend_operators.cMon Sep 12 05:53:20 2005
@@ -17,7 +17,7 @@
 
+-- 
+

 */

-/* $Id: zend_operators.c,v 1.219 2005/08/23 22:05:22 andrei Exp $ */
+/* $Id: zend_operators.c,v 1.220 2005/09/12 09:53:20 derick Exp $ */

 #include ctype.h

@@ -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 @@
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 @@
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 @@
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)

 {
http://cvs.php.net/diff.php/php-src/ext/standard/array.c? 
r1=1.323r2=1.324ty=u

Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.323  
php-src/ext/standard/array.c:1.324

--- php-src/ext/standard/array.c:1.323  Thu Sep  1 07:58:39 2005
+++ php-src/ext/standard/array.cMon Sep 12 05:53:22 2005
@@ -21,7 +21,7 @@
 
+-- 
+

 */

-/* $Id: array.c,v 1.323 2005/09/01 11:58:39 dmitry Exp $ */
+/* $Id: array.c,v 1.324 2005/09/12 09:53:22 derick Exp $ */

 #include php.h
 #include php_ini.h
@@ -163,11 +163,9 @@
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:
http://cvs.php.net/diff.php/php-src/ext/standard/tests/array/ 
locale_sort.phpt?r1=1.3r2=1.4ty=u

Index: php-src/ext/standard/tests/array/locale_sort.phpt
diff -u php-src/ext/standard/tests/array/locale_sort.phpt:1.3  
php-src/ext/standard/tests/array/locale_sort.phpt:1.4
--- php-src/ext/standard/tests/array/locale_sort.phpt:1.3	Wed Aug 17  
10:01:06 2005
+++ php-src/ext/standard/tests/array/locale_sort.phpt	Mon Sep 12  
05:53:23 2005

@@ -7,20 +7,21 @@
 }
 ?
 --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 @@
   [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 @@
   [uBC]=
   unicode(20) Colombie-Britannique
   [uPE]=
-  unicode(21) Île-du-Prince-Édouard
+  unicode(21) Île-du-Prince-Édouard
   [uMB]=
   unicode(8) Manitoba
   [uNB]=
   unicode(17) Nouveau-Brunswick
   

Re: [PHP-CVS] cvs: php-src /ext/standard array.c /ext/standard/tests/array locale_sort.phpt ZendEngine2 zend_operators.c

2005-09-12 Thread Derick Rethans
On Mon, 12 Sep 2005, Andrei Zmievski wrote:

 Perhaps we should cache the locale object somewhere..

yes, that's already on my todo list. Have some basic stuff working for 
that already, but no time to finish. Probably tomorrow on the plane.

Derick

-- 
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php