diff options
Diffstat (limited to 'IRCTokens/Hostmask.cs')
-rw-r--r-- | IRCTokens/Hostmask.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/IRCTokens/Hostmask.cs b/IRCTokens/Hostmask.cs new file mode 100644 index 0000000..2e1549a --- /dev/null +++ b/IRCTokens/Hostmask.cs @@ -0,0 +1,64 @@ +using System; + +namespace IRCTokens +{ + /// <summary> + /// Represents the three parts of a hostmask. Parse with the constructor. + /// </summary> + public class Hostmask : IEquatable<Hostmask> + { + private readonly string _source; + + public Hostmask(string source) + { + if (source == null) return; + + _source = source; + + if (source.Contains('@', StringComparison.Ordinal)) + { + var split = source.Split('@'); + + NickName = split[0]; + HostName = split[1]; + } + else + { + NickName = source; + } + + if (NickName.Contains('!', StringComparison.Ordinal)) + { + var userSplit = NickName.Split('!'); + NickName = userSplit[0]; + UserName = userSplit[1]; + } + } + + public string NickName { get; set; } + public string UserName { get; set; } + public string HostName { get; set; } + + public bool Equals(Hostmask other) + { + if (other == null) return false; + + return _source == other._source; + } + + public override string ToString() + { + return _source; + } + + public override int GetHashCode() + { + return _source.GetHashCode(StringComparison.Ordinal); + } + + public override bool Equals(object obj) + { + return Equals(obj as Hostmask); + } + } +} |