<commit_before>package com.github.nstdio.libpgn.core.parser;

import com.github.nstdio.libpgn.core.Configuration;
import com.github.nstdio.libpgn.core.exception.PgnException;
import com.github.nstdio.libpgn.entity.Result;

import javax.annotation.Nullable;

import static com.github.nstdio.libpgn.core.TokenTypes.GAMETERM;

class ResultParser extends AbstractParser implements Parser<Result> {

    ResultParser(PgnLexer lexer, Configuration config) {
        super(lexer, config);
    }

    @Override
    public Result parse() {
        lastNotEqThrow(GAMETERM);
        String result = read();

        for (Result res : Result.values()) {
            if (result.equals(res.getTerm())) {
                return res;
            }
        }

        throw new PgnException("Bad game termination.");
    }

    @Nullable
    @Override
    public Result tryParse() {
        return null;
    }
}
<commit_msg>Replace String reading with byte array in ResultParser.<commit_after>package com.github.nstdio.libpgn.core.parser;

import static com.github.nstdio.libpgn.core.TokenTypes.GAMETERM;

import javax.annotation.Nullable;

import com.github.nstdio.libpgn.core.Configuration;
import com.github.nstdio.libpgn.core.exception.PgnException;
import com.github.nstdio.libpgn.entity.Result;

class ResultParser extends AbstractParser implements Parser<Result> {

    ResultParser(PgnLexer lexer, Configuration config) {
        super(lexer, config);
    }

    @Override
    public Result parse() {
        lastNotEqThrow(GAMETERM);

        // TODO: Skip reading and use token length.
        byte[] resultBytes = readBytes();

        switch (resultBytes.length) {
            case 1:
                return Result.UNKNOWN;
            case 7:
                return Result.DRAW;
            case 3:
                return resultBytes[0] == 49 ? Result.WHITE : Result.BLACK;
            default:
                throw new PgnException("Bad game termination: " + new String(resultBytes));
        }
    }

    @Nullable
    @Override
    public Result tryParse() {
        return null;
    }
}

{'fraction_non_alphanumeric': 0.09717568214456677, 'fraction_numerical': 0.0028721876495931067, 'mean_word_length': 2.5483870967741935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5565193', 'n_tokens_mistral': 627, 'n_tokens_neox': 599, 'n_words': 132}