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/formatter - formatter_main.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 51 51 100.0 %
Date: 2015-02-21 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       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 "formatter_class.h"
      25             : #include "intl_convert.h"
      26             : 
      27             : /* {{{ */
      28         210 : static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
      29             : {
      30             :         const char* locale;
      31         210 :         char*       pattern = NULL;
      32         210 :         size_t      locale_len = 0, pattern_len = 0;
      33             :         zend_long   style;
      34         210 :         UChar*      spattern     = NULL;
      35         210 :         int32_t     spattern_len = 0;
      36         210 :         FORMATTER_METHOD_INIT_VARS;
      37             : 
      38             :         /* Parse parameters. */
      39         210 :         if( zend_parse_parameters( ZEND_NUM_ARGS(), "sl|s",
      40             :                 &locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE )
      41             :         {
      42           7 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
      43             :                         "numfmt_create: unable to parse input parameters", 0 );
      44           7 :                 Z_OBJ_P(return_value) = NULL;
      45           7 :                 return;
      46             :         }
      47             : 
      48         203 :         INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
      49         203 :         object = return_value;
      50         203 :         FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK;
      51             : 
      52             :         /* Convert pattern (if specified) to UTF-16. */
      53         203 :         if(pattern && pattern_len) {
      54          40 :                 intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(nfo));
      55          40 :                 INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16");
      56             :         }
      57             : 
      58         203 :         if(locale_len == 0) {
      59           3 :                 locale = intl_locale_get_default();
      60             :         }
      61             : 
      62             :         /* Create an ICU number formatter. */
      63         203 :         FORMATTER_OBJECT(nfo) = unum_open(style, spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(nfo));
      64             : 
      65         203 :         if(spattern) {
      66          40 :                 efree(spattern);
      67             :         }
      68             : 
      69         214 :         INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed");
      70             : }
      71             : /* }}} */
      72             : 
      73             : /* {{{ proto NumberFormatter NumberFormatter::create( string $locale, int style[, string $pattern ] )
      74             :  * Create number formatter. }}} */
      75             : /* {{{ proto NumberFormatter numfmt_create( string $locale, int style[, string $pattern ] )
      76             :  * Create number formatter.
      77             :  */
      78         105 : PHP_FUNCTION( numfmt_create )
      79             : {
      80         105 :         object_init_ex( return_value, NumberFormatter_ce_ptr );
      81         105 :         numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
      82         105 :         if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
      83           5 :                 RETURN_NULL();
      84             :         }
      85             : }
      86             : /* }}} */
      87             : 
      88             : /* {{{ proto void NumberFormatter::__construct( string $locale, int style[, string $pattern ] )
      89             :  * NumberFormatter object constructor.
      90             :  */
      91         105 : PHP_METHOD( NumberFormatter, __construct )
      92             : {
      93         105 :         zval orig_this = *getThis();
      94             : 
      95         105 :         return_value = getThis();
      96         105 :         numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
      97             : 
      98         105 :         if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
      99          10 :                 zend_object_store_ctor_failed(Z_OBJ(orig_this));
     100          10 :                 ZEND_CTOR_MAKE_NULL();
     101             :         }
     102         105 : }
     103             : /* }}} */
     104             : 
     105             : /* {{{ proto int NumberFormatter::getErrorCode()
     106             :  * Get formatter's last error code. }}} */
     107             : /* {{{ proto int numfmt_get_error_code( NumberFormatter $nf )
     108             :  * Get formatter's last error code.
     109             :  */
     110           3 : PHP_FUNCTION( numfmt_get_error_code )
     111             : {
     112           3 :         FORMATTER_METHOD_INIT_VARS
     113             : 
     114             :         /* Parse parameters. */
     115           3 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
     116             :                 &object, NumberFormatter_ce_ptr ) == FAILURE )
     117             :         {
     118           1 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     119             :                         "numfmt_get_error_code: unable to parse input params", 0 );
     120             : 
     121           1 :                 RETURN_FALSE;
     122             :         }
     123             : 
     124           2 :         nfo = Z_INTL_NUMBERFORMATTER_P(object);
     125             : 
     126             :         /* Return formatter's last error code. */
     127           2 :         RETURN_LONG( INTL_DATA_ERROR_CODE(nfo) );
     128             : }
     129             : /* }}} */
     130             : 
     131             : /* {{{ proto string NumberFormatter::getErrorMessage( )
     132             :  * Get text description for formatter's last error code. }}} */
     133             : /* {{{ proto string numfmt_get_error_message( NumberFormatter $nf )
     134             :  * Get text description for formatter's last error code.
     135             :  */
     136           3 : PHP_FUNCTION( numfmt_get_error_message )
     137             : {
     138           3 :         zend_string *message = NULL;
     139           3 :         FORMATTER_METHOD_INIT_VARS
     140             : 
     141             :         /* Parse parameters. */
     142           3 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
     143             :                 &object, NumberFormatter_ce_ptr ) == FAILURE )
     144             :         {
     145           1 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     146             :                         "numfmt_get_error_message: unable to parse input params", 0 );
     147             : 
     148           1 :                 RETURN_FALSE;
     149             :         }
     150             : 
     151           2 :         nfo = Z_INTL_NUMBERFORMATTER_P(object);
     152             : 
     153             :         /* Return last error message. */
     154           2 :         message = intl_error_get_message( INTL_DATA_ERROR_P(nfo) );
     155           2 :         RETURN_STR(message);
     156             : }
     157             : /* }}} */
     158             : 
     159             : /*
     160             :  * Local variables:
     161             :  * tab-width: 4
     162             :  * c-basic-offset: 4
     163             :  * End:
     164             :  * vim600: noet sw=4 ts=4 fdm=marker
     165             :  * vim<600: noet sw=4 ts=4
     166             :  */

Generated by: LCOV version 1.10

Generated at Sat, 21 Feb 2015 16:01:50 +0000 (7 days ago)

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