<commit_before>﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DomainPublicSuffix
{
    /// <summary>
    /// Meta information class for an individual TLD rule
    /// </summary>
    public class TLDRule : IComparable<TLDRule>
    {
        /// <summary>
        /// The rule name
        /// </summary>
        public string Name
        {
            get;
            private set;
        }

        /// <summary>
        /// The rule type
        /// </summary>
        public RuleType Type
        {
            get;
            private set;
        }

        /// <summary>
        /// Construct a TLDRule based on a single line from
        /// the www.publicsuffix.org list
        /// </summary>
        /// <param name="RuleInfo"></param>
        public TLDRule(string RuleInfo)
        {
            //TODO: Publicsuffix.org spec says a wildcard can be contained at any level not
            // just the left-most. As of May 2015 there are no examples of such a rule but
            // we may need to come up with a more complex matching algorithm in future.

            //  Parse the rule and set properties accordingly:
            if (RuleInfo.StartsWith("*", StringComparison.InvariantCultureIgnoreCase))
            {
                this.Type = RuleType.Wildcard;
                this.Name = RuleInfo.Substring(2);
            }
            else if (RuleInfo.StartsWith("!", StringComparison.InvariantCultureIgnoreCase))
            {
                this.Type = RuleType.Exception;
                this.Name = RuleInfo.Substring(1,RuleInfo.IndexOf('.')-1);
            }
            else
            {
                this.Type = RuleType.Normal;
                this.Name = RuleInfo;
            }
        }

        #region IComparable<TLDRule> Members

        public int CompareTo(TLDRule other)
        {
            if (other == null)
                return -1;

            return Name.CompareTo(other.Name);
        }

        #endregion

        #region RuleType enum
        
        /// <summary>
        /// TLD Rule type
        /// </summary>
        public enum RuleType
        {
            /// <summary>
            /// A normal rule
            /// </summary>
            Normal,

            /// <summary>
            /// A wildcard rule, as defined by www.publicsuffix.org
            /// </summary>
            Wildcard,

            /// <summary>
            /// An exception rule, as defined by www.publicsuffix.org
            /// </summary>
            Exception
        } 

        #endregion
    }
}<commit_msg>Handle Exception rules properly<commit_after>﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DomainPublicSuffix
{
    /// <summary>
    /// Meta information class for an individual TLD rule
    /// </summary>
    public class TLDRule : IComparable<TLDRule>
    {
        /// <summary>
        /// The rule name
        /// </summary>
        public string Name
        {
            get;
            private set;
        }

        /// <summary>
        /// The rule type
        /// </summary>
        public RuleType Type
        {
            get;
            private set;
        }

        /// <summary>
        /// Construct a TLDRule based on a single line from
        /// the www.publicsuffix.org list
        /// </summary>
        /// <param name="RuleInfo"></param>
        public TLDRule(string RuleInfo)
        {
            // Publicsuffix.org spec says a wildcard can be contained at any level not
            // just the left-most. As of Apr 2018 there are no examples of such a rule.
            // According to https://github.com/publicsuffix/list/issues/145 it is 
            // highly likely that we will never need to implement support for this and
            // that the offical spec will be changed to match the reality of our
            // current implementation.

            //  Parse the rule and set properties accordingly:
            if (RuleInfo.StartsWith("*", StringComparison.InvariantCultureIgnoreCase))
            {
                this.Type = RuleType.Wildcard;
                this.Name = RuleInfo.Substring(2);
            }
            else if (RuleInfo.StartsWith("!", StringComparison.InvariantCultureIgnoreCase))
            {
                this.Type = RuleType.Exception;
                this.Name = RuleInfo.Substring(1);
            }
            else
            {
                this.Type = RuleType.Normal;
                this.Name = RuleInfo;
            }
        }

        #region IComparable<TLDRule> Members

        public int CompareTo(TLDRule other)
        {
            if (other == null)
                return -1;

            return Name.CompareTo(other.Name);
        }

        #endregion

        #region RuleType enum
        
        /// <summary>
        /// TLD Rule type
        /// </summary>
        public enum RuleType
        {
            /// <summary>
            /// An exception rule, as defined by www.publicsuffix.org
            /// </summary>
            Exception,

            /// <summary>
            /// A wildcard rule, as defined by www.publicsuffix.org
            /// </summary>
            Wildcard,

            /// <summary>
            /// A normal rule
            /// </summary>
            Normal
        }

        #endregion
    }
}
{'fraction_non_alphanumeric': 0.09919820995711355, 'fraction_numerical': 0.0033563304120827896, 'mean_word_length': 1.2312811980033278, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 1, 'lorem ipsum': 0, 'www.': 6, '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': '7367684', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1313, 'n_words': 392}