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_class.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 36 40 90.0 %
Date: 2014-10-22 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             : #include <unicode/unum.h>
      18             : 
      19             : #include "formatter_class.h"
      20             : #include "php_intl.h"
      21             : #include "formatter_data.h"
      22             : #include "formatter_format.h"
      23             : #include "formatter_parse.h"
      24             : #include "formatter_main.h"
      25             : #include "formatter_attr.h"
      26             : 
      27             : #include <zend_exceptions.h>
      28             : 
      29             : zend_class_entry *NumberFormatter_ce_ptr = NULL;
      30             : static zend_object_handlers NumberFormatter_handlers;
      31             : 
      32             : /*
      33             :  * Auxiliary functions needed by objects of 'NumberFormatter' class
      34             :  */
      35             : 
      36             : /* {{{ NumberFormatter_objects_dtor */
      37         223 : static void NumberFormatter_object_dtor(
      38             :         zend_object *object
      39             :         TSRMLS_DC )
      40             : {
      41         223 :         zend_objects_destroy_object( object TSRMLS_CC );
      42         223 : }
      43             : /* }}} */
      44             : 
      45             : /* {{{ NumberFormatter_objects_free */
      46         233 : void NumberFormatter_object_free( zend_object *object TSRMLS_DC )
      47             : {
      48         233 :         NumberFormatter_object* nfo = php_intl_number_format_fetch_object(object);
      49             : 
      50         233 :         zend_object_std_dtor( &nfo->zo TSRMLS_CC );
      51             : 
      52         233 :         formatter_data_free( &nfo->nf_data TSRMLS_CC );
      53         233 : }
      54             : /* }}} */
      55             : 
      56             : /* {{{ NumberFormatter_object_create */
      57         233 : zend_object *NumberFormatter_object_create(zend_class_entry *ce TSRMLS_DC)
      58             : {
      59             :         NumberFormatter_object*     intern;
      60             : 
      61         233 :         intern = ecalloc( 1, sizeof(NumberFormatter_object) + sizeof(zval) * (ce->default_properties_count - 1) );
      62         233 :         formatter_data_init( &intern->nf_data TSRMLS_CC );
      63         233 :         zend_object_std_init( &intern->zo, ce TSRMLS_CC );
      64         233 :         object_properties_init(&intern->zo, ce);
      65             : 
      66         233 :         intern->zo.handlers = &NumberFormatter_handlers;
      67             : 
      68         233 :         return &intern->zo;
      69             : }
      70             : /* }}} */
      71             : 
      72             : /* {{{ NumberFormatter_object_clone */
      73           3 : zend_object *NumberFormatter_object_clone(zval *object TSRMLS_DC)
      74             : {
      75             :         NumberFormatter_object *nfo, *new_nfo;
      76             :         zend_object *new_obj;
      77             : 
      78           3 :         FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK;
      79           3 :         new_obj = NumberFormatter_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC);
      80           3 :         new_nfo = php_intl_number_format_fetch_object(new_obj);
      81             :         /* clone standard parts */      
      82           3 :         zend_objects_clone_members(&new_nfo->zo, &nfo->zo TSRMLS_CC);
      83             :         /* clone formatter object. It may fail, the destruction code must handle this case */
      84           3 :         if (FORMATTER_OBJECT(nfo) != NULL) {
      85           2 :                 FORMATTER_OBJECT(new_nfo) = unum_clone(FORMATTER_OBJECT(nfo),
      86           2 :                                 &INTL_DATA_ERROR_CODE(nfo));
      87           2 :                 if (U_FAILURE(INTL_DATA_ERROR_CODE(nfo))) {
      88             :                         /* set up error in case error handler is interested */
      89           0 :                         intl_errors_set(INTL_DATA_ERROR_P(nfo), INTL_DATA_ERROR_CODE(nfo),
      90             :                                         "Failed to clone NumberFormatter object", 0 TSRMLS_CC);
      91           0 :                         zend_throw_exception(NULL, "Failed to clone NumberFormatter object", 0 TSRMLS_CC);
      92             :                 }
      93             :         } else {
      94           1 :                 zend_throw_exception(NULL, "Cannot clone unconstructed NumberFormatter", 0 TSRMLS_CC);
      95             :         }
      96           3 :         return new_obj;
      97             : }
      98             : /* }}} */
      99             : 
     100             : /*
     101             :  * 'NumberFormatter' class registration structures & functions
     102             :  */
     103             : 
     104             : /* {{{ arginfo */
     105             : ZEND_BEGIN_ARG_INFO_EX(number_parse_arginfo, 0, 0, 1)
     106             :         ZEND_ARG_INFO(0, string)
     107             :         ZEND_ARG_INFO(0, type)
     108             :         ZEND_ARG_INFO(1, position)
     109             : ZEND_END_ARG_INFO()
     110             : 
     111             : ZEND_BEGIN_ARG_INFO_EX(number_parse_currency_arginfo, 0, 0, 2)
     112             :         ZEND_ARG_INFO(0, string)
     113             :         ZEND_ARG_INFO(1, currency)
     114             :         ZEND_ARG_INFO(1, position)
     115             : ZEND_END_ARG_INFO()
     116             : 
     117             : ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_getattribute, 0, 0, 1)
     118             :         ZEND_ARG_INFO(0, attr)
     119             : ZEND_END_ARG_INFO()
     120             : 
     121             : ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_setattribute, 0, 0, 2)
     122             :         ZEND_ARG_INFO(0, attr)
     123             :         ZEND_ARG_INFO(0, value)
     124             : ZEND_END_ARG_INFO()
     125             : 
     126             : ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_setsymbol, 0, 0, 2)
     127             :         ZEND_ARG_INFO(0, attr)
     128             :         ZEND_ARG_INFO(0, symbol)
     129             : ZEND_END_ARG_INFO()
     130             : 
     131             : ZEND_BEGIN_ARG_INFO(arginfo_numberformatter_getpattern, 0)
     132             : ZEND_END_ARG_INFO()
     133             : 
     134             : ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_setpattern, 0, 0, 1)
     135             :         ZEND_ARG_INFO(0, pattern)
     136             : ZEND_END_ARG_INFO()
     137             : 
     138             : ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_getlocale, 0, 0, 0)
     139             :         ZEND_ARG_INFO(0, type)
     140             : ZEND_END_ARG_INFO()
     141             : 
     142             : ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter___construct, 0, 0, 2)
     143             :         ZEND_ARG_INFO(0, locale)
     144             :         ZEND_ARG_INFO(0, style)
     145             :         ZEND_ARG_INFO(0, pattern)
     146             : ZEND_END_ARG_INFO()
     147             : 
     148             : ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_formatcurrency, 0, 0, 2)
     149             :         ZEND_ARG_INFO(0, num)
     150             :         ZEND_ARG_INFO(0, currency)
     151             : ZEND_END_ARG_INFO()
     152             : 
     153             : ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_format, 0, 0, 1)
     154             :         ZEND_ARG_INFO(0, num)
     155             :         ZEND_ARG_INFO(0, type)
     156             : ZEND_END_ARG_INFO()
     157             : /* }}} */
     158             : 
     159             : /* {{{ NumberFormatter_class_functions
     160             :  * Every 'NumberFormatter' class method has an entry in this table
     161             :  */
     162             : static zend_function_entry NumberFormatter_class_functions[] = {
     163             :         PHP_ME( NumberFormatter, __construct, arginfo_numberformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
     164             :         ZEND_FENTRY( create, ZEND_FN( numfmt_create ), arginfo_numberformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
     165             :         PHP_NAMED_FE( format, ZEND_FN( numfmt_format ), arginfo_numberformatter_format )
     166             :         PHP_NAMED_FE( parse, ZEND_FN( numfmt_parse ), number_parse_arginfo )
     167             :         PHP_NAMED_FE( formatCurrency, ZEND_FN( numfmt_format_currency ), arginfo_numberformatter_formatcurrency )
     168             :         PHP_NAMED_FE( parseCurrency, ZEND_FN( numfmt_parse_currency ), number_parse_currency_arginfo )
     169             :         PHP_NAMED_FE( setAttribute, ZEND_FN( numfmt_set_attribute ), arginfo_numberformatter_setattribute )
     170             :         PHP_NAMED_FE( getAttribute, ZEND_FN( numfmt_get_attribute ), arginfo_numberformatter_getattribute )
     171             :         PHP_NAMED_FE( setTextAttribute, ZEND_FN( numfmt_set_text_attribute ), arginfo_numberformatter_setattribute )
     172             :         PHP_NAMED_FE( getTextAttribute, ZEND_FN( numfmt_get_text_attribute ), arginfo_numberformatter_getattribute )
     173             :         PHP_NAMED_FE( setSymbol, ZEND_FN( numfmt_set_symbol ), arginfo_numberformatter_setsymbol )
     174             :         PHP_NAMED_FE( getSymbol, ZEND_FN( numfmt_get_symbol ), arginfo_numberformatter_getattribute )
     175             :         PHP_NAMED_FE( setPattern, ZEND_FN( numfmt_set_pattern ), arginfo_numberformatter_setpattern )
     176             :         PHP_NAMED_FE( getPattern, ZEND_FN( numfmt_get_pattern ), arginfo_numberformatter_getpattern )
     177             :         PHP_NAMED_FE( getLocale, ZEND_FN( numfmt_get_locale ), arginfo_numberformatter_getlocale )
     178             :         PHP_NAMED_FE( getErrorCode, ZEND_FN( numfmt_get_error_code ), arginfo_numberformatter_getpattern )
     179             :         PHP_NAMED_FE( getErrorMessage, ZEND_FN( numfmt_get_error_message ), arginfo_numberformatter_getpattern )
     180             :         PHP_FE_END
     181             : };
     182             : /* }}} */
     183             : 
     184             : /* {{{ formatter_register_class
     185             :  * Initialize 'NumberFormatter' class
     186             :  */
     187       20423 : void formatter_register_class( TSRMLS_D )
     188             : {
     189             :         zend_class_entry ce;
     190             : 
     191             :         /* Create and register 'NumberFormatter' class. */
     192       20423 :         INIT_CLASS_ENTRY( ce, "NumberFormatter", NumberFormatter_class_functions );
     193       20423 :         ce.create_object = NumberFormatter_object_create;
     194       20423 :         NumberFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
     195             : 
     196       20423 :         memcpy(&NumberFormatter_handlers, zend_get_std_object_handlers(),
     197             :                 sizeof(NumberFormatter_handlers));
     198       20423 :         NumberFormatter_handlers.offset = XtOffsetOf(NumberFormatter_object, zo);
     199       20423 :         NumberFormatter_handlers.clone_obj = NumberFormatter_object_clone;
     200       20423 :         NumberFormatter_handlers.dtor_obj = NumberFormatter_object_dtor;
     201       20423 :         NumberFormatter_handlers.free_obj = NumberFormatter_object_free;
     202             : 
     203             :         /* Declare 'NumberFormatter' class properties. */
     204       20423 :         if( !NumberFormatter_ce_ptr )
     205             :         {
     206           0 :                 zend_error(E_ERROR, "Failed to register NumberFormatter class");
     207           0 :                 return;
     208             :         }
     209             : }
     210             : /* }}} */
     211             : 
     212             : /*
     213             :  * Local variables:
     214             :  * tab-width: 4
     215             :  * c-basic-offset: 4
     216             :  * End:
     217             :  * vim600: noet sw=4 ts=4 fdm=marker
     218             :  * vim<600: noet sw=4 ts=4
     219             :  */

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:50 +0000 (2 days ago)

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