8
8
9
9
#define IC_METHOD (mname ) PHP_METHOD(IntlChar, mname)
10
10
11
- static inline int convert_cp (UChar32 * pcp , zval * zcp ) {
12
- zend_long cp = -1 ;
13
-
14
- if (Z_TYPE_P (zcp ) == IS_LONG ) {
15
- cp = Z_LVAL_P (zcp );
16
- } else if (Z_TYPE_P (zcp ) == IS_STRING ) {
11
+ static inline int convert_cp (UChar32 * pcp , zend_string * string_codepoint , zend_long int_codepoint ) {
12
+ if (string_codepoint != NULL ) {
17
13
int32_t i = 0 ;
18
- size_t zcp_len = Z_STRLEN_P ( zcp );
14
+ size_t string_codepoint_length = ZSTR_LEN ( string_codepoint );
19
15
20
- if (ZEND_SIZE_T_INT_OVFL (zcp_len )) {
16
+ if (ZEND_SIZE_T_INT_OVFL (string_codepoint_length )) {
21
17
intl_error_set_code (NULL , U_ILLEGAL_ARGUMENT_ERROR );
22
18
intl_error_set_custom_msg (NULL , "Input string is too long." , 0 );
23
19
return FAILURE ;
24
20
}
25
21
26
- U8_NEXT (Z_STRVAL_P ( zcp ), i , zcp_len , cp );
27
- if ((size_t )i != zcp_len ) {
22
+ U8_NEXT (ZSTR_VAL ( string_codepoint ), i , string_codepoint_length , int_codepoint );
23
+ if ((size_t )i != string_codepoint_length ) {
28
24
intl_error_set_code (NULL , U_ILLEGAL_ARGUMENT_ERROR );
29
25
intl_error_set_custom_msg (NULL , "Passing a UTF-8 character for codepoint requires a string which is exactly one UTF-8 codepoint long." , 0 );
30
26
return FAILURE ;
31
27
}
32
- } else {
33
- intl_error_set_code (NULL , U_ILLEGAL_ARGUMENT_ERROR );
34
- intl_error_set_custom_msg (NULL , "Invalid parameter for unicode point. Must be either integer or UTF-8 sequence." , 0 );
35
- return FAILURE ;
36
28
}
37
- if ((cp < UCHAR_MIN_VALUE ) || (cp > UCHAR_MAX_VALUE )) {
29
+
30
+ if ((int_codepoint < UCHAR_MIN_VALUE ) || (int_codepoint > UCHAR_MAX_VALUE )) {
38
31
intl_error_set_code (NULL , U_ILLEGAL_ARGUMENT_ERROR );
39
32
intl_error_set_custom_msg (NULL , "Codepoint out of range" , 0 );
40
33
return FAILURE ;
41
34
}
42
- * pcp = (UChar32 )cp ;
35
+ * pcp = (UChar32 )int_codepoint ;
43
36
return SUCCESS ;
44
37
}
45
38
39
+ static zend_never_inline int parse_code_point_param (INTERNAL_FUNCTION_PARAMETERS , UChar32 * cp ) {
40
+ zend_string * string_codepoint ;
41
+ zend_long int_codepoint ;
42
+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
43
+ Z_PARAM_STR_OR_LONG (string_codepoint , int_codepoint )
44
+ ZEND_PARSE_PARAMETERS_END_EX (return FAILURE );
45
+ return convert_cp (cp , string_codepoint , int_codepoint );
46
+ }
47
+
46
48
/* {{{ proto string IntlChar::chr(int|string $codepoint)
47
49
* Converts a numeric codepoint to UTF-8
48
50
* Acts as an identify function when given a valid UTF-8 encoded codepoint
49
51
*/
50
52
IC_METHOD (chr ) {
51
53
UChar32 cp ;
52
- zval * zcp ;
53
54
char buffer [5 ];
54
55
int buffer_len = 0 ;
55
56
56
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z" , & zcp ) == FAILURE ) {
57
- RETURN_THROWS ();
58
- }
59
-
60
- if (convert_cp (& cp , zcp ) == FAILURE ) {
57
+ if (parse_code_point_param (INTERNAL_FUNCTION_PARAM_PASSTHRU , & cp ) == FAILURE ) {
61
58
RETURN_NULL ();
62
59
}
63
60
@@ -76,13 +73,8 @@ IC_METHOD(chr) {
76
73
*/
77
74
IC_METHOD (ord ) {
78
75
UChar32 cp ;
79
- zval * zcp ;
80
76
81
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z" , & zcp ) == FAILURE ) {
82
- RETURN_THROWS ();
83
- }
84
-
85
- if (convert_cp (& cp , zcp ) == FAILURE ) {
77
+ if (parse_code_point_param (INTERNAL_FUNCTION_PARAM_PASSTHRU , & cp ) == FAILURE ) {
86
78
RETURN_NULL ();
87
79
}
88
80
@@ -94,13 +86,15 @@ IC_METHOD(ord) {
94
86
IC_METHOD (hasBinaryProperty ) {
95
87
UChar32 cp ;
96
88
zend_long prop ;
97
- zval * zcp ;
89
+ zend_string * string_codepoint ;
90
+ zend_long int_codepoint ;
98
91
99
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "zl" , & zcp , & prop ) == FAILURE ) {
100
- RETURN_THROWS ();
101
- }
92
+ ZEND_PARSE_PARAMETERS_START (2 , 2 )
93
+ Z_PARAM_STR_OR_LONG (string_codepoint , int_codepoint )
94
+ Z_PARAM_LONG (prop )
95
+ ZEND_PARSE_PARAMETERS_END ();
102
96
103
- if (convert_cp (& cp , zcp ) == FAILURE ) {
97
+ if (convert_cp (& cp , string_codepoint , int_codepoint ) == FAILURE ) {
104
98
RETURN_NULL ();
105
99
}
106
100
@@ -112,13 +106,15 @@ IC_METHOD(hasBinaryProperty) {
112
106
IC_METHOD (getIntPropertyValue ) {
113
107
UChar32 cp ;
114
108
zend_long prop ;
115
- zval * zcp ;
109
+ zend_string * string_codepoint ;
110
+ zend_long int_codepoint ;
116
111
117
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "zl" , & zcp , & prop ) == FAILURE ) {
118
- RETURN_THROWS ();
119
- }
112
+ ZEND_PARSE_PARAMETERS_START (2 , 2 )
113
+ Z_PARAM_STR_OR_LONG (string_codepoint , int_codepoint )
114
+ Z_PARAM_LONG (prop )
115
+ ZEND_PARSE_PARAMETERS_END ();
120
116
121
- if (convert_cp (& cp , zcp ) == FAILURE ) {
117
+ if (convert_cp (& cp , string_codepoint , int_codepoint ) == FAILURE ) {
122
118
RETURN_NULL ();
123
119
}
124
120
@@ -153,13 +149,8 @@ IC_METHOD(getIntPropertyMaxValue) {
153
149
/* {{{ proto float IntlChar::getNumericValue(int|string $codepoint) */
154
150
IC_METHOD (getNumericValue ) {
155
151
UChar32 cp ;
156
- zval * zcp ;
157
-
158
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z" , & zcp ) == FAILURE ) {
159
- RETURN_THROWS ();
160
- }
161
152
162
- if (convert_cp ( & cp , zcp ) == FAILURE ) {
153
+ if (parse_code_point_param ( INTERNAL_FUNCTION_PARAM_PASSTHRU , & cp ) == FAILURE ) {
163
154
RETURN_NULL ();
164
155
}
165
156
@@ -173,8 +164,7 @@ typedef struct _enumCharType_data {
173
164
zend_fcall_info_cache fci_cache ;
174
165
} enumCharType_data ;
175
166
static UBool enumCharType_callback (enumCharType_data * context ,
176
- UChar32 start , UChar32 limit ,
177
- UCharCategory type ) {
167
+ UChar32 start , UChar32 limit , UCharCategory type ) {
178
168
zval retval ;
179
169
zval args [3 ];
180
170
@@ -212,13 +202,8 @@ IC_METHOD(enumCharTypes) {
212
202
/* {{{ proto int IntlChar::getBlockCode(int|string $codepoint) */
213
203
IC_METHOD (getBlockCode ) {
214
204
UChar32 cp ;
215
- zval * zcp ;
216
205
217
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z" , & zcp ) == FAILURE ) {
218
- RETURN_THROWS ();
219
- }
220
-
221
- if (convert_cp (& cp , zcp ) == FAILURE ) {
206
+ if (parse_code_point_param (INTERNAL_FUNCTION_PARAM_PASSTHRU , & cp ) == FAILURE ) {
222
207
RETURN_NULL ();
223
208
}
224
209
@@ -229,17 +214,20 @@ IC_METHOD(getBlockCode) {
229
214
/* {{{ proto string IntlChar::charName(int|string $codepoint, int $nameChoice = IntlChar::UNICODE_CHAR_NAME) */
230
215
IC_METHOD (charName ) {
231
216
UChar32 cp ;
232
- zval * zcp ;
217
+ zend_string * string_codepoint ;
218
+ zend_long int_codepoint ;
233
219
UErrorCode error = U_ZERO_ERROR ;
234
220
zend_long nameChoice = U_UNICODE_CHAR_NAME ;
235
221
zend_string * buffer = NULL ;
236
222
int32_t buffer_len ;
237
223
238
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z|l" , & zcp , & nameChoice ) == FAILURE ) {
239
- RETURN_THROWS ();
240
- }
224
+ ZEND_PARSE_PARAMETERS_START (1 , 2 )
225
+ Z_PARAM_STR_OR_LONG (string_codepoint , int_codepoint )
226
+ Z_PARAM_OPTIONAL
227
+ Z_PARAM_LONG (nameChoice )
228
+ ZEND_PARSE_PARAMETERS_END ();
241
229
242
- if (convert_cp (& cp , zcp ) == FAILURE ) {
230
+ if (convert_cp (& cp , string_codepoint , int_codepoint ) == FAILURE ) {
243
231
RETURN_NULL ();
244
232
}
245
233
@@ -279,8 +267,8 @@ typedef struct _enumCharNames_data {
279
267
zend_fcall_info_cache fci_cache ;
280
268
} enumCharNames_data ;
281
269
static UBool enumCharNames_callback (enumCharNames_data * context ,
282
- UChar32 code , UCharNameChoice nameChoice ,
283
- const char * name , int32_t length ) {
270
+ UChar32 code , UCharNameChoice nameChoice ,
271
+ const char * name , int32_t length ) {
284
272
zval retval ;
285
273
zval args [3 ];
286
274
@@ -306,16 +294,22 @@ static UBool enumCharNames_callback(enumCharNames_data *context,
306
294
}
307
295
IC_METHOD (enumCharNames ) {
308
296
UChar32 start , limit ;
309
- zval * zstart , * zlimit ;
297
+ zend_string * string_start , * string_limit ;
298
+ zend_long int_start , int_limit ;
310
299
enumCharNames_data context ;
311
300
zend_long nameChoice = U_UNICODE_CHAR_NAME ;
312
301
UErrorCode error = U_ZERO_ERROR ;
313
302
314
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "zzf|l" , & zstart , & zlimit , & context .fci , & context .fci_cache , & nameChoice ) == FAILURE ) {
315
- RETURN_THROWS ();
316
- }
317
303
318
- if (convert_cp (& start , zstart ) == FAILURE || convert_cp (& limit , zlimit ) == FAILURE ) {
304
+ ZEND_PARSE_PARAMETERS_START (3 , 4 )
305
+ Z_PARAM_STR_OR_LONG (string_start , int_start )
306
+ Z_PARAM_STR_OR_LONG (string_limit , int_limit )
307
+ Z_PARAM_FUNC (context .fci , context .fci_cache )
308
+ Z_PARAM_OPTIONAL
309
+ Z_PARAM_LONG (nameChoice )
310
+ ZEND_PARSE_PARAMETERS_END ();
311
+
312
+ if (convert_cp (& start , string_start , int_start ) == FAILURE || convert_cp (& limit , string_limit , int_limit ) == FAILURE ) {
319
313
RETURN_NULL ();
320
314
}
321
315
@@ -395,19 +389,21 @@ IC_METHOD(getPropertyValueEnum) {
395
389
/* {{{ proto int|string IntlChar::foldCase(int|string $codepoint, int $options = IntlChar::FOLD_CASE_DEFAULT) */
396
390
IC_METHOD (foldCase ) {
397
391
UChar32 cp , ret ;
398
- zval * zcp ;
399
392
zend_long options = U_FOLD_CASE_DEFAULT ;
393
+ zend_string * string_codepoint ;
394
+ zend_long int_codepoint ;
400
395
401
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z|l" , & zcp , & options ) == FAILURE ) {
402
- RETURN_THROWS ();
403
- }
396
+ ZEND_PARSE_PARAMETERS_START (2 , 2 )
397
+ Z_PARAM_STR_OR_LONG (string_codepoint , int_codepoint )
398
+ Z_PARAM_LONG (options )
399
+ ZEND_PARSE_PARAMETERS_END ();
404
400
405
- if (convert_cp (& cp , zcp ) == FAILURE ) {
401
+ if (convert_cp (& cp , string_codepoint , int_codepoint ) == FAILURE ) {
406
402
RETURN_NULL ();
407
403
}
408
404
409
405
ret = u_foldCase (cp , options );
410
- if (Z_TYPE_P ( zcp ) == IS_STRING ) {
406
+ if (string_codepoint != NULL ) {
411
407
char buffer [5 ];
412
408
int buffer_len = 0 ;
413
409
U8_APPEND_UNSAFE (buffer , buffer_len , ret );
@@ -422,15 +418,18 @@ IC_METHOD(foldCase) {
422
418
/* {{{ proto int IntlChar::digit(int|string $codepoint[, int $radix = 10]) */
423
419
IC_METHOD (digit ) {
424
420
UChar32 cp ;
425
- zval * zcp ;
426
421
zend_long radix = 10 ;
427
422
int ret ;
423
+ zend_string * string_codepoint ;
424
+ zend_long int_codepoint ;
428
425
429
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z|l" , & zcp , & radix ) == FAILURE ) {
430
- RETURN_THROWS ();
431
- }
426
+ ZEND_PARSE_PARAMETERS_START (1 , 2 )
427
+ Z_PARAM_STR_OR_LONG (string_codepoint , int_codepoint )
428
+ Z_PARAM_OPTIONAL
429
+ Z_PARAM_LONG (radix )
430
+ ZEND_PARSE_PARAMETERS_END ();
432
431
433
- if (convert_cp (& cp , zcp ) == FAILURE ) {
432
+ if (convert_cp (& cp , string_codepoint , int_codepoint ) == FAILURE ) {
434
433
RETURN_NULL ();
435
434
}
436
435
@@ -459,15 +458,10 @@ IC_METHOD(forDigit) {
459
458
/* {{{ proto array IntlChar::charAge(int|string $codepoint) */
460
459
IC_METHOD (charAge ) {
461
460
UChar32 cp ;
462
- zval * zcp ;
463
461
UVersionInfo version ;
464
462
int i ;
465
463
466
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z" , & zcp ) == FAILURE ) {
467
- RETURN_THROWS ();
468
- }
469
-
470
- if (convert_cp (& cp , zcp ) == FAILURE ) {
464
+ if (parse_code_point_param (INTERNAL_FUNCTION_PARAM_PASSTHRU , & cp ) == FAILURE ) {
471
465
RETURN_NULL ();
472
466
}
473
467
@@ -499,17 +493,12 @@ IC_METHOD(getUnicodeVersion) {
499
493
/* {{{ proto string IntlChar::getFC_NFKC_Closure(int|string $codepoint) */
500
494
IC_METHOD (getFC_NFKC_Closure ) {
501
495
UChar32 cp ;
502
- zval * zcp ;
503
496
UChar * closure ;
504
497
zend_string * u8str ;
505
498
int32_t closure_len ;
506
499
UErrorCode error = U_ZERO_ERROR ;
507
500
508
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z" , & zcp ) == FAILURE ) {
509
- RETURN_THROWS ();
510
- }
511
-
512
- if (convert_cp (& cp , zcp ) == FAILURE ) {
501
+ if (parse_code_point_param (INTERNAL_FUNCTION_PARAM_PASSTHRU , & cp ) == FAILURE ) {
513
502
RETURN_NULL ();
514
503
}
515
504
@@ -536,9 +525,10 @@ IC_METHOD(getFC_NFKC_Closure) {
536
525
/* {{{ proto bool IntlChar::<name>(int|string $codepoint) */
537
526
#define IC_BOOL_METHOD_CHAR (name ) \
538
527
IC_METHOD(name) { \
539
- UChar32 cp; zval *zcp; \
540
- if ((zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcp) == FAILURE) || \
541
- (convert_cp(&cp, zcp) == FAILURE)) { return; } \
528
+ UChar32 cp; \
529
+ if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) { \
530
+ RETURN_NULL(); \
531
+ } \
542
532
RETURN_BOOL(u_##name(cp)); \
543
533
}
544
534
IC_BOOL_METHOD_CHAR (isUAlphabetic )
@@ -575,9 +565,10 @@ IC_BOOL_METHOD_CHAR(isJavaIDPart)
575
565
/* {{{ proto int IntlChar::<name>(int|string $codepoint) */
576
566
#define IC_INT_METHOD_CHAR (name ) \
577
567
IC_METHOD (name ) { \
578
- UChar32 cp ; zval * zcp ; \
579
- if ((zend_parse_parameters (ZEND_NUM_ARGS (), "z" , & zcp ) == FAILURE ) || \
580
- (convert_cp (& cp , zcp ) == FAILURE )) { return ; } \
568
+ UChar32 cp ; \
569
+ if (parse_code_point_param (INTERNAL_FUNCTION_PARAM_PASSTHRU , & cp ) == FAILURE ) { \
570
+ RETURN_NULL (); \
571
+ } \
581
572
RETURN_LONG (u_ ##name (cp)); \
582
573
}
583
574
IC_INT_METHOD_CHAR (charDirection )
@@ -593,11 +584,17 @@ IC_INT_METHOD_CHAR(charDigitValue)
593
584
*/
594
585
#define IC_CHAR_METHOD_CHAR (name ) \
595
586
IC_METHOD(name) { \
596
- UChar32 cp, ret; zval *zcp; \
597
- if ((zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcp) == FAILURE) || \
598
- (convert_cp(&cp, zcp) == FAILURE)) { return; } \
587
+ UChar32 cp, ret; \
588
+ zend_string *string_codepoint; \
589
+ zend_long int_codepoint; \
590
+ ZEND_PARSE_PARAMETERS_START(1, 1) \
591
+ Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint) \
592
+ ZEND_PARSE_PARAMETERS_END(); \
593
+ if (convert_cp(&cp, string_codepoint, int_codepoint) == FAILURE) { \
594
+ RETURN_NULL(); \
595
+ } \
599
596
ret = u_##name(cp); \
600
- if (Z_TYPE_P(zcp) == IS_STRING ) { \
597
+ if (string_codepoint != NULL ) { \
601
598
char buffer[5]; \
602
599
int buffer_len = 0; \
603
600
U8_APPEND_UNSAFE(buffer, buffer_len, ret); \
0 commit comments