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