<commit_before>// ***********************************************************************
// Copyright (c) 2015 <NAME>
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using NUnit.Options;

namespace NUnit.Common
{
    /// <summary>
    /// CommandLineOptions is the base class the specific option classes
    /// used for nunit3-console and nunitlite. It encapsulates all common
    /// settings and features of both. This is done to ensure that common
    /// features remain common and for the convenience of having the code
    /// in a common location. The class inherits from the Mono
    /// Options OptionSet class and provides a central location
    /// for defining and parsing options.
    /// </summary>
    public class CommandLineOptions : OptionSet
    {
        private static readonly string DEFAULT_WORK_DIRECTORY =
#if NETCF || PORTABLE
            @"\My Documents";
#elif SILVERLIGHT
            Environment.GetFolderPath(Environment.SpecialFolder.Personal);   
#else
            Environment.CurrentDirectory;
#endif

        private bool validated;
#if !PORTABLE
        private bool noresult;
#endif

        #region Constructor

        internal CommandLineOptions(IDefaultOptionsProvider defaultOptionsProvider, params string[] args)
        {
            // Apply default options
            if (defaultOptionsProvider == null) throw new ArgumentNullException("defaultOptionsProvider");

            TeamCity = defaultOptionsProvider.TeamCity;
            
            ConfigureOptions();            
            if (args != null)
                Parse(PreParse(args));
        }

        public CommandLineOptions(params string[] args)
        {
            ConfigureOptions();
            if (args != null)
                Parse(PreParse(args));
        }

#if !PORTABLE
        private int _nesting = 0;
#endif

        internal IEnumerable<string> PreParse(IEnumerable<string> args)
        {
#if PORTABLE
            return args;
#else
            if (++_nesting > 3)
            {
                ErrorMessages.Add("@ nesting exceeds maximum depth of 3");
                --_nesting;
                return args;
            }

            var listArgs = new List<string>();
            var delim = ' ';

            foreach (var arg in args)
            {
                if (arg.Length == 0 || arg[0] != '@')
                {
                    listArgs.Add(arg);
                    continue;
                }

                if (arg.Length == 1)
                {
                    ErrorMessages.Add("The file name should not be empty");
                    continue;
                }

                var offset = 1;
                if (arg.Length > 4 && arg[1] == '[' && arg[3] == ']')
                {
                    delim = arg[2];
                    offset = 4;
                }

                var filename = arg.Substring(offset);

                if (!File.Exists(filename))
                {
                    ErrorMessages.Add("The file \"" + filename + "\" was not found");
                    continue;
                }

                string contents;
                try
                    {
#if NETCF
                    using (var sr = new StreamReader (filename))
                        {
                        contents = sr.ReadToEnd ();
                        }
#else
                    contents = File.ReadAllText (filename);
#endif
                    }
                catch (IOException ex)
                    {
                    ErrorMessages.Add("Error reading \"" + filename + "\": " + ex.Message);
                    continue;
                    }

                var newArgs = GetArgs(contents.Replace("\r", "").Replace('\n', delim));
                    listArgs.AddRange(PreParse(newArgs));
            }

            --_nesting;
            return listArgs;
#endif
            }

#if !PORTABLE
        internal static IEnumerable<string> GetArgs(string commandLine)
        {
            const string re = @"\G(""((""""|[^""])+)""|(\S+)) *";
            var ms = Regex.Matches(commandLine, re);
            return ms.Cast<Match>().Select(m => Regex.Replace(m.Groups[2].Success ? m.Groups[2].Value : m.Groups[4].Value, @"""""", @""""));
        }
#endif

#endregion

#region Properties

        // Action to Perform

        public bool Explore { get; private set; }

        public bool ShowHelp { get; private set; }

        public bool ShowVersion { get; private set; }<commit_msg>Fix formatting<commit_after>// ***********************************************************************
// Copyright (c) 2015 <NAME>
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using NUnit.Options;

namespace NUnit.Common
{
    /// <summary>
    /// CommandLineOptions is the base class the specific option classes
    /// used for nunit3-console and nunitlite. It encapsulates all common
    /// settings and features of both. This is done to ensure that common
    /// features remain common and for the convenience of having the code
    /// in a common location. The class inherits from the Mono
    /// Options OptionSet class and provides a central location
    /// for defining and parsing options.
    /// </summary>
    public class CommandLineOptions : OptionSet
    {
        private static readonly string DEFAULT_WORK_DIRECTORY =
#if NETCF || PORTABLE
            @"\My Documents";
#elif SILVERLIGHT
            Environment.GetFolderPath(Environment.SpecialFolder.Personal);   
#else
            Environment.CurrentDirectory;
#endif

        private bool validated;
#if !PORTABLE
        private bool noresult;
#endif

        #region Constructor

        internal CommandLineOptions(IDefaultOptionsProvider defaultOptionsProvider, params string[] args)
        {
            // Apply default options
            if (defaultOptionsProvider == null) throw new ArgumentNullException("defaultOptionsProvider");

            TeamCity = defaultOptionsProvider.TeamCity;
            
            ConfigureOptions();            
            if (args != null)
                Parse(PreParse(args));
        }

        public CommandLineOptions(params string[] args)
        {
            ConfigureOptions();
            if (args != null)
                Parse(PreParse(args));
        }

#if !PORTABLE
        private int _nesting = 0;
#endif

        internal IEnumerable<string> PreParse(IEnumerable<string> args)
        {
#if PORTABLE
            return args;
#else
            if (++_nesting > 3)
            {
                ErrorMessages.Add("@ nesting exceeds maximum depth of 3");
                --_nesting;
                return args;
            }

            var listArgs = new List<string>();
            var delim = ' ';

            foreach (var arg in args)
            {
                if (arg.Length == 0 || arg[0] != '@')
                {
                    listArgs.Add(arg);
                    continue;
                }

                if (arg.Length == 1)
                {
                    ErrorMessages.Add("The file name should not be empty");
                    continue;
                }

                var offset = 1;
                if (arg.Length > 4 && arg[1] == '[' && arg[3] == ']')
                {
                    delim = arg[2];
                    offset = 4;
                }

                var filename = arg.Substring(offset);

                if (!File.Exists(filename))
                {
                    ErrorMessages.Add("The file \"" + filename + "\" was not found");
                    continue;
                }

                string contents;
                try
                    {
#if NETCF
                    using (var sr = new StreamReader (filename))
                        {
                        contents = sr.ReadToEnd ();
                        }
#else
                    contents = File.ReadAllText (filename);
#endif
                    }
                catch (IOException ex)
                    {
                    ErrorMessages.Add("Error reading \"" + filename + "\": " + ex.Message);
                    continue;
                    }

                var newArgs = GetArgs(contents.Replace("\r", "").Replace('\n', delim));
                listArgs.AddRange(PreParse(newArgs));
            }

            --_nesting;
            return listArgs;
#endif
            }

#if !PORTABLE
        internal static IEnumerable<string> GetArgs(string commandLine)
        {
            const string re = @"\G(""((""""|[^""])+)""|(\S+)) *";
            var ms = Regex.Matches(commandLine, re);
            return ms.Cast<Match>().Select(m => Regex.Replace(m.Groups[2].Success ? m.Groups[2].Value : m.Groups[4].Value, @"""""", @""""));
        }
#endif

#endregion

#region Properties

        // Action to Perform

        public bool Explore { get; private set; }

        public bool ShowHelp { get; private set; }

        public bool ShowVersion { get; private set; }
{'fraction_non_alphanumeric': 0.11949189662724485, 'fraction_numerical': 0.003504161191414805, 'mean_word_length': 1.7668444013572466, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 25, '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': '7385584', 'n_tokens_mistral': 2873, 'n_tokens_neox': 2641, 'n_words': 943}