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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final BundledUnicodeData.Lazy<Confusables.Data> private static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanconfusable(CharSequence left, CharSequence right) Returns whetherleftandrightare confusable.private static Confusables.Dataload()Returns the prototype mapping and key set parsed from the bundledconfusables.txtresource.parse(InputStream in) Parses the source-to-prototype mappings from theconfusables.txtdata.static Stringskeleton(CharSequence text) Returns the confusable skeleton oftext:NFD(map(NFD(text)))wheremapreplaces each code point with its UTS #39 prototype.
-
Field Details
-
RESOURCE
- See Also:
-
DATA
-
-
Constructor Details
-
Confusables
private Confusables()
-
-
Method Details
-
load
Returns the prototype mapping and key set parsed from the bundledconfusables.txtresource.- Returns:
- the prototype mapping and key set parsed from the bundled
confusables.txtresource - Throws:
IllegalStateException- Thrown if the resource is missing.UncheckedIOException- Thrown if the resource cannot be read.
-
parse
Parses the source-to-prototype mappings from theconfusables.txtdata. Package-private so the malformed-data handling can be exercised without the bundled resource.- Parameters:
in- The data stream.- Returns:
- The source code point to prototype string mapping.
- Throws:
IOException- Thrown if the stream cannot be read.IllegalArgumentException- Thrown if a line is structurally malformed or holds a non-hexadecimal code point.
-
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.
-