using System; using System.Collections.Generic; using System.Text.RegularExpressions; namespace SharpGen.Transform { public sealed partial class NamingRulesManager { private readonly List _expandShortName = new(); /// /// Adds the short name rule. /// /// Short name of the regex. /// Name of the expanded. public void AddShortNameRule(string regexShortName, string expandedName) { _expandShortName.Add(new ShortNameMapper(regexShortName, expandedName)); _expandShortName.Sort(); } private class ShortNameMapper : IComparable, IComparable { public ShortNameMapper(string regex, string replace) { Regex = new Regex("^" + regex); Replace = replace; HasRegexReplace = replace.Contains("$"); } public readonly Regex Regex; public readonly string Replace; public readonly bool HasRegexReplace; public int CompareTo(ShortNameMapper other) { return -Regex.ToString().Length.CompareTo((int) other.Regex.ToString().Length); } public int CompareTo(object obj) { return obj is ShortNameMapper mapper ? CompareTo(mapper) : throw new InvalidOperationException(); } } } }