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/msgformat - msgformat_attr.c
Test: PHP Code Coverage
Date: 2009-11-21 Instrumented lines: 40
Code covered: 77.5 % Executed lines: 31
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: Stanislav Malyshev <stas@zend.com>                          |
      14                 :    +----------------------------------------------------------------------+
      15                 :  */
      16                 : 
      17                 : #ifdef HAVE_CONFIG_H
      18                 : #include "config.h"
      19                 : #endif
      20                 : 
      21                 : #include "php_intl.h"
      22                 : #include "msgformat_class.h"
      23                 : #include "msgformat_attr.h"
      24                 : #include "intl_convert.h"
      25                 : 
      26                 : #include <unicode/ustring.h>
      27                 : 
      28                 : 
      29                 : /* {{{ proto string MessageFormatter::getPattern( )
      30                 :  * Get formatter pattern. }}} */
      31                 : /* {{{ proto string msgfmt_get_pattern( MessageFormatter $mf )
      32                 :  * Get formatter pattern.
      33                 :  */
      34                 : PHP_FUNCTION( msgfmt_get_pattern )
      35               8 : {
      36               8 :         MSG_FORMAT_METHOD_INIT_VARS;
      37                 : 
      38                 :         /* Parse parameters. */
      39               8 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, MessageFormatter_ce_ptr ) == FAILURE )
      40                 :         {
      41               0 :                 intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,  
      42                 :                         "msgfmt_get_pattern: unable to parse input params", 0 TSRMLS_CC );
      43               0 :                 RETURN_FALSE;
      44                 :         }
      45                 : 
      46                 :         /* Fetch the object. */
      47               8 :         MSG_FORMAT_METHOD_FETCH_OBJECT;
      48                 : 
      49               8 :         if(mfo->mf_data.orig_format) {
      50               8 :                 RETURN_STRINGL(mfo->mf_data.orig_format, mfo->mf_data.orig_format_len, 1);
      51                 :         }
      52                 : 
      53               0 :         RETURN_FALSE;
      54                 : }
      55                 : /* }}} */
      56                 : 
      57                 : /* {{{ proto bool MessageFormatter::setPattern( string $pattern )
      58                 :  * Set formatter pattern. }}} */
      59                 : /* {{{ proto bool msgfmt_set_pattern( MessageFormatter $mf, string $pattern )
      60                 :  * Set formatter pattern.
      61                 :  */
      62                 : PHP_FUNCTION( msgfmt_set_pattern )
      63               4 : {
      64               4 :         char*       value = NULL;
      65               4 :         int         value_len = 0;
      66               4 :         int         spattern_len = 0;
      67               4 :         UChar*      spattern  = NULL;
      68               4 :         MSG_FORMAT_METHOD_INIT_VARS;
      69                 : 
      70                 :         /* Parse parameters. */
      71               4 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
      72                 :                 &object, MessageFormatter_ce_ptr, &value, &value_len ) == FAILURE )
      73                 :         {
      74               0 :                 intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,  
      75                 :                         "msgfmt_set_pattern: unable to parse input params", 0 TSRMLS_CC);
      76               0 :                 RETURN_FALSE;
      77                 :         }
      78                 : 
      79               4 :         MSG_FORMAT_METHOD_FETCH_OBJECT;
      80                 : 
      81                 :         /* Convert given pattern to UTF-16. */
      82               4 :         intl_convert_utf8_to_utf16(&spattern, &spattern_len, value, value_len, &INTL_DATA_ERROR_CODE(mfo));
      83               4 :         INTL_METHOD_CHECK_STATUS(mfo, "Error converting pattern to UTF-16" );
      84                 : 
      85               4 :         if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) {
      86               0 :                 intl_error_set( NULL, U_INVALID_FORMAT_ERROR,
      87                 :                         "msgfmt_set_pattern: error converting pattern to quote-friendly format", 0 TSRMLS_CC );
      88               0 :                 RETURN_FALSE;
      89                 :         }
      90                 : 
      91                 :         /* TODO: add parse error information */
      92               4 :         umsg_applyPattern(MSG_FORMAT_OBJECT(mfo), spattern, spattern_len, NULL, &INTL_DATA_ERROR_CODE(mfo));
      93               4 :         efree(spattern);
      94               4 :         INTL_METHOD_CHECK_STATUS(mfo, "Error setting symbol value");
      95                 : 
      96               4 :         if(mfo->mf_data.orig_format) {
      97               4 :                 efree(mfo->mf_data.orig_format);
      98                 :         }
      99               4 :         mfo->mf_data.orig_format = estrndup(value, value_len);
     100               4 :         mfo->mf_data.orig_format_len = value_len;
     101                 : 
     102               4 :         RETURN_TRUE;
     103                 : }
     104                 : /* }}} */
     105                 : 
     106                 : /* {{{ proto string MessageFormatter::getLocale()
     107                 :  * Get formatter locale. }}} */
     108                 : /* {{{ proto string msgfmt_get_locale(MessageFormatter $mf)
     109                 :  * Get formatter locale.
     110                 :  */
     111                 : PHP_FUNCTION( msgfmt_get_locale )
     112               6 : {
     113                 :         char *loc;
     114               6 :         MSG_FORMAT_METHOD_INIT_VARS;
     115                 : 
     116                 :         /* Parse parameters. */
     117               6 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
     118                 :                 &object, MessageFormatter_ce_ptr ) == FAILURE )
     119                 :         {
     120               0 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     121                 :                         "msgfmt_get_locale: unable to parse input params", 0 TSRMLS_CC );
     122                 : 
     123               0 :                 RETURN_FALSE;
     124                 :         }
     125                 : 
     126                 :         /* Fetch the object. */
     127               6 :         MSG_FORMAT_METHOD_FETCH_OBJECT;
     128                 : 
     129               6 :         loc = (char *)umsg_getLocale(MSG_FORMAT_OBJECT(mfo));
     130               6 :         RETURN_STRING(loc, 1);
     131                 : }
     132                 : /* }}} */
     133                 : 
     134                 : /*
     135                 :  * Local variables:
     136                 :  * tab-width: 4
     137                 :  * c-basic-offset: 4
     138                 :  * End:
     139                 :  * vim600: noet sw=4 ts=4 fdm=marker
     140                 :  * vim<600: noet sw=4 ts=4
     141                 :  */

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.