int match(byte[] text, int textLen, byte[][] escapeSequences) {
        int i, j;
        int escN;
        int hits = 0;
        int misses = 0;
        int shifts = 0;
        int quality;
        scanInput:
        for (i = 0; i < textLen; i++) {
            if (text[i] == 0x1b) {
                checkEscapes:
                for (escN = 0; escN < escapeSequences.length; escN++) {
                    byte[] seq = escapeSequences[escN];

                    if ((textLen - i) < seq.length) {
                        continue checkEscapes;
                    }

                    for (j = 1; j < seq.length; j++) {
                        if (seq[j] != text[i + j]) {
                            continue checkEscapes;
                        }
                    }

                    hits++;
                    i += seq.length - 1;
                    continue scanInput;
                }

                misses++;
            }

            if (text[i] == 0x0e || text[i] == 0x0f) {
                // Shift in/out
                shifts++;
            }
        }

        if (hits == 0) {
            return 0;
        }

        //
        // Initial quality is based on relative proportion of recongized vs.
        //   unrecognized escape sequences.
        //   All good:  quality = 100;
        //   half or less good: quality = 0;
        //   linear inbetween.
        quality = (100 * hits - 100 * misses) / (hits + misses);

        // Back off quality if there were too few escape sequences seen.
        //   Include shifts in this computation, so that KR does not get penalized
        //   for having only a single Escape sequence, but many shifts.
        if (hits + shifts < 5) {
            quality -= (5 - (hits + shifts)) * 10;
        }

        if (quality < 0) {
            quality = 0;
        }
        return quality;
    }
Matching function shared among the 2022 detectors JP, CN and KR
Counts up the number of legal an unrecognized escape sequences in
the sample of text, and computes a score based on the total number &
the proportion that fit the encoding.

@param text            the byte buffer containing text to analyse
@param textLen         the size of the text in the byte.
@param escapeSequences the byte escape sequences to test for.
@return match quality, in the range of 0-100.
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-text-module/src/main/java/org/apache/tika/parser/txt/CharsetRecog_2022.java