50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
|
|
namespace IRCStates
|
|
{
|
|
public class ISupportPrefix
|
|
{
|
|
/// <summary>
|
|
/// Split the prefix value and add them to our known <see cref="Modes"/> and <see cref="Prefixes"/>
|
|
/// </summary>
|
|
/// <param name="splitVal"></param>
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
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; }
|
|
public List<string> Prefixes { get; }
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|