Class CharClass

java.lang.Object
org.aesh.readline.fuzzy.CharClass

public final class CharClass extends Object
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
    Modifier and Type
    Field
    Description
    static final int
    Delimiter character class (/,:;|).
    static final int
    Letter character class (non-cased letters, e.g.
    static final int
    Lowercase letter character class.
    static final int
    Non-word character class (punctuation and symbols not in other classes).
    static final int
    Numeric digit character class.
    static final int
    Uppercase letter character class.
    static final int
    Whitespace character class (spaces, tabs, newlines).
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    static short
    bonusAt(int[] input, int idx, FuzzyScheme scheme)
    Calculate the bonus for matching at a given position in the input.
    static int
    classOf(int codePoint)
    Classify a character (code point).
    static void
    init(FuzzyScheme scheme)
    Initialize the bonus matrix for a given scheme.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • WHITE

      public static final int WHITE
      Whitespace character class (spaces, tabs, newlines).
      See Also:
    • NON_WORD

      public static final int NON_WORD
      Non-word character class (punctuation and symbols not in other classes).
      See Also:
    • DELIMITER

      public static final int DELIMITER
      Delimiter character class (/,:;|).
      See Also:
    • LOWER

      public static final int LOWER
      Lowercase letter character class.
      See Also:
    • UPPER

      public static final int UPPER
      Uppercase letter character class.
      See Also:
    • LETTER

      public static final int LETTER
      Letter character class (non-cased letters, e.g. CJK ideographs).
      See Also:
    • NUMBER

      public static final int NUMBER
      Numeric digit character class.
      See Also:
  • Method Details

    • init

      public static void init(FuzzyScheme scheme)
      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 character
      curClass - the class of the current character
      Returns:
      the bonus score
    • bonusAt

      public static short bonusAt(int[] input, int idx, FuzzyScheme scheme)
      Calculate the bonus for matching at a given position in the input.
      Parameters:
      input - the input code points
      idx - the position in the input
      scheme - the scoring scheme (for initialCharClass)
      Returns:
      the bonus score