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
Fields -
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 WHITE- See Also:
-
NON_WORD
public static final int NON_WORD- See Also:
-
DELIMITER
public static final int DELIMITER- See Also:
-
LOWER
public static final int LOWER- See Also:
-
UPPER
public static final int UPPER- See Also:
-
LETTER
public static final int LETTER- See Also:
-
NUMBER
public static final int NUMBER- 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
-