mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
[RFC] Add grapheme_strrev function (#20949)
* [RFC] Add grapheme_strrev function Add more tests Arabic for grapheme_strrev function.
This commit is contained in:
1
NEWS
1
NEWS
@@ -37,6 +37,7 @@ PHP NEWS
|
||||
(BogdanUngureanu)
|
||||
. Fixed bug GH-20426 (Spoofchecker::setRestrictionLevel() error message
|
||||
suggests missing constants). (DanielEScherzer)
|
||||
. Added grapheme_strrev (Yuya Hamada)
|
||||
|
||||
- JSON:
|
||||
. Enriched JSON last error / exception message with error location.
|
||||
|
||||
@@ -137,6 +137,10 @@ PHP 8.6 UPGRADE NOTES
|
||||
. Added ReflectionProperty::isReadable() and ReflectionProperty::isWritable().
|
||||
RFC: https://wiki.php.net/rfc/isreadable-iswriteable
|
||||
|
||||
- Intl:
|
||||
. `grapheme_strrev()` returns strrev for grapheme cluster unit.
|
||||
RFC: https://wiki.php.net/rfc/grapheme_strrev
|
||||
|
||||
- Standard:
|
||||
. `clamp()` returns the given value if in range, else return the nearest
|
||||
bound.
|
||||
|
||||
@@ -1135,4 +1135,63 @@ out_ustring1:
|
||||
efree(ustring1);
|
||||
}
|
||||
|
||||
U_CFUNC PHP_FUNCTION(grapheme_strrev)
|
||||
{
|
||||
zend_string *string;
|
||||
UText *ut = nullptr;
|
||||
UErrorCode ustatus = U_ZERO_ERROR;
|
||||
UBreakIterator *bi;
|
||||
char *pstr, *end, *p;
|
||||
zend_string *ret;
|
||||
int32_t pos = 0, current = 0, end_len = 0;
|
||||
unsigned char u_break_iterator_buffer[U_BRK_SAFECLONE_BUFFERSIZE];
|
||||
|
||||
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||
Z_PARAM_STR(string)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
if (ZSTR_LEN(string) == 0) {
|
||||
RETURN_EMPTY_STRING();
|
||||
}
|
||||
|
||||
pstr = ZSTR_VAL(string);
|
||||
ut = utext_openUTF8(ut, pstr, ZSTR_LEN(string), &ustatus);
|
||||
|
||||
if (U_FAILURE(ustatus)) {
|
||||
intl_error_set_code(nullptr, ustatus);
|
||||
intl_error_set_custom_msg(nullptr, "Error opening UTF-8 text");
|
||||
|
||||
RETVAL_FALSE;
|
||||
goto close;
|
||||
}
|
||||
|
||||
bi = nullptr;
|
||||
ustatus = U_ZERO_ERROR;
|
||||
|
||||
bi = grapheme_get_break_iterator((void*)u_break_iterator_buffer, &ustatus );
|
||||
ret = zend_string_alloc(ZSTR_LEN(string), 0);
|
||||
p = ZSTR_VAL(ret);
|
||||
|
||||
ubrk_setUText(bi, ut, &ustatus);
|
||||
pos = ubrk_last(bi);
|
||||
if (pos == UBRK_DONE) {
|
||||
goto ubrk_end;
|
||||
}
|
||||
|
||||
current = ZSTR_LEN(string);
|
||||
for (end = pstr; pos != UBRK_DONE; ) {
|
||||
pos = ubrk_previous(bi);
|
||||
end_len = current - pos;
|
||||
for (int32_t j = 0; j < end_len; j++) {
|
||||
*p++ = *(pstr + pos + j);
|
||||
}
|
||||
current = pos;
|
||||
}
|
||||
ubrk_end:
|
||||
RETVAL_NEW_STR(ret);
|
||||
ubrk_close(bi);
|
||||
close:
|
||||
utext_close(ut);
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
@@ -445,6 +445,8 @@ function grapheme_str_split(string $string, int $length = 1): array|false {}
|
||||
|
||||
function grapheme_levenshtein(string $string1, string $string2, int $insertion_cost = 1, int $replacement_cost = 1, int $deletion_cost = 1, string $locale = ""): int|false {}
|
||||
|
||||
function grapheme_strrev(string $string): string|false {}
|
||||
|
||||
/** @param int $next */
|
||||
function grapheme_extract(string $haystack, int $size, int $type = GRAPHEME_EXTR_COUNT, int $offset = 0, &$next = null): string|false {}
|
||||
|
||||
|
||||
8
ext/intl/php_intl_arginfo.h
generated
8
ext/intl/php_intl_arginfo.h
generated
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit php_intl.stub.php instead.
|
||||
* Stub hash: d9e331c3a1ae46f8eae07ef0d39cb9990e74a0d1 */
|
||||
* Stub hash: c52fd0def2530be628beedbbcdcfecdcb07449a8 */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_intlcal_create_instance, 0, 0, IntlCalendar, 1)
|
||||
ZEND_ARG_OBJ_TYPE_MASK(0, timezone, IntlTimeZone|DateTimeZone, MAY_BE_STRING|MAY_BE_NULL, "null")
|
||||
@@ -501,6 +501,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_levenshtein, 0, 2, MAY_
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 0, "\"\"")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_strrev, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
|
||||
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_extract, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
|
||||
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0)
|
||||
@@ -922,6 +926,7 @@ ZEND_FUNCTION(grapheme_strstr);
|
||||
ZEND_FUNCTION(grapheme_stristr);
|
||||
ZEND_FUNCTION(grapheme_str_split);
|
||||
ZEND_FUNCTION(grapheme_levenshtein);
|
||||
ZEND_FUNCTION(grapheme_strrev);
|
||||
ZEND_FUNCTION(grapheme_extract);
|
||||
ZEND_FUNCTION(idn_to_ascii);
|
||||
ZEND_FUNCTION(idn_to_utf8);
|
||||
@@ -1113,6 +1118,7 @@ static const zend_function_entry ext_functions[] = {
|
||||
ZEND_FE(grapheme_stristr, arginfo_grapheme_stristr)
|
||||
ZEND_FE(grapheme_str_split, arginfo_grapheme_str_split)
|
||||
ZEND_FE(grapheme_levenshtein, arginfo_grapheme_levenshtein)
|
||||
ZEND_FE(grapheme_strrev, arginfo_grapheme_strrev)
|
||||
ZEND_FE(grapheme_extract, arginfo_grapheme_extract)
|
||||
ZEND_FE(idn_to_ascii, arginfo_idn_to_ascii)
|
||||
ZEND_FE(idn_to_utf8, arginfo_idn_to_utf8)
|
||||
|
||||
BIN
ext/intl/tests/grapheme_strrev.phpt
Normal file
BIN
ext/intl/tests/grapheme_strrev.phpt
Normal file
Binary file not shown.
Reference in New Issue
Block a user