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_format.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 0 53 0.0 %
Date: 2014-04-16 Functions: 0 3 0.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             : 
      23             : #include "php_intl.h"
      24             : #include "msgformat_class.h"
      25             : #include "msgformat_format.h"
      26             : #include "msgformat_data.h"
      27             : #include "msgformat_helpers.h"
      28             : #include "intl_convert.h"
      29             : 
      30             : #ifndef Z_ADDREF_P
      31             : #define Z_ADDREF_P(z) ((z)->refcount++)
      32             : #endif
      33             : 
      34             : /* {{{ */
      35           0 : static void msgfmt_do_format(MessageFormatter_object *mfo, zval *args, zval *return_value TSRMLS_DC)
      36             : {
      37             :         int count;
      38           0 :         UChar* formatted = NULL;
      39           0 :         int formatted_len = 0;
      40             :         HashTable *args_copy;
      41             : 
      42           0 :         count = zend_hash_num_elements(Z_ARRVAL_P(args));
      43             : 
      44           0 :         ALLOC_HASHTABLE(args_copy);
      45           0 :         zend_hash_init(args_copy, count, NULL, ZVAL_PTR_DTOR, 0);
      46           0 :         zend_hash_copy(args_copy, Z_ARRVAL_P(args), (copy_ctor_func_t)zval_add_ref,
      47             :                 NULL, sizeof(zval*));
      48             : 
      49           0 :         umsg_format_helper(mfo, args_copy, &formatted, &formatted_len TSRMLS_CC);
      50             : 
      51           0 :         zend_hash_destroy(args_copy);
      52           0 :         efree(args_copy);
      53             : 
      54           0 :         if (formatted && U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) {
      55           0 :                         efree(formatted);
      56             :         }
      57             : 
      58           0 :         if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) {
      59           0 :                 RETURN_FALSE;
      60             :         } else {
      61           0 :                 INTL_METHOD_RETVAL_UTF8(mfo, formatted, formatted_len, 1);
      62             :         }
      63             : }
      64             : /* }}} */
      65             : 
      66             : /* {{{ proto mixed MessageFormatter::format( array $args )
      67             :  * Format a message. }}} */
      68             : /* {{{ proto mixed msgfmt_format( MessageFormatter $nf, array $args )
      69             :  * Format a message.
      70             :  */
      71           0 : PHP_FUNCTION( msgfmt_format )
      72             : {
      73             :         zval *args;
      74           0 :         MSG_FORMAT_METHOD_INIT_VARS;
      75             : 
      76             : 
      77             :         /* Parse parameters. */
      78           0 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oa",
      79             :                 &object, MessageFormatter_ce_ptr,  &args ) == FAILURE )
      80             :         {
      81           0 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
      82             :                         "msgfmt_format: unable to parse input params", 0 TSRMLS_CC );
      83             : 
      84           0 :                 RETURN_FALSE;
      85             :         }
      86             : 
      87             :         /* Fetch the object. */
      88           0 :         MSG_FORMAT_METHOD_FETCH_OBJECT;
      89             : 
      90           0 :         msgfmt_do_format(mfo, args, return_value TSRMLS_CC);
      91             : }
      92             : /* }}} */
      93             : 
      94             : /* {{{ proto mixed MessageFormatter::formatMessage( string $locale, string $pattern, array $args )
      95             :  * Format a message. }}} */
      96             : /* {{{ proto mixed msgfmt_format_message( string $locale, string $pattern, array $args )
      97             :  * Format a message.
      98             :  */
      99           0 : PHP_FUNCTION( msgfmt_format_message )
     100             : {
     101             :         zval       *args;
     102           0 :         UChar      *spattern = NULL;
     103           0 :         int         spattern_len = 0;
     104           0 :         char       *pattern = NULL;
     105           0 :         int         pattern_len = 0;
     106           0 :         const char *slocale = NULL;
     107           0 :         int         slocale_len = 0;
     108           0 :         MessageFormatter_object mf = {0};
     109           0 :         MessageFormatter_object *mfo = &mf;
     110             : 
     111             :         /* Parse parameters. */
     112           0 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "ssa",
     113             :                   &slocale, &slocale_len, &pattern, &pattern_len, &args ) == FAILURE )
     114             :         {
     115           0 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     116             :                         "msgfmt_format_message: unable to parse input params", 0 TSRMLS_CC );
     117             : 
     118           0 :                 RETURN_FALSE;
     119             :         }
     120             : 
     121           0 :         msgformat_data_init(&mfo->mf_data TSRMLS_CC);
     122             : 
     123           0 :         if(pattern && pattern_len) {
     124           0 :                 intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo));
     125           0 :                 if( U_FAILURE(INTL_DATA_ERROR_CODE((mfo))) )
     126             :                 {
     127           0 :                         intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     128             :                                 "msgfmt_format_message: error converting pattern to UTF-16", 0 TSRMLS_CC );
     129           0 :                         RETURN_FALSE;
     130             :                 }
     131             :         } else {
     132           0 :                 spattern_len = 0;
     133           0 :                 spattern = NULL;
     134             :         }
     135             : 
     136           0 :         if(slocale_len == 0) {
     137           0 :                 slocale = intl_locale_get_default(TSRMLS_C);
     138             :         }
     139             : 
     140             : #ifdef MSG_FORMAT_QUOTE_APOS
     141           0 :         if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) {
     142           0 :                 intl_error_set( NULL, U_INVALID_FORMAT_ERROR,
     143             :                         "msgfmt_format_message: error converting pattern to quote-friendly format", 0 TSRMLS_CC );
     144           0 :                 RETURN_FALSE;
     145             :         }
     146             : #endif
     147             : 
     148             :         /* Create an ICU message formatter. */
     149           0 :         MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, slocale, NULL, &INTL_DATA_ERROR_CODE(mfo));
     150           0 :         if(spattern && spattern_len) {
     151           0 :                 efree(spattern);
     152             :         }
     153           0 :         INTL_METHOD_CHECK_STATUS(mfo, "Creating message formatter failed");
     154             : 
     155           0 :         msgfmt_do_format(mfo, args, return_value TSRMLS_CC);
     156             : 
     157             :         /* drop the temporary formatter */
     158           0 :         msgformat_data_free(&mfo->mf_data TSRMLS_CC);
     159             : }
     160             : /* }}} */
     161             : 
     162             : /*
     163             :  * Local variables:
     164             :  * tab-width: 4
     165             :  * c-basic-offset: 4
     166             :  * End:
     167             :  * vim600: noet sw=4 ts=4 fdm=marker
     168             :  * vim<600: noet sw=4 ts=4
     169             :  */

Generated by: LCOV version 1.10

Generated at Wed, 16 Apr 2014 12:47:49 +0000 (8 days ago)

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