using System.Collections.Generic; using System.Linq; namespace molilian.core { public static class AccountWarningConfigCore { private static readonly char[] Separators = new[] { '\r', '\n', ',', ',', ';', ';' }; public static Dictionary> FilterStats( string platform, Dictionary> stats, string? ignoredGroups) { if (stats == null || stats.Count == 0) return stats ?? new Dictionary>(); HashSet rules = ParseIgnoredGroups(ignoredGroups); if (rules.Count == 0) return stats; string normalizedPlatform = NormalizeToken(platform); return stats .Where(item => !ShouldIgnore(rules, normalizedPlatform, item.Key)) .ToDictionary(item => item.Key, item => item.Value); } private static bool ShouldIgnore(HashSet rules, string platform, string groupKey) { string normalizedGroup = NormalizeToken(groupKey); if (string.IsNullOrEmpty(normalizedGroup)) return false; return rules.Contains(normalizedGroup) || rules.Contains($"{platform}:{normalizedGroup}"); } private static HashSet ParseIgnoredGroups(string? ignoredGroups) { if (string.IsNullOrWhiteSpace(ignoredGroups)) { return new HashSet(System.StringComparer.OrdinalIgnoreCase); } return ignoredGroups .Split(Separators, System.StringSplitOptions.RemoveEmptyEntries | System.StringSplitOptions.TrimEntries) .Select(NormalizeToken) .Where(item => !string.IsNullOrEmpty(item) && !item.StartsWith("#")) .ToHashSet(System.StringComparer.OrdinalIgnoreCase); } private static string NormalizeToken(string? value) { return string.IsNullOrWhiteSpace(value) ? string.Empty : value.Trim().ToLowerInvariant(); } } }