<commit_before>package com.civilizer.domain;

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

import com.civilizer.utils.Pair;

public final class TextDecorator {
	
	public static final String PREFIX_FOR_HIGHLIGHT = "%28%7B%28%5Bsh%5D%20";
	public static final String POSTFIX_FOR_HIGHLIGHT = "%20%29%7D%29";
	
	private static final RangeComparator rangeComparator = new RangeComparator();
	
	private static class RangeComparator implements Comparator<Pair<Integer, Integer>> {
		@Override
        public int compare(Pair<Integer, Integer> arg0, Pair<Integer, Integer> arg1) {
            int d = arg0.getFirst() - arg1.getFirst();
            if (d == 0) {
            	// in case that the two ranges overlap
            	// the bigger range will have higher priority
            	d = arg1.getSecond() - arg0.getSecond();
            }
            return d;
        }
	}
	
	private static String escapeRegexMetaCharacters(String input) {
		return "\\Q" + input + "\\E";
	}
	
	private static void match(List<Pair<Integer, Integer>> output, String input, SearchParams sp, boolean caseSensitive) {
	    String regex = "";
		for (SearchParams.Keywords keywords : sp.getKeywords()) {
		    if (keywords.getTarget() == SearchParams.TARGET_TAG
		            || keywords.getTarget() == SearchParams.TARGET_ID
		            )
		        continue;
		    for (SearchParams.Keyword kw : keywords.getWords()) {
		        String w = kw.getWord();
		        if (kw.isId() || kw.isInverse()) {
		            continue;
		        }
		        if (!caseSensitive && ! kw.isCaseSensitive())
	                w = w.toLowerCase();
		        w = escapeRegexMetaCharacters(w);
		        if (kw.isWholeWord())
		            w = "\\b" + w + "\\b";
		        else if (kw.isBeginningWith())
		            w = "\\b" + w;
		        else if (kw.isEndingWith())
		            w = w + "\\b";
		        if (!regex.isEmpty())
		            regex += "|";
		        regex += "("+ w + ")";
		    }
		}		
		if (regex.isEmpty())<commit_msg>[bug fix] search phrase highlighting for regular expression was disabled<commit_after>package com.civilizer.domain;

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

import com.civilizer.utils.Pair;

public final class TextDecorator {
	
	public static final String PREFIX_FOR_HIGHLIGHT = "%28%7B%28%5Bsh%5D%20";
	public static final String POSTFIX_FOR_HIGHLIGHT = "%20%29%7D%29";
	
	private static final RangeComparator rangeComparator = new RangeComparator();
	
	private static class RangeComparator implements Comparator<Pair<Integer, Integer>> {
		@Override
        public int compare(Pair<Integer, Integer> arg0, Pair<Integer, Integer> arg1) {
            int d = arg0.getFirst() - arg1.getFirst();
            if (d == 0) {
            	// in case that the two ranges overlap
            	// the bigger range will have higher priority
            	d = arg1.getSecond() - arg0.getSecond();
            }
            return d;
        }
	}
	
	private static String escapeRegexMetaCharacters(String input) {
		return "\\Q" + input + "\\E";
	}
	
	private static void match(List<Pair<Integer, Integer>> output, String input, SearchParams sp, boolean caseSensitive) {
	    String regex = "";
		for (SearchParams.Keywords keywords : sp.getKeywords()) {
		    if (keywords.getTarget() == SearchParams.TARGET_TAG
		            || keywords.getTarget() == SearchParams.TARGET_ID
		            )
		        continue;
		    for (SearchParams.Keyword kw : keywords.getWords()) {
		        String w = kw.getWord();
		        if (kw.isId() || kw.isInverse()) {
		            continue;
		        }
		        if (!caseSensitive && ! kw.isCaseSensitive())
	                w = w.toLowerCase();
		        if (!kw.isRegex())
		            w = escapeRegexMetaCharacters(w);
		        if (kw.isWholeWord())
		            w = "\\b" + w + "\\b";
		        else if (kw.isBeginningWith())
		            w = "\\b" + w;
		        else if (kw.isEndingWith())
		            w = w + "\\b";
		        if (!regex.isEmpty())
		            regex += "|";
		        regex += "("+ w + ")";
		    }
		}		
		if (regex.isEmpty())
{'fraction_non_alphanumeric': 0.12830370014416145, 'fraction_numerical': 0.011052378664103796, 'mean_word_length': 2.175438596491228, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '3014459', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1195, 'n_words': 312}