<commit_before>﻿#if !NETSTANDARD14
using System;
using System.Collections.Generic;
using System.Linq;

namespace Config.Net.Stores.Impl.CommandLine
{
   class CommandLineConfigStore : IConfigStore
   {
      private readonly Dictionary<string, string> _nameToValue;
      private static readonly char[] ArgPrefixes = new[] { '-', '/' };
      private static readonly string[] ArgDelimiters = new[] { ":", "=" };
      private readonly bool _isCaseSensitive;

      public bool CanRead => true;

      public bool CanWrite => false;

      public CommandLineConfigStore(string[] args = null, bool isCaseSensitive = false, IEnumerable<KeyValuePair<string, int>> nameToPosition = null)
      {
         _isCaseSensitive = isCaseSensitive;

         _nameToValue = new Dictionary<string, string>(_isCaseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase);

         Parse(args ?? Environment.GetCommandLineArgs(), nameToPosition);
      }

      public void Dispose()
      {
      }

      public string Read(string key)
      {
         if (key == null) return null;

         string value;
         _nameToValue.TryGetValue(key, out value);
         return value;
      }

      public void Write(string key, string value)
      {
         throw new NotSupportedException();
      }

      private void Parse(string[] args, IEnumerable<KeyValuePair<string, int>> nameToPosition)
      {
         _nameToValue.Clear();

         var posToName = new Dictionary<int, string>();
         if (nameToPosition != null)
         {
            foreach(var p in nameToPosition)
            {
               if (p.Key != null)
               {
                  posToName[p.Value] = p.Key;
               }
            }
         }

         if (args == null) return;

         for (int i = 0; i < args.Length; i++)
         {
            string name;
            string value;

            var nameValue = Utils.SplitByDelimiter(args[i], ArgDelimiters);
            name = nameValue.Item1.TrimStart(ArgPrefixes);
            value = nameValue.Item2;

            if (name != null && value != null)
            {
               _nameToValue[name] = value;
            }
            else if(name != null && posToName.TryGetValue(i, out string ptnName))
            {
               _nameToValue[ptnName] = name;<commit_msg>add some tracing<commit_after>﻿#if !NETSTANDARD14
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace Config.Net.Stores.Impl.CommandLine
{
   class CommandLineConfigStore : IConfigStore
   {
      private readonly Dictionary<string, string> _nameToValue;
      private static readonly char[] ArgPrefixes = new[] { '-', '/' };
      private static readonly string[] ArgDelimiters = new[] { ":", "=" };
      private readonly bool _isCaseSensitive;

      public bool CanRead => true;

      public bool CanWrite => false;

      public CommandLineConfigStore(string[] args = null, bool isCaseSensitive = false, IEnumerable<KeyValuePair<string, int>> nameToPosition = null)
      {
         _isCaseSensitive = isCaseSensitive;

         _nameToValue = new Dictionary<string, string>(_isCaseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase);

         Parse(args ?? Environment.GetCommandLineArgs(), nameToPosition);
      }

      public void Dispose()
      {
      }

      public string Read(string key)
      {
         if (key == null) return null;

         string value;
         _nameToValue.TryGetValue(key, out value);
         return value;
      }

      public void Write(string key, string value)
      {
         throw new NotSupportedException();
      }

      private void Parse(string[] args, IEnumerable<KeyValuePair<string, int>> nameToPosition)
      {
         _nameToValue.Clear();

         var posToName = new Dictionary<int, string>();
         if (nameToPosition != null)
         {
            foreach(KeyValuePair<string, int> p in nameToPosition)
            {
               if (p.Key != null)
               {
                  posToName[p.Value] = p.Key;
               }
            }
         }

         if (args == null) return;

         for (int i = 0; i < args.Length; i++)
         {
            string name;
            string value;

            Debug.WriteLine($"arg {i}: {args[i]}");

            Tuple<string, string> nameValue = Utils.SplitByDelimiter(args[i], ArgDelimiters);
            name = nameValue.Item1.TrimStart(ArgPrefixes);
            value = nameValue.Item2;

            Debug.WriteLine($"name: {name}, value: {value}");

            if (name != null && value != null)
            {
               _nameToValue[name] = value;
            }
            else if(name != null && posToName.TryGetValue(i, out string ptnName))
            {
               Debug.WriteLine($"assigned {name} to pos {ptnName}");
               _nameToValue[ptnName] = name;
{'fraction_non_alphanumeric': 0.10484527687296417, 'fraction_numerical': 0.002035830618892508, 'mean_word_length': 2.0515527950310557, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 23, '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': '5831228', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1331, 'n_words': 329}