about summary refs log tree commit diff
path: root/IRCStates/ISupportPrefix.cs
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2020-05-14 23:06:10 -0400
committerBen Harris <ben@tilde.team>2020-05-14 23:17:47 -0400
commit21f1e95fb8e935134a969bc3d729964d8d2aadfa (patch)
treedb2be27e9b5ac48e19f92b56cbad68ab59f7099e /IRCStates/ISupportPrefix.cs
parent304df7805b9925c2edd992fd4177eef80197f807 (diff)
rename Irc to IRC
Diffstat (limited to 'IRCStates/ISupportPrefix.cs')
-rw-r--r--IRCStates/ISupportPrefix.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/IRCStates/ISupportPrefix.cs b/IRCStates/ISupportPrefix.cs
new file mode 100644
index 0000000..35c5344
--- /dev/null
+++ b/IRCStates/ISupportPrefix.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+
+namespace IRCStates
+{
+    public class ISupportPrefix
+    {
+        public ISupportPrefix(string splitVal)
+        {
+            if (splitVal == null) throw new ArgumentNullException(nameof(splitVal));
+
+            var split = splitVal.Substring(1).Split(')', 2);
+            Modes = new List<string>();
+            Modes.AddRange(split[0].Select(c => c.ToString(CultureInfo.InvariantCulture)));
+            Prefixes = new List<string>();
+            Prefixes.AddRange(split[1].Select(c => c.ToString(CultureInfo.InvariantCulture)));
+        }
+
+        public List<string> Modes { get; set; }
+        public List<string> Prefixes { get; set; }
+
+        public string FromMode(char mode)
+        {
+            return FromMode(mode.ToString(CultureInfo.InvariantCulture));
+        }
+
+        public string FromMode(string mode)
+        {
+            return Modes.Contains(mode) ? Prefixes[Modes.IndexOf(mode)] : null;
+        }
+
+        public string FromPrefix(char prefix)
+        {
+            return FromPrefix(prefix.ToString(CultureInfo.InvariantCulture));
+        }
+
+        public string FromPrefix(string prefix)
+        {
+            return Prefixes.Contains(prefix) ? Modes[Prefixes.IndexOf(prefix)] : null;
+        }
+    }
+}