<commit_before>package com.eqot.fontawesome;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FontAwesome {
    private static final String FONT_FILENAME = "fontawesome-webfont.ttf";

    private static Typeface sTypeface = null;
    private static final Pattern pattern = Pattern.compile("([^\\{]*)\\{([\\w\\-]+)\\}(.*)");

    public static void apply(Context context, View view) {
        if (sTypeface == null) {
            sTypeface = Typeface.createFromAsset(context.getAssets(), FONT_FILENAME);
        }

        if (!(view instanceof TextView)) {
            return;
        }

        final TextView textView = (TextView) view;
        textView.setAllCaps(false);
        String text = (String) textView.getText();

        final SpannableStringBuilder sb = new SpannableStringBuilder();
        while (true) {
            final Matcher matcher = pattern.matcher(text);
            if (!matcher.find()) {
                sb.append(text);
                break;
            }

            sb.append(matcher.group(1));

            final String character = getCharacterFromCode(context, matcher.group(2));
            final CustomTypefaceSpan typefaceSpan = new CustomTypefaceSpan("", sTypeface);
            sb.append(character, typefaceSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

            text = matcher.group(3);
        }

        textView.setText(sb);
    }

    private static String getCharacterFromCode(Context context, String code) {
        code = code.replace("-", "_");<commit_msg>Fix crash to repeatedly apply<commit_after>package com.eqot.fontawesome;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FontAwesome {
    private static final String FONT_FILENAME = "fontawesome-webfont.ttf";

    private static Typeface sTypeface = null;
    private static final Pattern pattern = Pattern.compile("([^\\{]*)\\{([\\w\\-]+)\\}(.*)");

    public static void apply(Context context, View view) {
        if (sTypeface == null) {
            sTypeface = Typeface.createFromAsset(context.getAssets(), FONT_FILENAME);
        }

        if (!(view instanceof TextView)) {
            return;
        }

        final TextView textView = (TextView) view;
        textView.setAllCaps(false);
        CharSequence text = textView.getText();

        final SpannableStringBuilder sb = new SpannableStringBuilder();
        while (true) {
            final Matcher matcher = pattern.matcher(text);
            if (!matcher.find()) {
                sb.append(text);
                break;
            }

            sb.append(matcher.group(1));

            final String character = getCharacterFromCode(context, matcher.group(2));
            final CustomTypefaceSpan typefaceSpan = new CustomTypefaceSpan("", sTypeface);
            sb.append(character, typefaceSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

            text = matcher.group(3);
        }

        textView.setText(sb);
    }

    private static String getCharacterFromCode(Context context, String code) {
        code = code.replace("-", "_");
{'fraction_non_alphanumeric': 0.11332062108417325, 'fraction_numerical': 0.0016344320348678834, 'mean_word_length': 2.793388429752066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '256720', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1006, 'n_words': 231}