PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/intl/collator - collator_compare.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 29 42 69.0 %
Date: 2014-09-19 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | This source file is subject to version 3.01 of the PHP license,      |
       6             :    | that is bundled with this package in the file LICENSE, and is        |
       7             :    | available through the world-wide-web at the following url:           |
       8             :    | http://www.php.net/license/3_01.txt                                  |
       9             :    | If you did not receive a copy of the PHP license and are unable to   |
      10             :    | obtain it through the world-wide-web, please send a note to          |
      11             :    | license@php.net so we can mail you a copy immediately.               |
      12             :    +----------------------------------------------------------------------+
      13             :    | Authors: Vadim Savchuk <vsavchuk@productengine.com>                  |
      14             :    |          Dmitry Lakhtyuk <dlakhtyuk@productengine.com>               |
      15             :    +----------------------------------------------------------------------+
      16             :  */
      17             : 
      18             : #ifdef HAVE_CONFIG_H
      19             : #include "config.h"
      20             : #endif
      21             : 
      22             : #include "php_intl.h"
      23             : #include "collator_class.h"
      24             : #include "collator_compare.h"
      25             : #include "intl_convert.h"
      26             : 
      27             : /* {{{ proto int Collator::compare( string $str1, string $str2 )
      28             :  * Compare two strings. }}} */
      29             : /* {{{ proto int collator_compare( Collator $coll, string $str1, string $str2 )
      30             :  * Compare two strings.
      31             :  */
      32          70 : PHP_FUNCTION( collator_compare )
      33             : {
      34          70 :         char*            str1      = NULL;
      35          70 :         char*            str2      = NULL;
      36          70 :         size_t              str1_len  = 0;
      37          70 :         size_t              str2_len  = 0;
      38             : 
      39          70 :         UChar*           ustr1     = NULL;
      40          70 :         UChar*           ustr2     = NULL;
      41          70 :         int              ustr1_len = 0;
      42          70 :         int              ustr2_len = 0;
      43             : 
      44             :         UCollationResult result;
      45             : 
      46          70 :         COLLATOR_METHOD_INIT_VARS
      47             : 
      48             :         /* Parse parameters. */
      49          70 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss",
      50             :                 &object, Collator_ce_ptr, &str1, &str1_len, &str2, &str2_len ) == FAILURE )
      51             :         {
      52           1 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
      53             :                          "collator_compare: unable to parse input params", 0 TSRMLS_CC );
      54             : 
      55           1 :                 RETURN_FALSE;
      56             :         }
      57             : 
      58             :         /* Fetch the object. */
      59          69 :         COLLATOR_METHOD_FETCH_OBJECT;
      60             : 
      61          69 :         if (!co || !co->ucoll) {
      62           1 :                 intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
      63           1 :                 intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
      64             :                         "Object not initialized", 0 TSRMLS_CC );
      65           1 :                 php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Object not initialized");
      66             : 
      67           0 :                 RETURN_FALSE;
      68             :         }
      69             : 
      70             :         /*
      71             :          * Compare given strings (converting them to UTF-16 first).
      72             :          */
      73             : 
      74             :         /* First convert the strings to UTF-16. */
      75          68 :         intl_convert_utf8_to_utf16(
      76             :                 &ustr1, &ustr1_len, str1, str1_len, COLLATOR_ERROR_CODE_P( co ) );
      77          68 :         if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) )
      78             :         {
      79             :                 /* Set global error code. */
      80           0 :                 intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
      81             : 
      82             :                 /* Set error messages. */
      83           0 :                 intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
      84             :                         "Error converting first argument to UTF-16", 0 TSRMLS_CC );
      85           0 :                 if (ustr1) {
      86           0 :                         efree( ustr1 );
      87             :                 }
      88           0 :                 RETURN_FALSE;
      89             :         }
      90             : 
      91          68 :         intl_convert_utf8_to_utf16(
      92             :                 &ustr2, &ustr2_len, str2, str2_len, COLLATOR_ERROR_CODE_P( co ) );
      93          68 :         if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) )
      94             :         {
      95             :                 /* Set global error code. */
      96           0 :                 intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
      97             : 
      98             :                 /* Set error messages. */
      99           0 :                 intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
     100             :                         "Error converting second argument to UTF-16", 0 TSRMLS_CC );
     101           0 :                 if (ustr1) {
     102           0 :                         efree( ustr1 );
     103             :                 }
     104           0 :                 if (ustr2) {
     105           0 :                         efree( ustr2 );
     106             :                 }
     107           0 :                 RETURN_FALSE;
     108             :         }
     109             : 
     110             :         /* Then compare them. */
     111         136 :         result = ucol_strcoll(
     112          68 :                 co->ucoll,
     113             :                 ustr1, ustr1_len,
     114             :                 ustr2, ustr2_len );
     115             : 
     116          68 :         if( ustr1 )
     117          68 :                 efree( ustr1 );
     118          68 :         if( ustr2 )
     119          68 :                 efree( ustr2 );
     120             : 
     121             :         /* Return result of the comparison. */
     122          68 :         RETURN_LONG( result );
     123             : }
     124             : /* }}} */
     125             : 
     126             : /*
     127             :  * Local variables:
     128             :  * tab-width: 4
     129             :  * c-basic-offset: 4
     130             :  * End:
     131             :  * vim600: noet sw=4 ts=4 fdm=marker
     132             :  * vim<600: noet sw=4 ts=4
     133             :  */

Generated by: LCOV version 1.10

Generated at Fri, 19 Sep 2014 17:11:08 +0000 (4 hours ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.