-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Add a locale for grapheme case-insensitive functions #18792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
d3b2061
8938426
8f2e544
4988e9a
7996330
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,7 @@ PHP_FUNCTION(grapheme_strpos) | |
char *haystack, *needle; | ||
size_t haystack_len, needle_len; | ||
const char *found; | ||
char *locale = ""; | ||
zend_long loffset = 0; | ||
int32_t offset = 0; | ||
size_t noffset = 0; | ||
|
@@ -121,7 +122,7 @@ PHP_FUNCTION(grapheme_strpos) | |
} | ||
|
||
/* do utf16 part of the strpos */ | ||
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* fIgnoreCase */, 0 /* last */ ); | ||
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* fIgnoreCase */, 0, locale /* last */ ); | ||
|
||
if ( ret_pos >= 0 ) { | ||
RETURN_LONG(ret_pos); | ||
|
@@ -134,19 +135,20 @@ PHP_FUNCTION(grapheme_strpos) | |
/* {{{ Find position of first occurrence of a string within another, ignoring case differences */ | ||
PHP_FUNCTION(grapheme_stripos) | ||
{ | ||
char *haystack, *needle; | ||
size_t haystack_len, needle_len; | ||
char *haystack, *needle, *locale = ""; | ||
size_t haystack_len, needle_len, locale_len = 0; | ||
const char *found; | ||
zend_long loffset = 0; | ||
int32_t offset = 0; | ||
zend_long ret_pos; | ||
int is_ascii; | ||
|
||
ZEND_PARSE_PARAMETERS_START(2, 3) | ||
ZEND_PARSE_PARAMETERS_START(2, 4) | ||
Z_PARAM_STRING(haystack, haystack_len) | ||
Z_PARAM_STRING(needle, needle_len) | ||
Z_PARAM_OPTIONAL | ||
Z_PARAM_LONG(loffset) | ||
Z_PARAM_STRING_OR_NULL(locale, locale_len) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you tell what happens if locale_len == 0 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I don't understand. Could you tell me what happens? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, In this case, calls default locales (not root locale if locale is |
||
ZEND_PARSE_PARAMETERS_END(); | ||
|
||
if ( OUTSIDE_STRING(loffset, haystack_len) ) { | ||
|
@@ -185,7 +187,7 @@ PHP_FUNCTION(grapheme_stripos) | |
} | ||
|
||
/* do utf16 part of the strpos */ | ||
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* fIgnoreCase */, 0 /*last */ ); | ||
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* fIgnoreCase */, 0, locale /*last */ ); | ||
|
||
if ( ret_pos >= 0 ) { | ||
RETURN_LONG(ret_pos); | ||
|
@@ -200,6 +202,7 @@ PHP_FUNCTION(grapheme_stripos) | |
PHP_FUNCTION(grapheme_strrpos) | ||
{ | ||
char *haystack, *needle; | ||
char *locale = ""; | ||
size_t haystack_len, needle_len; | ||
zend_long loffset = 0; | ||
int32_t offset = 0; | ||
|
@@ -242,7 +245,7 @@ PHP_FUNCTION(grapheme_strrpos) | |
/* else we need to continue via utf16 */ | ||
} | ||
|
||
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* f_ignore_case */, 1/* last */); | ||
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* f_ignore_case */, 1, locale /* last */); | ||
|
||
if ( ret_pos >= 0 ) { | ||
RETURN_LONG(ret_pos); | ||
|
@@ -257,18 +260,19 @@ PHP_FUNCTION(grapheme_strrpos) | |
/* {{{ Find position of last occurrence of a string within another, ignoring case */ | ||
PHP_FUNCTION(grapheme_strripos) | ||
{ | ||
char *haystack, *needle; | ||
size_t haystack_len, needle_len; | ||
char *haystack, *needle, *locale = ""; | ||
size_t haystack_len, needle_len, locale_len = 0; | ||
zend_long loffset = 0; | ||
int32_t offset = 0; | ||
zend_long ret_pos; | ||
int is_ascii; | ||
|
||
ZEND_PARSE_PARAMETERS_START(2, 3) | ||
ZEND_PARSE_PARAMETERS_START(2, 4) | ||
Z_PARAM_STRING(haystack, haystack_len) | ||
Z_PARAM_STRING(needle, needle_len) | ||
Z_PARAM_OPTIONAL | ||
Z_PARAM_LONG(loffset) | ||
Z_PARAM_STRING_OR_NULL(locale, locale_len) | ||
ZEND_PARSE_PARAMETERS_END(); | ||
|
||
if ( OUTSIDE_STRING(loffset, haystack_len) ) { | ||
|
@@ -309,7 +313,7 @@ PHP_FUNCTION(grapheme_strripos) | |
/* else we need to continue via utf16 */ | ||
} | ||
|
||
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* f_ignore_case */, 1 /*last */); | ||
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* f_ignore_case */, 1, locale /*last */); | ||
|
||
if ( ret_pos >= 0 ) { | ||
RETURN_LONG(ret_pos); | ||
|
@@ -537,17 +541,18 @@ PHP_FUNCTION(grapheme_substr) | |
/* {{{ strstr_common_handler */ | ||
static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_case) | ||
{ | ||
char *haystack, *needle; | ||
char *haystack, *needle, *locale = ""; | ||
const char *found; | ||
size_t haystack_len, needle_len; | ||
size_t haystack_len, needle_len, locale_len = 0; | ||
int32_t ret_pos, uchar_pos; | ||
bool part = false; | ||
|
||
ZEND_PARSE_PARAMETERS_START(2, 3) | ||
ZEND_PARSE_PARAMETERS_START(2, 4) | ||
Z_PARAM_STRING(haystack, haystack_len) | ||
Z_PARAM_STRING(needle, needle_len) | ||
Z_PARAM_OPTIONAL | ||
Z_PARAM_BOOL(part) | ||
Z_PARAM_STRING_OR_NULL(locale, locale_len) | ||
ZEND_PARSE_PARAMETERS_END(); | ||
|
||
if ( !f_ignore_case ) { | ||
|
@@ -574,7 +579,7 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas | |
} | ||
|
||
/* need to work in utf16 */ | ||
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, 0, &uchar_pos, f_ignore_case, 0 /*last */ ); | ||
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, 0, &uchar_pos, f_ignore_case, 0, locale /*last */ ); | ||
|
||
if ( ret_pos < 0 ) { | ||
RETURN_FALSE; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
grapheme_stripos() function locale dependency test | ||
--EXTENSIONS-- | ||
intl | ||
--FILE-- | ||
<?php | ||
var_dump(grapheme_stripos("abc", "abc", 0)); | ||
var_dump(grapheme_stripos("i", "\u{0130}", 0, "tr_TR")); | ||
var_dump(grapheme_stripos("i", "\u{0130}", 0, "en_US")); | ||
?> | ||
--EXPECT-- | ||
int(0) | ||
int(0) | ||
bool(false) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--TEST-- | ||
grapheme_stristr() function locale dependency test | ||
--EXTENSIONS-- | ||
intl | ||
--FILE-- | ||
<?php | ||
var_dump(grapheme_stristr("abc", "abc", 0)); | ||
var_dump(grapheme_stristr("i", "\u{0130}", 0, "tr_TR")); | ||
var_dump(grapheme_stristr("i", "\u{0130}", 0, "en_US")); | ||
?> | ||
--EXPECT-- | ||
string(3) "abc" | ||
string(1) "i" | ||
bool(false) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
grapheme_strripos() function locale dependency test | ||
--EXTENSIONS-- | ||
intl | ||
--FILE-- | ||
<?php | ||
var_dump(grapheme_strripos("abc", "abc", 0)); | ||
var_dump(grapheme_strripos("i", "\u{0130}", 0, "tr_TR")); | ||
var_dump(grapheme_strripos("i", "\u{0130}", 0, "en_US")); | ||
?> | ||
--EXPECT-- | ||
int(0) | ||
int(0) | ||
bool(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should initialise these with
= NULL;
, the empty string is done in a code segment like this, and will not be happy when you free it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much. Indeed.
locale
should= NULL;
. Therefore, signature is wrong.