Class CharClass
java.lang.Object
org.aesh.readline.fuzzy.CharClass
Character classification and bonus matrix for fuzzy matching.
This is a direct port of fzf's character classification system.
Characters are classified into one of 7 categories, and a precomputed
bonusMatrix[prevClass][curClass] lookup table provides the bonus
score for matching at each position based on the transition between
adjacent character classes.
The ASCII fast path (classOfAscii(int)) uses a precomputed
128-entry lookup table for O(1) classification of ASCII characters.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDelimiter character class (/,:;|).static final intLetter character class (non-cased letters, e.g.static final intLowercase letter character class.static final intNon-word character class (punctuation and symbols not in other classes).static final intNumeric digit character class.static final intUppercase letter character class.static final intWhitespace character class (spaces, tabs, newlines). -
Method Summary
Modifier and TypeMethodDescriptionstatic shortbonus(int prevClass, int curClass) Look up the bonus for a character at a given position based on the previous and current character classes.static shortbonusAt(int[] input, int idx, FuzzyScheme scheme) Calculate the bonus for matching at a given position in the input.static intclassOf(int codePoint) Classify a character (code point).static voidinit(FuzzyScheme scheme) Initialize the bonus matrix for a given scheme.
-
Field Details
-
WHITE
public static final int WHITEWhitespace character class (spaces, tabs, newlines).- See Also:
-
NON_WORD
public static final int NON_WORDNon-word character class (punctuation and symbols not in other classes).- See Also:
-
DELIMITER
public static final int DELIMITERDelimiter character class (/,:;|).- See Also:
-
LOWER
public static final int LOWERLowercase letter character class.- See Also:
-
UPPER
public static final int UPPERUppercase letter character class.- See Also:
-
LETTER
public static final int LETTERLetter character class (non-cased letters, e.g. CJK ideographs).- See Also:
-
NUMBER
public static final int NUMBERNumeric digit character class.- See Also:
-
-
Method Details
-
init
Initialize the bonus matrix for a given scheme. Must be called before using the bonus matrix.- Parameters:
scheme- the scoring scheme to use
-
classOf
public static int classOf(int codePoint) Classify a character (code point). Uses the fast ASCII lookup table for code points 0-127, falls back to Unicode classification for non-ASCII.- Parameters:
codePoint- the character code point- Returns:
- the character class constant
-
bonus
public static short bonus(int prevClass, int curClass) Look up the bonus for a character at a given position based on the previous and current character classes.- Parameters:
prevClass- the class of the preceding charactercurClass- the class of the current character- Returns:
- the bonus score
-
bonusAt
Calculate the bonus for matching at a given position in the input.- Parameters:
input- the input code pointsidx- the position in the inputscheme- the scoring scheme (for initialCharClass)- Returns:
- the bonus score
-