<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace RowJoin.Views
{
    public partial class MainView : Form
    {
        public MainView()
        {
            InitializeComponent();
            CbxTemplate.SelectedIndex = 1;
        }

        private string Join()
        {
            StringBuilder result = new StringBuilder();
            result.Append(TxtHeader.Text);
            string[] lines = TxtInput.Text.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i<lines.Length; i++)
            {
                lines[i] = $"{TxtBefore.Text}{lines[i]}{TxtAfter.Text}";
            }
            result.Append(string.Join(TxtBetween.Text, lines));
            result.Append(TxtFooter.Text);
            return result.ToString();
        }

        private void TxtHeader_TextChanged(object sender, EventArgs e)
        {
            TxtOutput.Text = Join();
        }

        private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var templates = new List<JoinTemplate>();
            templates.Add(new JoinTemplate(0, "select * from $TABLE where ", "$COLUMN like '%", " or ", "%'", ""));
            templates.Add(new JoinTemplate(1, "(", "'", "', '", "'", ")"));
            var cbx = (ComboBoxEdit) sender;
            var template = templates.ElementAt(cbx.SelectedIndex);
            TxtHeader.Text = template.Header;
            TxtBefore.Text = template.BeforeEach;
            TxtBetween.Text = template.BetweenEach;
            TxtAfter.Text = template.AfterEach;
            TxtFooter.Text = template.Footer;
            Join();
        }
    }

    public class JoinTemplate
    {
        public JoinTemplate(int index, string header, string beforeEach, string betweenEach, string afterEach, string footer)
        {
            Index = index;
            Header = header;
            BeforeEach = beforeEach;
            BetweenEach = betweenEach;
            AfterEach = afterEach;
            Footer = footer;
        }<commit_msg>fix: avoid multiple redundant joins when selecting a Template<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace RowJoin.Views
{
    public partial class MainView : Form
    {
        public MainView()
        {
            InitializeComponent();
            CbxTemplate.SelectedIndex = 1;
        }

        private string Join()
        {
            StringBuilder result = new StringBuilder();
            result.Append(TxtHeader.Text);
            string[] lines = TxtInput.Text.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i<lines.Length; i++)
            {
                lines[i] = $"{TxtBefore.Text}{lines[i]}{TxtAfter.Text}";
            }
            result.Append(string.Join(TxtBetween.Text, lines));
            result.Append(TxtFooter.Text);
            return result.ToString();
        }

        private void TxtHeader_TextChanged(object sender, EventArgs e)
        {
            if(AutoJoin)
                TxtOutput.Text = Join();
        }

        private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var templates = new List<JoinTemplate>();
            templates.Add(new JoinTemplate(0, "select * from $TABLE where ", "$COLUMN like '%", " or ", "%'", ""));
            templates.Add(new JoinTemplate(1, "(", "'", "', '", "'", ")"));
            var cbx = (ComboBoxEdit) sender;
            var template = templates.ElementAt(cbx.SelectedIndex);
            AutoJoin = false;
            TxtHeader.Text = template.Header;
            TxtBefore.Text = template.BeforeEach;
            TxtBetween.Text = template.BetweenEach;
            TxtAfter.Text = template.AfterEach;
            TxtFooter.Text = template.Footer;
            AutoJoin = true;
            Join();
        }

        public bool AutoJoin { get; private set; }
    }

    public class JoinTemplate
    {
        public JoinTemplate(int index, string header, string beforeEach, string betweenEach, string afterEach, string footer)
        {
            Index = index;
            Header = header;
            BeforeEach = beforeEach;
            BetweenEach = betweenEach;
            AfterEach = afterEach;
            Footer = footer;
        }
{'fraction_non_alphanumeric': 0.1115077698446031, 'fraction_numerical': 0.0020999580008399833, 'mean_word_length': 2.055163566388711, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5143016', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1260, 'n_words': 293}