]> granicus.if.org Git - php/commitdiff
Unicode support for strcoll().
authorAndrei Zmievski <andrei@php.net>
Mon, 14 Aug 2006 22:00:46 +0000 (22:00 +0000)
committerAndrei Zmievski <andrei@php.net>
Mon, 14 Aug 2006 22:00:46 +0000 (22:00 +0000)
ext/standard/string.c
unicode-progress.txt

index e2e045e26e43e7485cf0f5ab028cbcc06c2c45cc..850be0e9dd28d4071bcc6212848ac705746c4b88 100644 (file)
@@ -494,24 +494,32 @@ PHP_FUNCTION(nl_langinfo)
 #endif
 /* }}} */
 
-#ifdef HAVE_STRCOLL
-/* {{{ proto int strcoll(string str1, string str2)
+/* {{{ proto int strcoll(string str1, string str2) U
    Compares two strings using the current locale */
 PHP_FUNCTION(strcoll)
 {
-       zval **s1, **s2;
+       zstr s1, s2;
+       int s1_len, s2_len;
+       zend_uchar str_type;
 
-       if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "TT", &s1, &s1_len,
+                                                         &str_type, &s2, &s2_len, &str_type) == FAILURE) {
+               return;
+       }
+
+       if (str_type == IS_UNICODE) {
+               RETURN_LONG(ZEND_COLL_RESULT(ucol_strcoll(UG(default_collator)->coll, s1.u, s1_len, s2.u, s2_len)));
+       } else {
+#ifdef HAVE_STRCOLL
+               RETURN_LONG(strcoll((const char *) s1.s,
+                                                       (const char *) s2.s));
+#else
+               RETURN_FALSE;
+#endif
        }
-       convert_to_string_ex(s1);
-       convert_to_string_ex(s2);
 
-       RETURN_LONG(strcoll((const char *) Z_STRVAL_PP(s1),
-                           (const char *) Z_STRVAL_PP(s2)));
 }
 /* }}} */
-#endif
 
 /* {{{ php_charmask
  * Fills a 256-byte bytemask with input. You can specify a range like 'a..z',
index 7196354252e5ca7bd2472091eab340898a61be5d..8fc9c72ff0888990d41e243280a56b78ebd120f8 100644 (file)
@@ -43,8 +43,6 @@ ext/standard
         Params API. Rest - no idea yet.
 
     str_replace()
-        Params API, IS_UNICODE upgrade
-
     stri_replace()
         Params API, IS_UNICODE upgrade. Case-folding should be handled
         similar to stristr().
@@ -52,9 +50,6 @@ ext/standard
     str_word_count()
         Params API, IS_UNICODE support, using u_isalpha(), etc.
     
-    strcoll()
-        Params API, upgrade to use Collator if TT == IS_UNICODE, test
-
     stristr()
         This is the problematic one. There are a few approaches:
 
@@ -188,6 +183,7 @@ ext/standard
     str_rot13()
     str_shuffle()
     str_split()
+    strcoll()
     strcspn()
     strip_tags()
     stripcslashes()