stas                                     Mon, 26 Oct 2009 22:35:48 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=289961

Log:
add collator_get_sort_key()

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/intl/collator/collator_class.c
    U   php/php-src/branches/PHP_5_3/ext/intl/collator/collator_sort.c
    U   php/php-src/branches/PHP_5_3/ext/intl/collator/collator_sort.h
    U   php/php-src/branches/PHP_5_3/ext/intl/php_intl.c
    U   php/php-src/branches/PHP_5_3/ext/intl/tests/ut_common.inc

Modified: php/php-src/branches/PHP_5_3/ext/intl/collator/collator_class.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/collator/collator_class.c     
2009-10-26 22:18:01 UTC (rev 289960)
+++ php/php-src/branches/PHP_5_3/ext/intl/collator/collator_class.c     
2009-10-26 22:35:48 UTC (rev 289961)
@@ -125,6 +125,7 @@
        PHP_NAMED_FE( getLocale, ZEND_FN( collator_get_locale ), collator_1_arg 
)
        PHP_NAMED_FE( getErrorCode, ZEND_FN( collator_get_error_code ), 
collator_0_args )
        PHP_NAMED_FE( getErrorMessage, ZEND_FN( collator_get_error_message ), 
collator_0_args )
+       PHP_NAMED_FE( getSortKey, ZEND_FN( collator_get_sort_key ), 
collator_2_args )
        { NULL, NULL, NULL }
 };
 /* }}} */

Modified: php/php-src/branches/PHP_5_3/ext/intl/collator/collator_sort.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/collator/collator_sort.c      
2009-10-26 22:18:01 UTC (rev 289960)
+++ php/php-src/branches/PHP_5_3/ext/intl/collator/collator_sort.c      
2009-10-26 22:35:48 UTC (rev 289961)
@@ -523,6 +523,69 @@
 }
 /* }}} */

+/* {{{ proto bool Collator::getSortKey( Collator $coll, string $str )
+ * Get a sort key for a string from a Collator. }}} */
+/* {{{ proto bool collator_get_sort_key( Collator $coll, string $str )
+ * Get a sort key for a string from a Collator. }}} */
+PHP_FUNCTION( collator_get_sort_key )
+{
+       char*            str      = NULL;
+       int              str_len  = 0;
+       UChar*           ustr     = NULL;
+       int              ustr_len = 0;
+       uint8_t*         key     = NULL;
+       int              key_len = 0;
+
+       COLLATOR_METHOD_INIT_VARS
+
+       /* Parse parameters. */
+       if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), 
"Os",
+               &object, Collator_ce_ptr, &str, &str_len ) == FAILURE )
+       {
+               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
+                        "collator_get_sort_key: unable to parse input params", 
0 TSRMLS_CC );
+
+               RETURN_FALSE;
+       }
+
+       /* Fetch the object. */
+       COLLATOR_METHOD_FETCH_OBJECT;
+
+
+       /*
+        * Compare given strings (converting them to UTF-16 first).
+        */
+
+       /* First convert the strings to UTF-16. */
+       intl_convert_utf8_to_utf16(
+               &ustr, &ustr_len, str, str_len, COLLATOR_ERROR_CODE_P( co ) );
+       if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) )
+       {
+               /* Set global error code. */
+               intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC 
);
+
+               /* Set error messages. */
+               intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
+                       "Error converting first argument to UTF-16", 0 
TSRMLS_CC );
+               efree( ustr );
+               RETURN_FALSE;
+       }
+
+       key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, key, 0);
+       if(!key_len) {
+               efree( ustr );
+               RETURN_FALSE;
+       }
+       key = emalloc(key_len);
+       key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, key, key_len);
+       efree( ustr );
+       if(!key_len) {
+               RETURN_FALSE;
+       }
+       RETURN_STRINGL((char *)key, key_len, 0);
+}
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4

Modified: php/php-src/branches/PHP_5_3/ext/intl/collator/collator_sort.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/collator/collator_sort.h      
2009-10-26 22:18:01 UTC (rev 289960)
+++ php/php-src/branches/PHP_5_3/ext/intl/collator/collator_sort.h      
2009-10-26 22:35:48 UTC (rev 289961)
@@ -24,6 +24,7 @@

 PHP_FUNCTION( collator_sort );
 PHP_FUNCTION( collator_sort_with_sort_keys );
+PHP_FUNCTION( collator_get_sort_key );
 PHP_FUNCTION( collator_asort );

 #endif // COLLATOR_SORT_H

Modified: php/php-src/branches/PHP_5_3/ext/intl/php_intl.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/php_intl.c    2009-10-26 22:18:01 UTC 
(rev 289960)
+++ php/php-src/branches/PHP_5_3/ext/intl/php_intl.c    2009-10-26 22:35:48 UTC 
(rev 289961)
@@ -351,6 +351,7 @@
        PHP_FE( collator_get_locale, collator_1_arg )
        PHP_FE( collator_get_error_code, collator_0_args )
        PHP_FE( collator_get_error_message, collator_0_args )
+       PHP_FE( collator_get_sort_key, collator_2_args )

        /* formatter functions */
        PHP_FE( numfmt_create, arginfo_numfmt_create )

Modified: php/php-src/branches/PHP_5_3/ext/intl/tests/ut_common.inc
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/tests/ut_common.inc   2009-10-26 
22:18:01 UTC (rev 289960)
+++ php/php-src/branches/PHP_5_3/ext/intl/tests/ut_common.inc   2009-10-26 
22:35:48 UTC (rev 289961)
@@ -59,6 +59,10 @@
 {
     return $GLOBALS['oo-mode'] ? $coll->sortWithSortKeys( $arr ) : 
collator_sort_with_sort_keys( $coll, $arr );
 }
+function ut_coll_get_sort_key( $coll, $str )
+{
+    return $GLOBALS['oo-mode'] ? $coll->getSortKey( $str ) : 
collator_get_sort_key( $coll, $str );
+}
 function ut_coll_asort( $coll, &$arr, $sort_flag = Collator::SORT_REGULAR )
 {
     return $GLOBALS['oo-mode'] ? $coll->asort( $arr, $sort_flag ) : 
collator_asort( $coll, $arr, $sort_flag );

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

Reply via email to