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

LTP GCOV extension - code coverage report
Current view: directory - intl/collator - collator_compare.c
Test: PHP Code Coverage
Date: 2009-11-21 Instrumented lines: 33
Code covered: 66.7 % Executed lines: 22
Legend: not executed executed

       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                 : PHP_FUNCTION( collator_compare )
      33              68 : {
      34              68 :         char*            str1      = NULL;
      35              68 :         char*            str2      = NULL;
      36              68 :         int              str1_len  = 0;
      37              68 :         int              str2_len  = 0;
      38                 : 
      39              68 :         UChar*           ustr1     = NULL;
      40              68 :         UChar*           ustr2     = NULL;
      41              68 :         int              ustr1_len = 0;
      42              68 :         int              ustr2_len = 0;
      43                 : 
      44                 :         UCollationResult result;
      45                 : 
      46              68 :         COLLATOR_METHOD_INIT_VARS
      47                 : 
      48                 :         /* Parse parameters. */
      49              68 :         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               0 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
      53                 :                          "collator_compare: unable to parse input params", 0 TSRMLS_CC );
      54                 : 
      55               0 :                 RETURN_FALSE;
      56                 :         }
      57                 : 
      58                 :         /* Fetch the object. */
      59              68 :         COLLATOR_METHOD_FETCH_OBJECT;
      60                 : 
      61                 : 
      62                 :         /*
      63                 :          * Compare given strings (converting them to UTF-16 first).
      64                 :          */
      65                 : 
      66                 :         /* First convert the strings to UTF-16. */
      67              68 :         intl_convert_utf8_to_utf16(
      68                 :                 &ustr1, &ustr1_len, str1, str1_len, COLLATOR_ERROR_CODE_P( co ) );
      69              68 :         if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) )
      70                 :         {
      71                 :                 /* Set global error code. */
      72               0 :                 intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
      73                 : 
      74                 :                 /* Set error messages. */
      75               0 :                 intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
      76                 :                         "Error converting first argument to UTF-16", 0 TSRMLS_CC );
      77               0 :                 efree( ustr1 );
      78               0 :                 RETURN_FALSE;
      79                 :         }
      80                 : 
      81              68 :         intl_convert_utf8_to_utf16(
      82                 :                 &ustr2, &ustr2_len, str2, str2_len, COLLATOR_ERROR_CODE_P( co ) );
      83              68 :         if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) )
      84                 :         {
      85                 :                 /* Set global error code. */
      86               0 :                 intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
      87                 : 
      88                 :                 /* Set error messages. */
      89               0 :                 intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
      90                 :                         "Error converting second argument to UTF-16", 0 TSRMLS_CC );
      91               0 :                 efree( ustr1 );
      92               0 :                 efree( ustr2 );
      93               0 :                 RETURN_FALSE;
      94                 :         }
      95                 : 
      96                 :         /* Then compare them. */
      97              68 :         result = ucol_strcoll(
      98                 :                 co->ucoll,
      99                 :                 ustr1, ustr1_len,
     100                 :                 ustr2, ustr2_len );
     101                 : 
     102              68 :         if( ustr1 )
     103              68 :                 efree( ustr1 );
     104              68 :         if( ustr2 )
     105              68 :                 efree( ustr2 );
     106                 : 
     107                 :         /* Return result of the comparison. */
     108              68 :         RETURN_LONG( result );
     109                 : }
     110                 : /* }}} */
     111                 : 
     112                 : /*
     113                 :  * Local variables:
     114                 :  * tab-width: 4
     115                 :  * c-basic-offset: 4
     116                 :  * End:
     117                 :  * vim600: noet sw=4 ts=4 fdm=marker
     118                 :  * vim<600: noet sw=4 ts=4
     119                 :  */

Generated by: LTP GCOV extension version 1.5

Generated at Sat, 21 Nov 2009 12:27:01 +0000 (3 days ago)

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