Class Confusables
"paypal" and a version using Cyrillic
lookalikes, exactly when their skeletons are equal.
The mapping is loaded on first use from the confusables.txt resource of the Unicode
security data. If that resource is missing or cannot be read, every call that needs it throws
IllegalStateException or UncheckedIOException. The skeleton of a string
is NFD(map(NFD(s))): decompose, replace each code point with its prototype, and
decompose again. This changes length and offsets, so it is a matching-only comparison form, not
an offset-preserving transform.
This implements only the UTS #39 skeleton transform and the confusable-detection test built on skeleton equality. The other mechanisms defined in the report, such as identifier restriction levels, mixed-script and whole-script confusable detection, and the bidirectional skeleton, are out of scope.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanconfusable(CharSequence left, CharSequence right) Returns whetherleftandrightare confusable.static Stringskeleton(CharSequence text) Returns the confusable skeleton oftext:NFD(map(NFD(text)))wheremapreplaces each code point with its UTS #39 prototype.
-
Method Details
-
skeleton
Returns the confusable skeleton oftext:NFD(map(NFD(text)))wheremapreplaces each code point with its UTS #39 prototype. The skeleton is for comparison only; it is not human-readable text and does not preserve offsets.- Parameters:
text- The text to reduce.- Returns:
- The skeleton.
- Throws:
IllegalArgumentException- Thrown iftextisnull.IllegalStateException- Thrown if the bundledconfusables.txtresource is missing.UncheckedIOException- Thrown if the bundledconfusables.txtresource cannot be read.
-
confusable
- Parameters:
left- The first string.right- The second string.- Returns:
- whether
leftandrightare confusable - Throws:
IllegalArgumentException- Thrown ifleftorrightisnull.IllegalStateException- Thrown if the bundledconfusables.txtresource is missing.UncheckedIOException- Thrown if the bundledconfusables.txtresource cannot be read.
-