@@ -81,18 +81,20 @@ PHP_MINFO_FUNCTION(php_gettext)
81
81
/* {{{ Set the textdomain to "domain". Returns the current domain */
82
82
PHP_FUNCTION (textdomain )
83
83
{
84
- char * domain_name = NULL , * retval ;
84
+ char * domain_name = NULL , * retval = NULL ;
85
85
zend_string * domain = NULL ;
86
86
87
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "S!" , & domain ) == FAILURE ) {
88
- RETURN_THROWS ();
89
- }
87
+ ZEND_PARSE_PARAMETERS_START (0 , 1 )
88
+ Z_PARAM_OPTIONAL
89
+ Z_PARAM_STR_OR_NULL (domain )
90
+ ZEND_PARSE_PARAMETERS_END ();
90
91
91
92
if (domain != NULL ) {
92
93
PHP_GETTEXT_DOMAIN_LENGTH_CHECK (1 , ZSTR_LEN (domain ))
93
- }
94
-
95
- if (domain != NULL && !zend_string_equals_literal (domain , "0" )) {
94
+ if (zend_string_equals_literal (domain , "0" )) {
95
+ zend_argument_value_error (1 , "cannot be zero" );
96
+ RETURN_THROWS ();
97
+ }
96
98
domain_name = ZSTR_VAL (domain );
97
99
}
98
100
@@ -105,7 +107,7 @@ PHP_FUNCTION(textdomain)
105
107
/* {{{ Return the translation of msgid for the current domain, or msgid unaltered if a translation does not exist */
106
108
PHP_FUNCTION (gettext )
107
109
{
108
- char * msgstr ;
110
+ char * msgstr = NULL ;
109
111
zend_string * msgid ;
110
112
111
113
ZEND_PARSE_PARAMETERS_START (1 , 1 )
@@ -126,12 +128,13 @@ PHP_FUNCTION(gettext)
126
128
/* {{{ Return the translation of msgid for domain_name, or msgid unaltered if a translation does not exist */
127
129
PHP_FUNCTION (dgettext )
128
130
{
129
- char * msgstr ;
131
+ char * msgstr = NULL ;
130
132
zend_string * domain , * msgid ;
131
133
132
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "SS" , & domain , & msgid ) == FAILURE ) {
133
- RETURN_THROWS ();
134
- }
134
+ ZEND_PARSE_PARAMETERS_START (2 , 2 )
135
+ Z_PARAM_STR (domain )
136
+ Z_PARAM_STR (msgid )
137
+ ZEND_PARSE_PARAMETERS_END ();
135
138
136
139
PHP_GETTEXT_DOMAIN_LENGTH_CHECK (1 , ZSTR_LEN (domain ))
137
140
PHP_GETTEXT_LENGTH_CHECK (2 , ZSTR_LEN (msgid ))
@@ -149,13 +152,15 @@ PHP_FUNCTION(dgettext)
149
152
/* {{{ Return the translation of msgid for domain_name and category, or msgid unaltered if a translation does not exist */
150
153
PHP_FUNCTION (dcgettext )
151
154
{
152
- char * msgstr ;
155
+ char * msgstr = NULL ;
153
156
zend_string * domain , * msgid ;
154
157
zend_long category ;
155
158
156
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "SSl" , & domain , & msgid , & category ) == FAILURE ) {
157
- RETURN_THROWS ();
158
- }
159
+ ZEND_PARSE_PARAMETERS_START (3 , 3 )
160
+ Z_PARAM_STR (domain )
161
+ Z_PARAM_STR (msgid )
162
+ Z_PARAM_LONG (category )
163
+ ZEND_PARSE_PARAMETERS_END ();
159
164
160
165
PHP_GETTEXT_DOMAIN_LENGTH_CHECK (1 , ZSTR_LEN (domain ))
161
166
PHP_GETTEXT_LENGTH_CHECK (2 , ZSTR_LEN (msgid ))
@@ -174,19 +179,24 @@ PHP_FUNCTION(dcgettext)
174
179
/* {{{ Bind to the text domain domain_name, looking for translations in dir. Returns the current domain */
175
180
PHP_FUNCTION (bindtextdomain )
176
181
{
177
- char * domain ;
178
- size_t domain_len ;
179
- zend_string * dir = NULL ;
182
+ zend_string * domain , * dir = NULL ;
180
183
char * retval , dir_name [MAXPATHLEN ];
181
184
182
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "sS!" , & domain , & domain_len , & dir ) == FAILURE ) {
185
+ ZEND_PARSE_PARAMETERS_START (1 , 2 )
186
+ Z_PARAM_STR (domain )
187
+ Z_PARAM_OPTIONAL
188
+ Z_PARAM_STR_OR_NULL (dir )
189
+ ZEND_PARSE_PARAMETERS_END ();
190
+
191
+ PHP_GETTEXT_DOMAIN_LENGTH_CHECK (1 , ZSTR_LEN (domain ))
192
+
193
+ if (!ZSTR_LEN (domain )) {
194
+ zend_argument_value_error (1 , "cannot be empty" );
183
195
RETURN_THROWS ();
184
196
}
185
197
186
- PHP_GETTEXT_DOMAIN_LENGTH_CHECK (1 , domain_len )
187
-
188
198
if (dir == NULL ) {
189
- RETURN_STRING (bindtextdomain (domain , NULL ));
199
+ RETURN_STRING (bindtextdomain (ZSTR_VAL ( domain ) , NULL ));
190
200
}
191
201
192
202
if (ZSTR_LEN (dir ) != 0 && !zend_string_equals_literal (dir , "0" )) {
@@ -197,7 +207,7 @@ PHP_FUNCTION(bindtextdomain)
197
207
RETURN_FALSE ;
198
208
}
199
209
200
- retval = bindtextdomain (domain , dir_name );
210
+ retval = bindtextdomain (ZSTR_VAL ( domain ) , dir_name );
201
211
202
212
RETURN_STRING (retval );
203
213
}
@@ -207,18 +217,20 @@ PHP_FUNCTION(bindtextdomain)
207
217
/* {{{ Plural version of gettext() */
208
218
PHP_FUNCTION (ngettext )
209
219
{
210
- char * msgid1 , * msgid2 , * msgstr ;
211
- size_t msgid1_len , msgid2_len ;
220
+ char * msgstr = NULL ;
221
+ zend_string * msgid1 , * msgid2 ;
212
222
zend_long count ;
213
223
214
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "ssl" , & msgid1 , & msgid1_len , & msgid2 , & msgid2_len , & count ) == FAILURE ) {
215
- RETURN_THROWS ();
216
- }
224
+ ZEND_PARSE_PARAMETERS_START (3 , 3 )
225
+ Z_PARAM_STR (msgid1 )
226
+ Z_PARAM_STR (msgid2 )
227
+ Z_PARAM_LONG (count )
228
+ ZEND_PARSE_PARAMETERS_END ();
217
229
218
- PHP_GETTEXT_LENGTH_CHECK (1 , msgid1_len )
219
- PHP_GETTEXT_LENGTH_CHECK (2 , msgid2_len )
230
+ PHP_GETTEXT_LENGTH_CHECK (1 , ZSTR_LEN ( msgid1 ) )
231
+ PHP_GETTEXT_LENGTH_CHECK (2 , ZSTR_LEN ( msgid2 ) )
220
232
221
- msgstr = ngettext (msgid1 , msgid2 , count );
233
+ msgstr = ngettext (ZSTR_VAL ( msgid1 ), ZSTR_VAL ( msgid2 ) , count );
222
234
223
235
ZEND_ASSERT (msgstr );
224
236
RETURN_STRING (msgstr );
@@ -230,20 +242,22 @@ PHP_FUNCTION(ngettext)
230
242
/* {{{ Plural version of dgettext() */
231
243
PHP_FUNCTION (dngettext )
232
244
{
233
- char * domain , * msgid1 , * msgid2 , * msgstr = NULL ;
234
- size_t domain_len , msgid1_len , msgid2_len ;
245
+ char * msgstr = NULL ;
246
+ zend_string * domain , * msgid1 , * msgid2 ;
235
247
zend_long count ;
236
248
237
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "sssl" , & domain , & domain_len ,
238
- & msgid1 , & msgid1_len , & msgid2 , & msgid2_len , & count ) == FAILURE ) {
239
- RETURN_THROWS ();
240
- }
249
+ ZEND_PARSE_PARAMETERS_START (4 , 4 )
250
+ Z_PARAM_STR (domain )
251
+ Z_PARAM_STR (msgid1 )
252
+ Z_PARAM_STR (msgid2 )
253
+ Z_PARAM_LONG (count )
254
+ ZEND_PARSE_PARAMETERS_END ();
241
255
242
- PHP_GETTEXT_DOMAIN_LENGTH_CHECK (1 , domain_len )
243
- PHP_GETTEXT_LENGTH_CHECK (2 , msgid1_len )
244
- PHP_GETTEXT_LENGTH_CHECK (3 , msgid2_len )
256
+ PHP_GETTEXT_DOMAIN_LENGTH_CHECK (1 , ZSTR_LEN ( domain ) )
257
+ PHP_GETTEXT_LENGTH_CHECK (2 , ZSTR_LEN ( msgid1 ) )
258
+ PHP_GETTEXT_LENGTH_CHECK (3 , ZSTR_LEN ( msgid2 ) )
245
259
246
- msgstr = dngettext (domain , msgid1 , msgid2 , count );
260
+ msgstr = dngettext (ZSTR_VAL ( domain ), ZSTR_VAL ( msgid1 ), ZSTR_VAL ( msgid2 ) , count );
247
261
248
262
ZEND_ASSERT (msgstr );
249
263
RETURN_STRING (msgstr );
@@ -255,23 +269,26 @@ PHP_FUNCTION(dngettext)
255
269
/* {{{ Plural version of dcgettext() */
256
270
PHP_FUNCTION (dcngettext )
257
271
{
258
- char * domain , * msgid1 , * msgid2 , * msgstr = NULL ;
259
- size_t domain_len , msgid1_len , msgid2_len ;
272
+ char * msgstr = NULL ;
273
+ zend_string * domain , * msgid1 , * msgid2 ;
260
274
zend_long count , category ;
261
275
262
276
RETVAL_FALSE ;
263
277
264
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "sssll" , & domain , & domain_len ,
265
- & msgid1 , & msgid1_len , & msgid2 , & msgid2_len , & count , & category ) == FAILURE ) {
266
- RETURN_THROWS ();
267
- }
278
+ ZEND_PARSE_PARAMETERS_START (5 , 5 )
279
+ Z_PARAM_STR (domain )
280
+ Z_PARAM_STR (msgid1 )
281
+ Z_PARAM_STR (msgid2 )
282
+ Z_PARAM_LONG (count )
283
+ Z_PARAM_LONG (category )
284
+ ZEND_PARSE_PARAMETERS_END ();
268
285
269
- PHP_GETTEXT_DOMAIN_LENGTH_CHECK (1 , domain_len )
270
- PHP_GETTEXT_LENGTH_CHECK (2 , msgid1_len )
271
- PHP_GETTEXT_LENGTH_CHECK (3 , msgid2_len )
286
+ PHP_GETTEXT_DOMAIN_LENGTH_CHECK (1 , ZSTR_LEN ( domain ) )
287
+ PHP_GETTEXT_LENGTH_CHECK (2 , ZSTR_LEN ( msgid1 ) )
288
+ PHP_GETTEXT_LENGTH_CHECK (3 , ZSTR_LEN ( msgid2 ) )
272
289
PHP_DCGETTEXT_CATEGORY_CHECK (5 , category )
273
290
274
- msgstr = dcngettext (domain , msgid1 , msgid2 , count , category );
291
+ msgstr = dcngettext (ZSTR_VAL ( domain ), ZSTR_VAL ( msgid1 ), ZSTR_VAL ( msgid2 ) , count , category );
275
292
276
293
ZEND_ASSERT (msgstr );
277
294
RETURN_STRING (msgstr );
@@ -284,16 +301,23 @@ PHP_FUNCTION(dcngettext)
284
301
/* {{{ Specify the character encoding in which the messages from the DOMAIN message catalog will be returned. */
285
302
PHP_FUNCTION (bind_textdomain_codeset )
286
303
{
287
- char * domain , * codeset = NULL , * retval = NULL ;
288
- size_t domain_len , codeset_len ;
304
+ char * retval = NULL ;
305
+ zend_string * domain , * codeset = NULL ;
306
+
307
+ ZEND_PARSE_PARAMETERS_START (1 , 2 )
308
+ Z_PARAM_STR (domain )
309
+ Z_PARAM_OPTIONAL
310
+ Z_PARAM_STR_OR_NULL (codeset )
311
+ ZEND_PARSE_PARAMETERS_END ();
312
+
313
+ PHP_GETTEXT_DOMAIN_LENGTH_CHECK (1 , ZSTR_LEN (domain ))
289
314
290
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "ss!" , & domain , & domain_len , & codeset , & codeset_len ) == FAILURE ) {
315
+ if (!ZSTR_LEN (domain )) {
316
+ zend_argument_value_error (1 , "cannot be empty" );
291
317
RETURN_THROWS ();
292
318
}
293
319
294
- PHP_GETTEXT_DOMAIN_LENGTH_CHECK (1 , domain_len )
295
-
296
- retval = bind_textdomain_codeset (domain , codeset );
320
+ retval = bind_textdomain_codeset (ZSTR_VAL (domain ), codeset ? ZSTR_VAL (codeset ) : NULL );
297
321
298
322
if (!retval ) {
299
323
RETURN_FALSE ;
0 commit comments