<commit_before>/*
 * Copyright 2011 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.bitbucket.mlopatkin.android.logviewer;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

public class TextHighlightCellRenderer implements DecoratingCellRenderer {

    private TableCellRenderer inner;
    private static final String highlightBackgroundColor = "yellow";
    private static final String highlightTextColor = "red";
    private static final String spanBegin = String.format(
            "<span style='color: %s; background-color: %s'>", highlightTextColor,
            highlightBackgroundColor);
    private static final String spanEnd = "</span>";

    private String textToSearch;

    @Override
    public void setInnerRenderer(TableCellRenderer renderer) {
        inner = renderer;
    }

    private String highlightMatches(String value) {
        StringBuilder result = new StringBuilder(value);
        int pos = result.indexOf(textToSearch);
        while (pos != -1) {
            String val = result.substring(pos, textToSearch.length());
            result.replace(pos, pos + textToSearch.length(), spanBegin + val + spanEnd);
            pos += val.length() + spanBegin.length() + spanEnd.length();
            pos = result.indexOf(textToSearch, pos);
        }
        result.insert(0, "<html>");
        result.append("</html>");
        return result.toString();
    }<commit_msg>IndexOutOfBounds in TextHighlighter<commit_after>/*
 * Copyright 2011 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.bitbucket.mlopatkin.android.logviewer;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

public class TextHighlightCellRenderer implements DecoratingCellRenderer {

    private TableCellRenderer inner;
    private static final String highlightBackgroundColor = "yellow";
    private static final String highlightTextColor = "red";
    private static final String spanBegin = String.format(
            "<span style='color: %s; background-color: %s'>", highlightTextColor,
            highlightBackgroundColor);
    private static final String spanEnd = "</span>";

    private String textToSearch;

    @Override
    public void setInnerRenderer(TableCellRenderer renderer) {
        inner = renderer;
    }

    private String highlightMatches(String value) {
        StringBuilder result = new StringBuilder(value);
        int pos = result.indexOf(textToSearch);
        while (pos != -1 && pos < result.length()) {
            String val = result.substring(pos, pos + textToSearch.length());
            result.replace(pos, pos + textToSearch.length(), spanBegin + val + spanEnd);
            pos += val.length() + spanBegin.length() + spanEnd.length();
            pos = result.indexOf(textToSearch, pos);
        }
        result.insert(0, "<html>");
        result.append("</html>");
        return result.toString();
    }
{'fraction_non_alphanumeric': 0.0961869618696187, 'fraction_numerical': 0.004920049200492005, 'mean_word_length': 3.353319057815846, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3318774', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1023, 'n_words': 359}