<commit_before>﻿using EditorConfig.Core;
using System.Collections.Generic;
using System.Linq;

namespace Elders.VSE_FormatDocumentOnSave.Configurations
{
    public sealed class EditorConfigConfiguration : IConfiguration
    {
        private readonly bool enable = true;
        private readonly string allowed = ".*";
        private readonly string denied = "";
        private readonly string command = "Edit.FormatDocument";
        private readonly bool enableInDebug = false;

        public EditorConfigConfiguration(string formatConfigFile)
        {
            var parser = new EditorConfig.Core.EditorConfigParser(formatConfigFile);
            FileConfiguration configFile = parser.Parse(formatConfigFile).First();

            if (configFile.Properties.ContainsKey("enable"))
            {
                configFile.Properties.TryGetValue("enable", out string enableAsString);
                bool.TryParse(enableAsString, out enable);
            }

            if (configFile.Properties.ContainsKey("allowed_extensions"))
                configFile.Properties.TryGetValue("allowed_extensions", out allowed);

            if (configFile.Properties.ContainsKey("denied_extensions"))
                configFile.Properties.TryGetValue("denied_extensions", out denied);

            if (configFile.Properties.ContainsKey("command"))
                configFile.Properties.TryGetValue("command", out command);

            if (configFile.Properties.ContainsKey("enable_in_debug"))
            {
                configFile.Properties.TryGetValue("enable_in_debug", out string enableInDebugAsString);
                bool.TryParse(enableInDebugAsString, out enableInDebug);
            }
        }

        public bool IsEnable => enable;

        IEnumerable<string> IConfiguration.Allowed => allowed.Split(' ');

        IEnumerable<string> IConfiguration.Denied => denied.Split(' ');

        public string Commands => command;

        public bool EnableInDebug => enableInDebug;
    }
}<commit_msg>fix potential error when parsing, if value is not recognized, keep the current value<commit_after>﻿using EditorConfig.Core;
using System.Collections.Generic;
using System.Linq;

namespace Elders.VSE_FormatDocumentOnSave.Configurations
{
    public sealed class EditorConfigConfiguration : IConfiguration
    {
        private readonly bool enable = true;
        private readonly string allowed = ".*";
        private readonly string denied = "";
        private readonly string command = "Edit.FormatDocument";
        private readonly bool enableInDebug = false;

        public EditorConfigConfiguration(string formatConfigFile)
        {
            var parser = new EditorConfigParser(formatConfigFile);
            FileConfiguration configFile = parser.Parse(formatConfigFile).First();

            if (configFile.Properties.TryGetValue("enable", out string enableAsString) && bool.TryParse(enableAsString, out bool enableParsed))
                enable = enableParsed;

            if (configFile.Properties.ContainsKey("allowed_extensions"))
                configFile.Properties.TryGetValue("allowed_extensions", out allowed);

            if (configFile.Properties.ContainsKey("denied_extensions"))
                configFile.Properties.TryGetValue("denied_extensions", out denied);

            if (configFile.Properties.ContainsKey("command"))
                configFile.Properties.TryGetValue("command", out command);

            if (configFile.Properties.TryGetValue("enable_in_debug", out string enableInDebugAsString) && bool.TryParse(enableInDebugAsString, out bool enableInDebugParsed))
                enableInDebug = enableInDebugParsed;
        }

        public bool IsEnable => enable;

        IEnumerable<string> IConfiguration.Allowed => allowed.Split(' ');

        IEnumerable<string> IConfiguration.Denied => denied.Split(' ');

        public string Commands => command;

        public bool EnableInDebug => enableInDebug;
    }
}
{'fraction_non_alphanumeric': 0.08756919979869149, 'fraction_numerical': 0.0, 'mean_word_length': 2.9829659318637276, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '422072', 'n_tokens_mistral': 946, 'n_tokens_neox': 913, 'n_words': 211}