Annotation of embedaddon/php/ext/intl/formatter/formatter_class.c, revision 1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>