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/msgformat - msgformat.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 52 54 96.3 %
Date: 2014-10-24 Functions: 5 5 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: Stanislav Malyshev <stas@zend.com>                          |
      14             :    +----------------------------------------------------------------------+
      15             :  */
      16             : 
      17             : #ifdef HAVE_CONFIG_H
      18             : #include "config.h"
      19             : #endif
      20             : 
      21             : #include <unicode/ustring.h>
      22             : #include <unicode/umsg.h>
      23             : 
      24             : #include "php_intl.h"
      25             : #include "msgformat_class.h"
      26             : #include "intl_convert.h"
      27             : 
      28             : /* {{{ */
      29          61 : static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) 
      30             : {
      31             :         char*       locale;
      32             :         char*       pattern;
      33          61 :         int         locale_len = 0, pattern_len = 0;
      34          61 :         UChar*      spattern     = NULL;
      35          61 :         int         spattern_len = 0;
      36             :         zval*       object;
      37             :         MessageFormatter_object* mfo;
      38          61 :         intl_error_reset( NULL TSRMLS_CC );
      39             : 
      40          61 :         object = return_value;
      41             :         /* Parse parameters. */
      42          61 :         if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "ss",
      43             :                 &locale, &locale_len, &pattern, &pattern_len ) == FAILURE )
      44             :         {
      45          10 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
      46             :                         "msgfmt_create: unable to parse input parameters", 0 TSRMLS_CC );
      47             :                 zval_dtor(return_value);
      48          10 :                 RETURN_NULL();
      49             :         }
      50             : 
      51          51 :         INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
      52          51 :         MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
      53             : 
      54             :         /* Convert pattern (if specified) to UTF-16. */
      55          96 :         if(pattern && pattern_len) {
      56          48 :                 intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo));
      57          51 :                 INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to UTF-16");
      58             :         } else {
      59           3 :                 spattern_len = 0;
      60           3 :                 spattern = NULL;
      61             :         }
      62             : 
      63          48 :         if(locale_len == 0) {
      64           3 :                 locale = INTL_G(default_locale);
      65             :         }
      66             : 
      67             : #ifdef MSG_FORMAT_QUOTE_APOS
      68          48 :         if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) {
      69           0 :                 INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to quote-friendly format");
      70             :         }
      71             : #endif
      72             : 
      73          48 :         if ((mfo)->mf_data.orig_format) {
      74           0 :                 msgformat_data_free(&mfo->mf_data TSRMLS_CC);
      75             :         }
      76             : 
      77          48 :         (mfo)->mf_data.orig_format = estrndup(pattern, pattern_len);
      78          48 :         (mfo)->mf_data.orig_format_len = pattern_len;
      79             :         
      80             :         /* Create an ICU message formatter. */
      81          48 :         MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(mfo));
      82             : 
      83          48 :         if(spattern) {
      84          45 :                 efree(spattern);
      85             :         }
      86             : 
      87          64 :         INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed");
      88             : }
      89             : /* }}} */
      90             : 
      91             : /* {{{ proto MessageFormatter MesssageFormatter::create( string $locale, string $pattern )
      92             :  * Create formatter. }}} */
      93             : /* {{{ proto MessageFormatter msgfmt_create( string $locale, string $pattern )
      94             :  * Create formatter.
      95             :  */
      96          52 : PHP_FUNCTION( msgfmt_create )
      97             : {
      98          52 :         object_init_ex( return_value, MessageFormatter_ce_ptr );
      99          52 :         msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
     100          52 : }
     101             : /* }}} */
     102             : 
     103             : /* {{{ proto void MessageFormatter::__construct( string $locale, string $pattern )
     104             :  * MessageFormatter object constructor.
     105             :  */
     106           9 : PHP_METHOD( MessageFormatter, __construct )
     107             : {
     108           9 :         return_value = getThis();
     109           9 :         msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
     110           9 : }
     111             : /* }}} */
     112             : 
     113             : /* {{{ proto int MessageFormatter::getErrorCode()
     114             :  * Get formatter's last error code. }}} */
     115             : /* {{{ proto int msgfmt_get_error_code( MessageFormatter $nf )
     116             :  * Get formatter's last error code.
     117             :  */
     118           3 : PHP_FUNCTION( msgfmt_get_error_code )
     119             : {
     120           3 :         zval*                    object  = NULL;
     121           3 :         MessageFormatter_object*  mfo     = NULL;
     122             : 
     123             :         /* Parse parameters. */
     124           3 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
     125             :                 &object, MessageFormatter_ce_ptr ) == FAILURE )
     126             :         {
     127           1 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     128             :                         "msgfmt_get_error_code: unable to parse input params", 0 TSRMLS_CC );
     129             : 
     130           1 :                 RETURN_FALSE;
     131             :         }
     132             : 
     133           2 :         mfo = (MessageFormatter_object *) zend_object_store_get_object( object TSRMLS_CC );
     134             : 
     135             :         /* Return formatter's last error code. */
     136           2 :         RETURN_LONG( INTL_DATA_ERROR_CODE(mfo) );
     137             : }
     138             : /* }}} */
     139             : 
     140             : /* {{{ proto string MessageFormatter::getErrorMessage( )
     141             :  * Get text description for formatter's last error code. }}} */
     142             : /* {{{ proto string msgfmt_get_error_message( MessageFormatter $coll )
     143             :  * Get text description for formatter's last error code.
     144             :  */
     145           3 : PHP_FUNCTION( msgfmt_get_error_message )
     146             : {
     147           3 :         char*                    message = NULL;
     148           3 :         zval*                    object  = NULL;
     149           3 :         MessageFormatter_object*  mfo     = NULL;
     150             : 
     151             :         /* Parse parameters. */
     152           3 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
     153             :                 &object, MessageFormatter_ce_ptr ) == FAILURE )
     154             :         {
     155           1 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     156             :                         "msgfmt_get_error_message: unable to parse input params", 0 TSRMLS_CC );
     157             : 
     158           1 :                 RETURN_FALSE;
     159             :         }
     160             : 
     161           2 :         mfo = (MessageFormatter_object *) zend_object_store_get_object( object TSRMLS_CC );
     162             : 
     163             :         /* Return last error message. */
     164           2 :         message = intl_error_get_message( &mfo->mf_data.error TSRMLS_CC );
     165           2 :         RETURN_STRING( message, 0);
     166             : }
     167             : /* }}} */
     168             : 
     169             : /*
     170             :  * Local variables:
     171             :  * tab-width: 4
     172             :  * c-basic-offset: 4
     173             :  * End:
     174             :  * vim600: noet sw=4 ts=4 fdm=marker
     175             :  * vim<600: noet sw=4 ts=4
     176             :  */

Generated by: LCOV version 1.10

Generated at Fri, 24 Oct 2014 05:21:48 +0000 (7 days ago)

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