Package com.maybeitssquid.safeascii
Class ASCIIFilter
java.lang.Object
com.maybeitssquid.safeascii.ASCIIFilter
- All Implemented Interfaces:
IntFunction<CharSequence>
A filter function that selectively preserves ASCII characters.
This class processes Unicode codepoints, retaining them only if they are within the ASCII
range (codepoints less than 128) and do not belong to any of the blocked Unicode categories
defined at construction (see Character.getType(int)). Codepoints that do not meet these
criteria are transformed into an empty string.
-
Constructor Summary
ConstructorsConstructorDescriptionASCIIFilter(byte... block) Create an ASCII filter that blocks characters of the specified Unicode categories. -
Method Summary
-
Constructor Details
-
ASCIIFilter
public ASCIIFilter(byte... block) Create an ASCII filter that blocks characters of the specified Unicode categories.To create an instance that allows all ASCII characters, use:
ASCIIFilter ascii = new ASCIIFilter();To create an instance that disallows ASCII control characters, use:
ASCIIFilter blockControls = new ASCIIFilter(Character.CONTROL);- Parameters:
block- Unicode categories to block- See Also:
-
-
Method Details
-
apply
Processes a Unicode codepoint.- Specified by:
applyin interfaceIntFunction<CharSequence>- Parameters:
value- the codepoint to process.- Returns:
- a string containing the character if it is a permitted ASCII character; otherwise, an empty string.
-