<commit_before>﻿using System;
using System.IO;
using System.Text;

namespace mze9412.ScriptCompiler.Helpers
{
    public static class ClipCopy
    {
        //[STAThread]
        //static void Main(string[] aargh)
        //{
        //    if (!aargh.Any())
        //    {
        //        Console.WriteLine("missing argument");
        //        return;
        //    }

        //    var result = new StringBuilder();

        //    Includefile(result, new FileInfo(aargh[0]).FullName, false, first: true);

        //    Clipboard.SetText(result.ToString());
        //}


        /// <summary>
        /// Adds the files content to the given StringBuilder 
        /// </summary>
        /// <param name="addToMe">the StringBuilder to add to</param>
        /// <param name="filename">the file to include</param>
        /// <param name="makeCompact">removes all whitespaces from the file</param>
        /// <param name="linetheshold">requires makeCompact:a newline will be added after added lines exceed this many characters; -1 for off</param>
        /// <param name="first">if starting with an empty StringBuilder this has to be true</param>
        public static void Includefile(StringBuilder addToMe, string filename, bool makeCompact, int linetheshold = -1, bool first = false)
        {

            try
            {
                var addMe = new StringBuilder();
                if (!first) addMe.Append(makeCompact ? "}" : "\n}\n");

                using (var readMe = new StreamReader(filename))
                {
                    string line;
                    var started = false;
                    var stop = false;
                    var currlinelength = 0;
                    var tresholdLength = linetheshold;
                    bool linecommentErrorShown = false;
                    while ((line = readMe.ReadLine()) != null && !stop)
                    {
                        if (!started)
                        {
                            if (line.Contains("/**Begin copy here**"))
                            {
                                started = true;
                            }
                        }
                        else
                        {
                            if (line.Contains("/**End copy here**"))
                            {
                                stop = true;
                            }
                            else if (line.Trim().StartsWith("///"))
                            {
                                continue;
                            }
                            else
                            {
                                if (line.Trim().StartsWith("//#include"))
                                {
                                    var incl =
                                        line.Trim()
                                            .Substring(line.Trim().IndexOf('(') + 1, line.Trim().IndexOf(')') - line.Trim().IndexOf('(') - 1)
                                            .Split(new[] {','});

                                    try
                                    {
                                        Includefile(addMe, new FileInfo(filename).Directory.FullName + "\\" + incl[0], bool.Parse(incl[1]));
                                    }
                                    catch (Exception x)
                                    {
                                        Console.WriteLine("Inner NOPE:\n" + incl[0] + "\n" + incl[1] + "\n" + x);
                                    }<commit_msg>Remove unused line and small cleanup<commit_after>﻿using System;
using System.IO;
using System.Text;

namespace mze9412.ScriptCompiler.Helpers
{
    public static class ClipCopy
    {
        //[STAThread]
        //static void Main(string[] aargh)
        //{
        //    if (!aargh.Any())
        //    {
        //        Console.WriteLine("missing argument");
        //        return;
        //    }

        //    var result = new StringBuilder();

        //    Includefile(result, new FileInfo(aargh[0]).FullName, false, first: true);

        //    Clipboard.SetText(result.ToString());
        //}


        /// <summary>
        /// Adds the files content to the given StringBuilder 
        /// </summary>
        /// <param name="addToMe">the StringBuilder to add to</param>
        /// <param name="filename">the file to include</param>
        /// <param name="makeCompact">removes all whitespaces from the file</param>
        /// <param name="linetheshold">requires makeCompact:a newline will be added after added lines exceed this many characters; -1 for off</param>
        /// <param name="first">if starting with an empty StringBuilder this has to be true</param>
        public static void Includefile(StringBuilder addToMe, string filename, bool makeCompact, int linetheshold = -1, bool first = false)
        {
            try
            {
                var addMe = new StringBuilder();
                if (!first) addMe.Append(makeCompact ? "}" : "\n}\n");

                using (var readMe = new StreamReader(filename))
                {
                    string line;
                    var started = false;
                    var stop = false;
                    var currlinelength = 0;
                    var tresholdLength = linetheshold;
                    bool linecommentErrorShown = false;
                    while ((line = readMe.ReadLine()) != null && !stop)
                    {
                        if (!started)
                        {
                            if (line.Contains("/**Begin copy here**"))
                            {
                                started = true;
                            }
                        }
                        else
                        {
                            if (line.Contains("/**End copy here**"))
                            {
                                stop = true;
                            }
                            else if (line.Trim().StartsWith("///"))
                            {
                                continue;
                            }
                            else
                            {
                                if (line.Trim().StartsWith("//#include"))
                                {
                                    var incl =
                                        line.Trim()
                                            .Substring(line.Trim().IndexOf('(') + 1, line.Trim().IndexOf(')') - line.Trim().IndexOf('(') - 1)
                                            .Split(',');

                                    try
                                    {
                                        Includefile(addMe, new FileInfo(filename).Directory.FullName + "\\" + incl[0], bool.Parse(incl[1]));
                                    }
                                    catch (Exception x)
                                    {
                                        Console.WriteLine("Inner NOPE:\n" + incl[0] + "\n" + incl[1] + "\n" + x);
                                    }
{'fraction_non_alphanumeric': 0.10799438990182328, 'fraction_numerical': 0.003927068723702665, 'mean_word_length': 0.8915119363395225, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '503126', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1549, 'n_words': 381}