@@ -81,19 +81,22 @@ PHP_FUNCTION(grapheme_strlen)
81
81
/* {{{ Find position of first occurrence of a string within another */
82
82
PHP_FUNCTION (grapheme_strpos )
83
83
{
84
- char * haystack , * needle ;
85
- size_t haystack_len , needle_len ;
84
+ char * haystack , * needle , * locale = "" ;
85
+ size_t haystack_len , needle_len , locale_len ;
86
86
const char * found ;
87
87
zend_long loffset = 0 ;
88
88
int32_t offset = 0 ;
89
+ zend_long strength = UCOL_DEFAULT_STRENGTH ;
89
90
size_t noffset = 0 ;
90
91
zend_long ret_pos ;
91
92
92
- ZEND_PARSE_PARAMETERS_START (2 , 3 )
93
+ ZEND_PARSE_PARAMETERS_START (2 , 5 )
93
94
Z_PARAM_STRING (haystack , haystack_len )
94
95
Z_PARAM_STRING (needle , needle_len )
95
96
Z_PARAM_OPTIONAL
96
97
Z_PARAM_LONG (loffset )
98
+ Z_PARAM_STRING (locale , locale_len )
99
+ Z_PARAM_LONG (strength )
97
100
ZEND_PARSE_PARAMETERS_END ();
98
101
99
102
if ( OUTSIDE_STRING (loffset , haystack_len ) ) {
@@ -121,7 +124,7 @@ PHP_FUNCTION(grapheme_strpos)
121
124
}
122
125
123
126
/* do utf16 part of the strpos */
124
- ret_pos = grapheme_strpos_utf16 (haystack , haystack_len , needle , needle_len , offset , NULL , 0 /* fIgnoreCase */ , 0 , "" /* last */ );
127
+ ret_pos = grapheme_strpos_utf16 (haystack , haystack_len , needle , needle_len , offset , NULL , 0 /* fIgnoreCase */ , 0 , locale , strength /* last */ );
125
128
126
129
if ( ret_pos >= 0 ) {
127
130
RETURN_LONG (ret_pos );
@@ -139,15 +142,17 @@ PHP_FUNCTION(grapheme_stripos)
139
142
const char * found ;
140
143
zend_long loffset = 0 ;
141
144
int32_t offset = 0 ;
145
+ zend_long strength = UCOL_DEFAULT_STRENGTH ;
142
146
zend_long ret_pos ;
143
147
int is_ascii ;
144
148
145
- ZEND_PARSE_PARAMETERS_START (2 , 4 )
149
+ ZEND_PARSE_PARAMETERS_START (2 , 5 )
146
150
Z_PARAM_STRING (haystack , haystack_len )
147
151
Z_PARAM_STRING (needle , needle_len )
148
152
Z_PARAM_OPTIONAL
149
153
Z_PARAM_LONG (loffset )
150
154
Z_PARAM_STRING (locale , locale_len )
155
+ Z_PARAM_LONG (strength )
151
156
ZEND_PARSE_PARAMETERS_END ();
152
157
153
158
if ( OUTSIDE_STRING (loffset , haystack_len ) ) {
@@ -186,7 +191,7 @@ PHP_FUNCTION(grapheme_stripos)
186
191
}
187
192
188
193
/* do utf16 part of the strpos */
189
- ret_pos = grapheme_strpos_utf16 (haystack , haystack_len , needle , needle_len , offset , NULL , 1 /* fIgnoreCase */ , 0 , locale /*last */ );
194
+ ret_pos = grapheme_strpos_utf16 (haystack , haystack_len , needle , needle_len , offset , NULL , 1 /* fIgnoreCase */ , 0 , locale , strength /*last */ );
190
195
191
196
if ( ret_pos >= 0 ) {
192
197
RETURN_LONG (ret_pos );
@@ -205,14 +210,16 @@ PHP_FUNCTION(grapheme_strrpos)
205
210
size_t haystack_len , needle_len ;
206
211
zend_long loffset = 0 ;
207
212
int32_t offset = 0 ;
213
+ zend_long strength = UCOL_DEFAULT_STRENGTH ;
208
214
zend_long ret_pos ;
209
215
int is_ascii ;
210
216
211
- ZEND_PARSE_PARAMETERS_START (2 , 3 )
217
+ ZEND_PARSE_PARAMETERS_START (2 , 4 )
212
218
Z_PARAM_STRING (haystack , haystack_len )
213
219
Z_PARAM_STRING (needle , needle_len )
214
220
Z_PARAM_OPTIONAL
215
221
Z_PARAM_LONG (loffset )
222
+ Z_PARAM_LONG (strength )
216
223
ZEND_PARSE_PARAMETERS_END ();
217
224
218
225
if ( OUTSIDE_STRING (loffset , haystack_len ) ) {
@@ -244,7 +251,7 @@ PHP_FUNCTION(grapheme_strrpos)
244
251
/* else we need to continue via utf16 */
245
252
}
246
253
247
- ret_pos = grapheme_strpos_utf16 (haystack , haystack_len , needle , needle_len , offset , NULL , 0 /* f_ignore_case */ , 1 , locale /* last */ );
254
+ ret_pos = grapheme_strpos_utf16 (haystack , haystack_len , needle , needle_len , offset , NULL , 0 /* f_ignore_case */ , 1 , locale , strength /* last */ );
248
255
249
256
if ( ret_pos >= 0 ) {
250
257
RETURN_LONG (ret_pos );
@@ -263,15 +270,17 @@ PHP_FUNCTION(grapheme_strripos)
263
270
size_t haystack_len , needle_len , locale_len = 0 ;
264
271
zend_long loffset = 0 ;
265
272
int32_t offset = 0 ;
273
+ zend_long strength = UCOL_DEFAULT_STRENGTH ;
266
274
zend_long ret_pos ;
267
275
int is_ascii ;
268
276
269
- ZEND_PARSE_PARAMETERS_START (2 , 4 )
277
+ ZEND_PARSE_PARAMETERS_START (2 , 5 )
270
278
Z_PARAM_STRING (haystack , haystack_len )
271
279
Z_PARAM_STRING (needle , needle_len )
272
280
Z_PARAM_OPTIONAL
273
281
Z_PARAM_LONG (loffset )
274
282
Z_PARAM_STRING (locale , locale_len )
283
+ Z_PARAM_LONG (strength )
275
284
ZEND_PARSE_PARAMETERS_END ();
276
285
277
286
if ( OUTSIDE_STRING (loffset , haystack_len ) ) {
@@ -312,7 +321,7 @@ PHP_FUNCTION(grapheme_strripos)
312
321
/* else we need to continue via utf16 */
313
322
}
314
323
315
- ret_pos = grapheme_strpos_utf16 (haystack , haystack_len , needle , needle_len , offset , NULL , 1 /* f_ignore_case */ , 1 , locale /*last */ );
324
+ ret_pos = grapheme_strpos_utf16 (haystack , haystack_len , needle , needle_len , offset , NULL , 1 /* f_ignore_case */ , 1 , locale , strength /*last */ );
316
325
317
326
if ( ret_pos >= 0 ) {
318
327
RETURN_LONG (ret_pos );
@@ -327,13 +336,14 @@ PHP_FUNCTION(grapheme_strripos)
327
336
/* {{{ Returns part of a string */
328
337
PHP_FUNCTION (grapheme_substr )
329
338
{
330
- char * str ;
339
+ char * str , * locale = "" ;
331
340
zend_string * u8_sub_str ;
332
341
UChar * ustr ;
333
- size_t str_len ;
342
+ size_t str_len , locale_len ;
334
343
int32_t ustr_len ;
335
344
zend_long lstart = 0 , length = 0 ;
336
345
int32_t start = 0 ;
346
+ zend_long strength = UCOL_DEFAULT ;
337
347
int iter_val ;
338
348
UErrorCode status ;
339
349
unsigned char u_break_iterator_buffer [U_BRK_SAFECLONE_BUFFERSIZE ];
@@ -342,11 +352,13 @@ PHP_FUNCTION(grapheme_substr)
342
352
int32_t (* iter_func )(UBreakIterator * );
343
353
bool no_length = true;
344
354
345
- ZEND_PARSE_PARAMETERS_START (2 , 3 )
355
+ ZEND_PARSE_PARAMETERS_START (2 , 5 )
346
356
Z_PARAM_STRING (str , str_len )
347
357
Z_PARAM_LONG (lstart )
348
358
Z_PARAM_OPTIONAL
349
359
Z_PARAM_LONG_OR_NULL (length , no_length )
360
+ Z_PARAM_STRING (locale , locale_len )
361
+ Z_PARAM_LONG (strength )
350
362
ZEND_PARSE_PARAMETERS_END ();
351
363
352
364
if (lstart < INT32_MIN || lstart > INT32_MAX ) {
@@ -544,24 +556,17 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas
544
556
const char * found ;
545
557
size_t haystack_len , needle_len , locale_len = 0 ;
546
558
int32_t ret_pos , uchar_pos ;
559
+ zend_long strength = UCOL_DEFAULT_STRENGTH ;
547
560
bool part = false;
548
561
549
- if (f_ignore_case == 1 ) {
550
- ZEND_PARSE_PARAMETERS_START (2 , 4 )
551
- Z_PARAM_STRING (haystack , haystack_len )
552
- Z_PARAM_STRING (needle , needle_len )
553
- Z_PARAM_OPTIONAL
554
- Z_PARAM_BOOL (part )
555
- Z_PARAM_STRING (locale , locale_len )
556
- ZEND_PARSE_PARAMETERS_END ();
557
- } else {
558
- ZEND_PARSE_PARAMETERS_START (2 , 3 )
559
- Z_PARAM_STRING (haystack , haystack_len )
560
- Z_PARAM_STRING (needle , needle_len )
561
- Z_PARAM_OPTIONAL
562
- Z_PARAM_BOOL (part )
563
- ZEND_PARSE_PARAMETERS_END ();
564
- }
562
+ ZEND_PARSE_PARAMETERS_START (2 , 5 )
563
+ Z_PARAM_STRING (haystack , haystack_len )
564
+ Z_PARAM_STRING (needle , needle_len )
565
+ Z_PARAM_OPTIONAL
566
+ Z_PARAM_BOOL (part )
567
+ Z_PARAM_STRING (locale , locale_len )
568
+ Z_PARAM_LONG (strength )
569
+ ZEND_PARSE_PARAMETERS_END ();
565
570
566
571
if ( !f_ignore_case ) {
567
572
@@ -587,7 +592,7 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas
587
592
}
588
593
589
594
/* need to work in utf16 */
590
- ret_pos = grapheme_strpos_utf16 (haystack , haystack_len , needle , needle_len , 0 , & uchar_pos , f_ignore_case , 0 , locale /*last */ );
595
+ ret_pos = grapheme_strpos_utf16 (haystack , haystack_len , needle , needle_len , 0 , & uchar_pos , f_ignore_case , 0 , locale , strength /*last */ );
591
596
592
597
if ( ret_pos < 0 ) {
593
598
RETURN_FALSE ;
@@ -932,14 +937,19 @@ PHP_FUNCTION(grapheme_levenshtein)
932
937
zend_long cost_ins = 1 ;
933
938
zend_long cost_rep = 1 ;
934
939
zend_long cost_del = 1 ;
940
+ char * locale = "" ;
941
+ size_t locale_len = 0 ;
942
+ zend_long strength = UCOL_DEFAULT_STRENGTH ;
935
943
936
- ZEND_PARSE_PARAMETERS_START (2 , 5 )
944
+ ZEND_PARSE_PARAMETERS_START (2 , 7 )
937
945
Z_PARAM_STR (string1 )
938
946
Z_PARAM_STR (string2 )
939
947
Z_PARAM_OPTIONAL
940
948
Z_PARAM_LONG (cost_ins )
941
949
Z_PARAM_LONG (cost_rep )
942
950
Z_PARAM_LONG (cost_del )
951
+ Z_PARAM_STRING (locale , locale_len )
952
+ Z_PARAM_LONG (strength )
943
953
ZEND_PARSE_PARAMETERS_END ();
944
954
945
955
if (cost_ins <= 0 || cost_ins > UINT_MAX / 4 ) {
@@ -1056,14 +1066,15 @@ PHP_FUNCTION(grapheme_levenshtein)
1056
1066
RETVAL_FALSE ;
1057
1067
goto out_bi2 ;
1058
1068
}
1059
- UCollator * collator = ucol_open ("" , & ustatus );
1069
+ UCollator * collator = ucol_open (locale , & ustatus );
1060
1070
if (U_FAILURE (ustatus )) {
1061
1071
intl_error_set_code (NULL , ustatus );
1062
1072
1063
1073
intl_error_set_custom_msg (NULL , "Error on ucol_open" , 0 );
1064
1074
RETVAL_FALSE ;
1065
1075
goto out_collator ;
1066
1076
}
1077
+ ucol_setStrength (collator , strength );
1067
1078
1068
1079
zend_long * p1 , * p2 , * tmp ;
1069
1080
p1 = safe_emalloc ((size_t ) strlen_2 + 1 , sizeof (zend_long ), 0 );
0 commit comments