<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace Pequot
{
    [XmlRoot("settings")]
    public class SerializableSettings
        : Dictionary<string, string>, IXmlSerializable
    {
        

        #region IXmlSerializable Members
        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            bool wasEmpty = reader.IsEmptyElement;
            reader.Read();

            if (wasEmpty)
                return;

            while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                string key = XmlConvert.DecodeName(reader.Name);
                string value = reader.ReadString();

                this.Add(key, value);

                reader.Read();
            }
            reader.ReadEndElement();
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            foreach (String key in this.Keys)
            {
                writer.WriteStartElement(XmlConvert.EncodeName(key));
                writer.WriteString(this[key]);
                writer.WriteEndElement();
            }
        }
        #endregion
    }
}<commit_msg>Make saved settings more readable<commit_after>﻿using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;

namespace Pequot
{
    [XmlRoot("settings")]
    public class SerializableSettings
        : Dictionary<string, string>, IXmlSerializable
    {
        

        #region IXmlSerializable Members
        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(XmlReader reader)
        {
            bool wasEmpty = reader.IsEmptyElement;
            reader.Read();

            if (wasEmpty)
                return;

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                // Convert from human-readable element names (see below)
                string key = XmlConvert.DecodeName(reader.Name.Replace("___", "_x0020_").Replace("__x005F__", "___"));
                string value = reader.ReadString();

                if(key!=null)
                {
                    if(ContainsKey(key))
                        // update if already exists
                        this[key] = value;
                    else
                        Add(key, value);
                }

                reader.Read();
            }
            reader.ReadEndElement();
        }

        public void WriteXml(XmlWriter writer)
        {
            foreach (String key in Keys)
            {
                // Convert to human-readable element names by substituting three underscores for an encoded space (2nd Replace)
                // and making sure existing triple-underscores will not cause confusion by substituting with partial encoding
                string encoded = XmlConvert.EncodeName(key);
                if (encoded == null) continue;
                writer.WriteStartElement(encoded.Replace("___", "__x005F__").Replace("_x0020_", "___"));
                writer.WriteString(this[key]);
                writer.WriteEndElement();
            }
        }
        #endregion
    }
}
{'fraction_non_alphanumeric': 0.08804283164782867, 'fraction_numerical': 0.00446162998215348, 'mean_word_length': 1.5809669992325404, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4014621', 'n_tokens_mistral': 858, 'n_tokens_neox': 794, 'n_words': 186}