Skip to content

Commit 17e395e

Browse files
committed
Remove strength because locale can strength.
see the grapheme_levenshtein.phpt file.
1 parent 9e79a6c commit 17e395e

File tree

6 files changed

+37
-84
lines changed

6 files changed

+37
-84
lines changed

ext/intl/grapheme/grapheme_string.c

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,15 @@ PHP_FUNCTION(grapheme_strpos)
8686
const char *found;
8787
zend_long loffset = 0;
8888
int32_t offset = 0;
89-
zend_long strength = UCOL_DEFAULT_STRENGTH;
9089
size_t noffset = 0;
9190
zend_long ret_pos;
9291

93-
ZEND_PARSE_PARAMETERS_START(2, 5)
92+
ZEND_PARSE_PARAMETERS_START(2, 4)
9493
Z_PARAM_STRING(haystack, haystack_len)
9594
Z_PARAM_STRING(needle, needle_len)
9695
Z_PARAM_OPTIONAL
9796
Z_PARAM_LONG(loffset)
9897
Z_PARAM_STRING(locale, locale_len)
99-
Z_PARAM_LONG(strength)
10098
ZEND_PARSE_PARAMETERS_END();
10199

102100
if ( OUTSIDE_STRING(loffset, haystack_len) ) {
@@ -124,7 +122,7 @@ PHP_FUNCTION(grapheme_strpos)
124122
}
125123

126124
/* do utf16 part of the strpos */
127-
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* fIgnoreCase */, 0, locale, strength /* last */ );
125+
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* fIgnoreCase */, 0, locale /* last */ );
128126

129127
if ( ret_pos >= 0 ) {
130128
RETURN_LONG(ret_pos);
@@ -142,17 +140,15 @@ PHP_FUNCTION(grapheme_stripos)
142140
const char *found;
143141
zend_long loffset = 0;
144142
int32_t offset = 0;
145-
zend_long strength = UCOL_SECONDARY;
146143
zend_long ret_pos;
147144
int is_ascii;
148145

149-
ZEND_PARSE_PARAMETERS_START(2, 5)
146+
ZEND_PARSE_PARAMETERS_START(2, 4)
150147
Z_PARAM_STRING(haystack, haystack_len)
151148
Z_PARAM_STRING(needle, needle_len)
152149
Z_PARAM_OPTIONAL
153150
Z_PARAM_LONG(loffset)
154151
Z_PARAM_STRING(locale, locale_len)
155-
Z_PARAM_LONG(strength)
156152
ZEND_PARSE_PARAMETERS_END();
157153

158154
if ( OUTSIDE_STRING(loffset, haystack_len) ) {
@@ -191,7 +187,7 @@ PHP_FUNCTION(grapheme_stripos)
191187
}
192188

193189
/* do utf16 part of the strpos */
194-
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* fIgnoreCase */, 0, locale, strength /*last */ );
190+
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* fIgnoreCase */, 0, locale /*last */ );
195191

196192
if ( ret_pos >= 0 ) {
197193
RETURN_LONG(ret_pos);
@@ -210,17 +206,15 @@ PHP_FUNCTION(grapheme_strrpos)
210206
size_t haystack_len, needle_len, locale_len;
211207
zend_long loffset = 0;
212208
int32_t offset = 0;
213-
zend_long strength = UCOL_DEFAULT_STRENGTH;
214209
zend_long ret_pos;
215210
int is_ascii;
216211

217-
ZEND_PARSE_PARAMETERS_START(2, 5)
212+
ZEND_PARSE_PARAMETERS_START(2, 4)
218213
Z_PARAM_STRING(haystack, haystack_len)
219214
Z_PARAM_STRING(needle, needle_len)
220215
Z_PARAM_OPTIONAL
221216
Z_PARAM_LONG(loffset)
222217
Z_PARAM_STRING(locale, locale_len)
223-
Z_PARAM_LONG(strength)
224218
ZEND_PARSE_PARAMETERS_END();
225219

226220
if ( OUTSIDE_STRING(loffset, haystack_len) ) {
@@ -252,7 +246,7 @@ PHP_FUNCTION(grapheme_strrpos)
252246
/* else we need to continue via utf16 */
253247
}
254248

255-
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* f_ignore_case */, 1, locale, strength /* last */);
249+
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* f_ignore_case */, 1, locale /* last */);
256250

257251
if ( ret_pos >= 0 ) {
258252
RETURN_LONG(ret_pos);
@@ -271,17 +265,15 @@ PHP_FUNCTION(grapheme_strripos)
271265
size_t haystack_len, needle_len, locale_len = 0;
272266
zend_long loffset = 0;
273267
int32_t offset = 0;
274-
zend_long strength = UCOL_SECONDARY;
275268
zend_long ret_pos;
276269
int is_ascii;
277270

278-
ZEND_PARSE_PARAMETERS_START(2, 5)
271+
ZEND_PARSE_PARAMETERS_START(2, 4)
279272
Z_PARAM_STRING(haystack, haystack_len)
280273
Z_PARAM_STRING(needle, needle_len)
281274
Z_PARAM_OPTIONAL
282275
Z_PARAM_LONG(loffset)
283276
Z_PARAM_STRING(locale, locale_len)
284-
Z_PARAM_LONG(strength)
285277
ZEND_PARSE_PARAMETERS_END();
286278

287279
if ( OUTSIDE_STRING(loffset, haystack_len) ) {
@@ -322,7 +314,7 @@ PHP_FUNCTION(grapheme_strripos)
322314
/* else we need to continue via utf16 */
323315
}
324316

325-
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* f_ignore_case */, 1, locale, strength /*last */);
317+
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* f_ignore_case */, 1, locale /*last */);
326318

327319
if ( ret_pos >= 0 ) {
328320
RETURN_LONG(ret_pos);
@@ -344,7 +336,6 @@ PHP_FUNCTION(grapheme_substr)
344336
int32_t ustr_len;
345337
zend_long lstart = 0, length = 0;
346338
int32_t start = 0;
347-
zend_long strength = UCOL_DEFAULT;
348339
int iter_val;
349340
UErrorCode status;
350341
unsigned char u_break_iterator_buffer[U_BRK_SAFECLONE_BUFFERSIZE];
@@ -353,13 +344,12 @@ PHP_FUNCTION(grapheme_substr)
353344
int32_t (*iter_func)(UBreakIterator *);
354345
bool no_length = true;
355346

356-
ZEND_PARSE_PARAMETERS_START(2, 5)
347+
ZEND_PARSE_PARAMETERS_START(2, 4)
357348
Z_PARAM_STRING(str, str_len)
358349
Z_PARAM_LONG(lstart)
359350
Z_PARAM_OPTIONAL
360351
Z_PARAM_LONG_OR_NULL(length, no_length)
361352
Z_PARAM_STRING(locale, locale_len)
362-
Z_PARAM_LONG(strength)
363353
ZEND_PARSE_PARAMETERS_END();
364354

365355
if (lstart < INT32_MIN || lstart > INT32_MAX) {
@@ -557,22 +547,14 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas
557547
const char *found;
558548
size_t haystack_len, needle_len, locale_len = 0;
559549
int32_t ret_pos, uchar_pos;
560-
zend_long strength;
561550
bool part = false;
562551

563-
if (f_ignore_case) {
564-
strength = UCOL_SECONDARY;
565-
} else {
566-
strength = UCOL_DEFAULT_STRENGTH;
567-
}
568-
569-
ZEND_PARSE_PARAMETERS_START(2, 5)
552+
ZEND_PARSE_PARAMETERS_START(2, 4)
570553
Z_PARAM_STRING(haystack, haystack_len)
571554
Z_PARAM_STRING(needle, needle_len)
572555
Z_PARAM_OPTIONAL
573556
Z_PARAM_BOOL(part)
574557
Z_PARAM_STRING(locale, locale_len)
575-
Z_PARAM_LONG(strength)
576558
ZEND_PARSE_PARAMETERS_END();
577559

578560
if ( !f_ignore_case ) {
@@ -599,7 +581,7 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas
599581
}
600582

601583
/* need to work in utf16 */
602-
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, 0, &uchar_pos, f_ignore_case, 0, locale, strength /*last */ );
584+
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, 0, &uchar_pos, f_ignore_case, 0, locale /*last */ );
603585

604586
if ( ret_pos < 0 ) {
605587
RETURN_FALSE;
@@ -946,17 +928,15 @@ PHP_FUNCTION(grapheme_levenshtein)
946928
zend_long cost_del = 1;
947929
char *locale = "";
948930
size_t locale_len = 0;
949-
zend_long strength = UCOL_DEFAULT_STRENGTH;
950931

951-
ZEND_PARSE_PARAMETERS_START(2, 7)
932+
ZEND_PARSE_PARAMETERS_START(2, 6)
952933
Z_PARAM_STR(string1)
953934
Z_PARAM_STR(string2)
954935
Z_PARAM_OPTIONAL
955936
Z_PARAM_LONG(cost_ins)
956937
Z_PARAM_LONG(cost_rep)
957938
Z_PARAM_LONG(cost_del)
958939
Z_PARAM_STRING(locale, locale_len)
959-
Z_PARAM_LONG(strength)
960940
ZEND_PARSE_PARAMETERS_END();
961941

962942
if (cost_ins <= 0 || cost_ins > UINT_MAX / 4) {
@@ -1081,7 +1061,6 @@ PHP_FUNCTION(grapheme_levenshtein)
10811061
RETVAL_FALSE;
10821062
goto out_collator;
10831063
}
1084-
ucol_setStrength(collator, strength);
10851064

10861065
zend_long *p1, *p2, *tmp;
10871066
p1 = safe_emalloc((size_t) strlen_2 + 1, sizeof(zend_long), 0);

ext/intl/grapheme/grapheme_util.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void grapheme_substr_ascii(char *str, size_t str_len, int32_t f, int32_t l, char
9494

9595

9696
/* {{{ grapheme_strpos_utf16 - strrpos using utf16*/
97-
int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int32_t *puchar_pos, int f_ignore_case, int last, char* locale, int32_t strength)
97+
int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int32_t *puchar_pos, int f_ignore_case, int last, char* locale)
9898
{
9999
UChar *uhaystack = NULL, *uneedle = NULL;
100100
int32_t uhaystack_len = 0, uneedle_len = 0, char_pos, ret_pos, offset_pos = 0;
@@ -139,11 +139,13 @@ int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle,
139139
src = usearch_open(uneedle, uneedle_len, uhaystack, uhaystack_len, locale, bi, &status);
140140
STRPOS_CHECK_STATUS(status, "Error creating search object");
141141

142-
UCollator *coll = usearch_getCollator(src);
143-
ucol_setAttribute(coll, UCOL_STRENGTH, strength, &status);
144-
STRPOS_CHECK_STATUS(status, "Error setting collation strength");
145-
status = U_ZERO_ERROR;
146-
usearch_reset(src);
142+
if(f_ignore_case) {
143+
UCollator *coll = usearch_getCollator(src);
144+
status = U_ZERO_ERROR;
145+
ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_SECONDARY, &status);
146+
STRPOS_CHECK_STATUS(status, "Error setting collation strength");
147+
usearch_reset(src);
148+
}
147149

148150
if(offset != 0) {
149151
offset_pos = grapheme_get_haystack_offset(bi, offset);

ext/intl/grapheme/grapheme_util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ zend_long grapheme_ascii_check(const unsigned char *day, size_t len);
2525
void grapheme_substr_ascii(char *str, size_t str_len, int32_t f, int32_t l, char **sub_str, int32_t *sub_str_len);
2626
zend_long grapheme_strrpos_ascii(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset);
2727

28-
int32_t grapheme_strrpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int f_ignore_case, char* locale, int32_t strength);
29-
int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int *puchar_pos, int f_ignore_case, int last, char* locale, int32_t strength);
28+
int32_t grapheme_strrpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int f_ignore_case, char* locale);
29+
int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int *puchar_pos, int f_ignore_case, int last, char* locale);
3030

3131
int32_t grapheme_split_string(const UChar *text, int32_t text_length, int boundary_array[], int boundary_array_len );
3232

ext/intl/php_intl.stub.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,6 @@
166166
* @cvalue UIDNA_ERROR_CONTEXTJ
167167
*/
168168
const IDNA_ERROR_CONTEXTJ = UNKNOWN;
169-
/**
170-
* @var int
171-
* @cvalue UCOL_DEFAULT_STRENGTH
172-
*/
173-
const UCOL_DEFAULT_STRENGTH = UNKNOWN;
174-
/**
175-
* @var int
176-
* @cvalue UCOL_SECONDARY
177-
*/
178-
const UCOL_SECONDARY = UNKNOWN;
179169

180170
class IntlException extends Exception
181171
{
@@ -437,23 +427,23 @@ function numfmt_get_error_message(NumberFormatter $formatter): string {}
437427

438428
function grapheme_strlen(string $string): int|false|null {}
439429

440-
function grapheme_strpos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): int|false {}
430+
function grapheme_strpos(string $haystack, string $needle, int $offset = 0, string $locale = ""): int|false {}
441431

442-
function grapheme_stripos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_SECONDARY): int|false {}
432+
function grapheme_stripos(string $haystack, string $needle, int $offset = 0, string $locale = ""): int|false {}
443433

444-
function grapheme_strrpos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): int|false {}
434+
function grapheme_strrpos(string $haystack, string $needle, int $offset = 0, string $locale = ""): int|false {}
445435

446-
function grapheme_strripos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_SECONDARY): int|false {}
436+
function grapheme_strripos(string $haystack, string $needle, int $offset = 0, string $locale = ""): int|false {}
447437

448-
function grapheme_substr(string $string, int $offset, ?int $length = null, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): string|false {}
438+
function grapheme_substr(string $string, int $offset, ?int $length = null, string $locale = ""): string|false {}
449439

450-
function grapheme_strstr(string $haystack, string $needle, bool $beforeNeedle = false, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): string|false {}
440+
function grapheme_strstr(string $haystack, string $needle, bool $beforeNeedle = false, string $locale = ""): string|false {}
451441

452-
function grapheme_stristr(string $haystack, string $needle, bool $beforeNeedle = false, string $locale = "", int $strength = UCOL_SECONDARY): string|false {}
442+
function grapheme_stristr(string $haystack, string $needle, bool $beforeNeedle = false, string $locale = ""): string|false {}
453443

454444
function grapheme_str_split(string $string, int $length = 1): array|false {}
455445

456-
function grapheme_levenshtein(string $string1, string $string2, int $insertion_cost = 1, int $replacement_cost = 1, int $deletion_cost = 1, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): int|false {}
446+
function grapheme_levenshtein(string $string1, string $string2, int $insertion_cost = 1, int $replacement_cost = 1, int $deletion_cost = 1, string $locale = ""): int|false {}
457447

458448
/** @param int $next */
459449
function grapheme_extract(string $haystack, int $size, int $type = GRAPHEME_EXTR_COUNT, int $offset = 0, &$next = null): string|false {}

ext/intl/php_intl_arginfo.h

Lines changed: 4 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/intl/tests/grapheme_levenshtein.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ var_dump(grapheme_levenshtein($nabe, $nabe_E0100));
6060

6161
// variable $nabe and $nabe_E0101 is different because that is IVS.
6262
// $nabe_E0101 is variable selector in U+908A U+E0101.
63-
// grapheme_levenshtein can catches different only match strength is Collator::IDENTICAL.
64-
// So result is maybe 1.
63+
// grapheme_levenshtein can catches different only match strength is u-ks-identic for locale.
64+
// So result is expect to 1.
6565
$nabe = '';
6666
$nabe_E0101 = "\u{908A}\u{E0101}";
67-
var_dump(grapheme_levenshtein($nabe, $nabe_E0101, strength: Collator::IDENTICAL));
67+
var_dump(grapheme_levenshtein($nabe, $nabe_E0101, locale: "ja_JP-u-ks-identic"));
6868

6969
// combining character
7070
var_dump(grapheme_levenshtein("\u{0065}\u{0301}", "\u{00e9}"));

0 commit comments

Comments
 (0)