Skip to content

[RFC] Add grapheme_strrev function#20949

Merged
youkidearitai merged 6 commits intophp:masterfrom
youkidearitai:grapheme_strrev
Mar 4, 2026
Merged

[RFC] Add grapheme_strrev function#20949
youkidearitai merged 6 commits intophp:masterfrom
youkidearitai:grapheme_strrev

Conversation

@youkidearitai
Copy link
Copy Markdown
Contributor

Add grapheme_strrev function. strrev for grapheme cluster unit.

RFC: https://wiki.php.net/rfc/grapheme_strrev

Add more tests Arabic for grapheme_strrev function.
@youkidearitai youkidearitai marked this pull request as ready for review February 20, 2026 01:47
@youkidearitai
Copy link
Copy Markdown
Contributor Author

This RFC is accepted, So ready for review.

@youkidearitai
Copy link
Copy Markdown
Contributor Author

There's no rush, Does anyone review this?

p = ZSTR_VAL(ret);

ubrk_setUText(bi, ut, &ustatus);
pos = ubrk_last(bi);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might be worth check in case pos == UBRK_DONE is to "jump to conclusion" to bypass the loop below wdyt ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I added RETVAL_EMPTY_STRING.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one detail, do not forget you allocate ret pointer line 1172.

Copy link
Copy Markdown
Member

@devnexen devnexen Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might just simpler to raise the goto label at the 1190 line instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried add ubrk_end in RETVAL_NEW_STR .

ubrk_setUText(bi, ut, &ustatus);
pos = ubrk_last(bi);
if (pos == UBRK_DONE) {
RETVAL_EMPTY_STRING();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but then this line looks useless wdyt ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I remove RETVAL_EMPTY_STRING.

Copy link
Copy Markdown
Member

@devnexen devnexen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LCTM

@youkidearitai
Copy link
Copy Markdown
Contributor Author

Thank you, I'll merge tomorrow(maybe 9am JST) if there is no concern.

@youkidearitai youkidearitai merged commit 7a1c261 into php:master Mar 4, 2026
18 checks passed
@youkidearitai youkidearitai deleted the grapheme_strrev branch March 4, 2026 00:47
@youkidearitai
Copy link
Copy Markdown
Contributor Author

Thank you very much. Merged.

ubrk_setUText(bi, ut, &ustatus);
pos = ubrk_last(bi);
if (pos == UBRK_DONE) {
goto ubrk_end;
Copy link
Copy Markdown
Member

@ndossche ndossche Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this code path is taken, then the return value isn't set correctly I think?
If this code path is taken, is the string NUL terminated? It seems not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, Indeed. So I use RETVAL_EMPTY_STRING() in line 1178 right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the empty string should be returned and the string allocation should be postponed to after this is.
Looking further at this: I don't immediately understand what code writes the NUL terminator for the loop below?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants