This source file includes following definitions.
- numfmt_ctor
- PHP_FUNCTION
- PHP_METHOD
- PHP_FUNCTION
- PHP_FUNCTION
1
2
3
4
5
6
7
8
9
10
11
12
13
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 static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
29 {
30 const char* locale;
31 char* pattern = NULL;
32 int locale_len = 0, pattern_len = 0;
33 long style;
34 UChar* spattern = NULL;
35 int spattern_len = 0;
36 FORMATTER_METHOD_INIT_VARS;
37
38
39 if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "sl|s",
40 &locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE )
41 {
42 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
43 "numfmt_create: unable to parse input parameters", 0 TSRMLS_CC );
44 zval_dtor(return_value);
45 RETURN_NULL();
46 }
47
48 INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
49 object = return_value;
50 FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK;
51
52
53 if(pattern && pattern_len) {
54 intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(nfo));
55 INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16");
56 }
57
58 if(locale_len == 0) {
59 locale = intl_locale_get_default(TSRMLS_C);
60 }
61
62
63 FORMATTER_OBJECT(nfo) = unum_open(style, spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(nfo));
64
65 if(spattern) {
66 efree(spattern);
67 }
68
69 INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed");
70 }
71
72
73
74
75
76
77
78 PHP_FUNCTION( numfmt_create )
79 {
80 object_init_ex( return_value, NumberFormatter_ce_ptr );
81 numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
82 }
83
84
85
86
87
88 PHP_METHOD( NumberFormatter, __construct )
89 {
90 return_value = getThis();
91 numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
92 }
93
94
95
96
97
98
99
100 PHP_FUNCTION( numfmt_get_error_code )
101 {
102 FORMATTER_METHOD_INIT_VARS
103
104
105 if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
106 &object, NumberFormatter_ce_ptr ) == FAILURE )
107 {
108 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
109 "numfmt_get_error_code: unable to parse input params", 0 TSRMLS_CC );
110
111 RETURN_FALSE;
112 }
113
114 nfo = (NumberFormatter_object *) zend_object_store_get_object( object TSRMLS_CC );
115
116
117 RETURN_LONG( INTL_DATA_ERROR_CODE(nfo) );
118 }
119
120
121
122
123
124
125
126 PHP_FUNCTION( numfmt_get_error_message )
127 {
128 char* message = NULL;
129 FORMATTER_METHOD_INIT_VARS
130
131
132 if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
133 &object, NumberFormatter_ce_ptr ) == FAILURE )
134 {
135 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
136 "numfmt_get_error_message: unable to parse input params", 0 TSRMLS_CC );
137
138 RETURN_FALSE;
139 }
140
141 nfo = (NumberFormatter_object *) zend_object_store_get_object( object TSRMLS_CC );
142
143
144 message = intl_error_get_message( INTL_DATA_ERROR_P(nfo) TSRMLS_CC );
145 RETURN_STRING( message, 0);
146 }
147
148
149
150
151
152
153
154
155
156