ext/intl: Add SpoofChecker::getBidiSkeleton() - #23017
Merged
Merged
Conversation
devnexen
reviewed
Aug 4, 2026
| } | ||
|
|
||
| UnicodeString skeleton; | ||
| uspoof_getBidiSkeletonUnicodeString( |
Member
There was a problem hiding this comment.
why not uspoof_getBidiSkeletonUTF8 ?
Member
Author
There was a problem hiding this comment.
Correct, since PHP strings are already UTF-8 byte strings :)
| #if __cplusplus >= 201703L | ||
| #include <string_view> | ||
| #include <unicode/unistr.h> | ||
| #include <unicode/uspoof.h> |
Member
There was a problem hiding this comment.
if you remove it, do you get a build error ?
Member
Author
There was a problem hiding this comment.
Yes. php_intl.h set U_SHOW_CPLUSPLUS_API to 0 so the declaration of uspoof_getBidiSkeletonUnicodeString() was hidden, even though ICU’s symbol-renaming macro still expanded the call to uspoof_getBidiSkeletonUnicodeString_74.
So I need to manually add this.
Member
Author
There was a problem hiding this comment.
However, if we use the UTF8 API here, we can remove this.
devnexen
reviewed
Aug 4, 2026
|
|
||
| var_dump($checker->getBidiSkeleton(Spoofchecker::LTR, "\x80")); | ||
| var_dump(intl_get_error_code() === U_INVALID_CHAR_FOUND); | ||
| ?> |
Member
There was a problem hiding this comment.
nice to have
var_dump(
$checker->getBidiSkeleton(Spoofchecker::LTR, "\u{05D0}A_1") ===
$checker->getBidiSkeleton(Spoofchecker::LTR, "\u{05D0}1_A")
);
var_dump(
$checker->getBidiSkeleton(Spoofchecker::RTL, "\u{05D0}A_1") ===
$checker->getBidiSkeleton(Spoofchecker::RTL, "\u{05D0}1_A")
);Co-Authored-By: David CARLIER <devnexen@gmail.com>
devnexen
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up #13469. Since we have
SpoofChecker::areBidiConfusable()with all these constant (UBIDI_LTR, UBIDI_RTL, UBIDI_MIXED and UBIDI_NEUTRAL) it can only determine whether two strings are visually confusable in a given text direction. Applications that need to detect confusable identifiers among a large existing set would otherwise need to repeatedly perform pairwise comparisons usingareBidiConfusable().Now since ICU 74+ and we have
SpoofChecker::areBidiConfusable()already, it is convenient to add the correspondingSpoofChecker::areBidiConfusable(). ICU's bidi skeleton API transforms an identifier into a skeleton for a given text direction. So it is useful for larger compares.e.g.
The internal API is documented at: https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/uspoof_8h.html#a5aeeef353b4cca531b61480597a03e85