Skip to content

Commit a993d00

Browse files
committed
Modify default value for grapheme_stri* functions
1 parent 3431fd7 commit a993d00

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

ext/intl/grapheme/grapheme_string.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ PHP_FUNCTION(grapheme_stripos)
142142
const char *found;
143143
zend_long loffset = 0;
144144
int32_t offset = 0;
145-
zend_long strength = UCOL_DEFAULT_STRENGTH;
145+
zend_long strength = UCOL_SECONDARY;
146146
zend_long ret_pos;
147147
int is_ascii;
148148

@@ -271,7 +271,7 @@ PHP_FUNCTION(grapheme_strripos)
271271
size_t haystack_len, needle_len, locale_len = 0;
272272
zend_long loffset = 0;
273273
int32_t offset = 0;
274-
zend_long strength = UCOL_DEFAULT_STRENGTH;
274+
zend_long strength = UCOL_SECONDARY;
275275
zend_long ret_pos;
276276
int is_ascii;
277277

@@ -557,9 +557,15 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas
557557
const char *found;
558558
size_t haystack_len, needle_len, locale_len = 0;
559559
int32_t ret_pos, uchar_pos;
560-
zend_long strength = UCOL_DEFAULT_STRENGTH;
560+
zend_long strength;
561561
bool part = false;
562562

563+
if (f_ignore_case) {
564+
strength = UCOL_SECONDARY;
565+
} else {
566+
strength = UCOL_DEFAULT_STRENGTH;
567+
}
568+
563569
ZEND_PARSE_PARAMETERS_START(2, 5)
564570
Z_PARAM_STRING(haystack, haystack_len)
565571
Z_PARAM_STRING(needle, needle_len)

ext/intl/grapheme/grapheme_util.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,11 @@ 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-
if(f_ignore_case) {
143-
UCollator *coll = usearch_getCollator(src);
144-
ucol_setStrength(coll, strength);
145-
status = U_ZERO_ERROR;
146-
ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_SECONDARY, &status);
147-
STRPOS_CHECK_STATUS(status, "Error setting collation strength");
148-
usearch_reset(src);
149-
}
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);
150147

151148
if(offset != 0) {
152149
offset_pos = grapheme_get_haystack_offset(bi, offset);

ext/intl/php_intl.stub.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@
171171
* @cvalue UCOL_DEFAULT_STRENGTH
172172
*/
173173
const UCOL_DEFAULT_STRENGTH = UNKNOWN;
174+
/**
175+
* @var int
176+
* @cvalue UCOL_SECONDARY
177+
*/
178+
const UCOL_SECONDARY = UNKNOWN;
174179

175180
class IntlException extends Exception
176181
{
@@ -438,17 +443,17 @@ function grapheme_strlen(string $string): int|false|null {}
438443

439444
function grapheme_strpos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): int|false {}
440445

441-
function grapheme_stripos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): int|false {}
446+
function grapheme_stripos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_SECONDARY): int|false {}
442447

443448
function grapheme_strrpos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): int|false {}
444449

445-
function grapheme_strripos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): int|false {}
450+
function grapheme_strripos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_SECONDARY): int|false {}
446451

447452
function grapheme_substr(string $string, int $offset, ?int $length = null, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): string|false {}
448453

449454
function grapheme_strstr(string $haystack, string $needle, bool $beforeNeedle = false, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): string|false {}
450455

451-
function grapheme_stristr(string $haystack, string $needle, bool $beforeNeedle = false, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): string|false {}
456+
function grapheme_stristr(string $haystack, string $needle, bool $beforeNeedle = false, string $locale = "", int $strength = UCOL_SECONDARY): string|false {}
452457

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

ext/intl/php_intl_arginfo.h

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

0 commit comments

Comments
 (0)