1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
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
}
}
|