<commit_before>package greed.code.transform;

import greed.code.CodeByLine;
import greed.code.CodeTransformer;

import java.util.ArrayList;

/**
 * @author WuCY
 */
public class BlockCleaner implements CodeTransformer {

    private String startTag;
    private String endTag;

    public BlockCleaner(String startTag, String endTag) {
        this.startTag = startTag;
        this.endTag = endTag;
    }


    @Override
    public CodeByLine transform(CodeByLine input) {
        CodeByLine res = new CodeByLine();

        ArrayList<String> buffer = new ArrayList<String>();
        int totalLen = 0;
        boolean inBlock = false;
        for (String line: input.getLines()) {
            if (line.trim().equals(startTag)) {
                inBlock = true;
            }
            else if (line.trim().equals(endTag)) {
                if (totalLen > 0)
                    res.getLines().addAll(buffer);
                inBlock = false;
                buffer.clear();
                totalLen = 0;
            }
            else {
                if (inBlock) {
                    buffer.add(line);
                    totalLen += line.trim().length();
                }
                else
                    res.getLines().add(line);
            }
        }<commit_msg>[bug fix] BlockCleaner cleans the tags as well<commit_after>package greed.code.transform;

import greed.code.CodeByLine;
import greed.code.CodeTransformer;

import java.util.ArrayList;

/**
 * @author WuCY
 */
public class BlockCleaner implements CodeTransformer {

    private String startTag;
    private String endTag;

    public BlockCleaner(String startTag, String endTag) {
        this.startTag = startTag;
        this.endTag = endTag;
    }


    @Override
    public CodeByLine transform(CodeByLine input) {
        CodeByLine res = new CodeByLine();

        ArrayList<String> buffer = new ArrayList<String>();
        int totalLen = 0;
        boolean inBlock = false;
        for (String line: input.getLines()) {
            if (line.trim().equals(startTag)) {
                inBlock = true;
                buffer.add(line);
            }
            else if (line.trim().equals(endTag)) {
                buffer.add(line);
                if (totalLen > 0)
                    res.getLines().addAll(buffer);
                inBlock = false;
                buffer.clear();
                totalLen = 0;
            }
            else {
                if (inBlock) {
                    buffer.add(line);
                    totalLen += line.trim().length();
                }
                else
                    res.getLines().add(line);
            }
        }
{'fraction_non_alphanumeric': 0.10116148370176097, 'fraction_numerical': 0.0022480329711502436, 'mean_word_length': 1.5236294896030245, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5826380', 'n_tokens_mistral': 729, 'n_tokens_neox': 683, 'n_words': 163}