Skip to content

Implement grapheme_mask() function#22605

Open
sepehrphpr wants to merge 39 commits into
php:masterfrom
sepehrphpr:master
Open

Implement grapheme_mask() function#22605
sepehrphpr wants to merge 39 commits into
php:masterfrom
sepehrphpr:master

Conversation

@sepehrphpr

Copy link
Copy Markdown

Description

Adds grapheme_mask() function to the intl extension for Unicode-aware string masking.

Features

  • Masks a portion of a string based on grapheme clusters (not bytes)
  • Supports Unicode grapheme clusters including emoji sequences, combining characters, and ZWJ sequences
  • Proper validation of mask character (must be exactly one grapheme cluster)
  • Similar interface to substr() with offset and length parameters

Implementation

  • New function in ext/intl/grapheme.c
  • Helper functions in grapheme_util.h
  • Comprehensive tests in ext/intl/tests/grapheme_mask.phpt

Examples

grapheme_mask("Hello World", "*", 3, 2); // "Hello **rld"
grapheme_mask("سلام دنیا", "#", 2, 3);   // "سا###نیا"
grapheme_mask("👨‍👩‍👧‍👦 Family", "", 0, 1); // "• Family"

## RFC
Implements RFC: https://wiki.php.net/rfc/grapheme_mask

@youkidearitai

Copy link
Copy Markdown
Contributor

Thank you very much for your pull request.
But your master branch is seems old, Could you rebase origin/master? (PHP License is out of date, Modified-BSD license in PHP 8.6)
And, your patch infinite loop when compiling. Please fix them.

@LamentXU123 LamentXU123 left a comment

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.

This doesn't only add grapheme_mask function. Please be clear in documenting what your changes bring for people to review.

Also, this very much requires a RFC, see how to create a RFC here

@youkidearitai

Copy link
Copy Markdown
Contributor

RFC is here: https://wiki.php.net/rfc/grapheme_mask
(Please write description)

@LamentXU123

LamentXU123 commented Jul 5, 2026

Copy link
Copy Markdown
Member

I see. Thank you.
(edited) You may also need to fix the License header in files you've changed.

@sepehrphpr

sepehrphpr commented Jul 5, 2026 via email

Copy link
Copy Markdown
Author

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.

3 participants