using System; using System.IO; namespace PKHeX.Core; public static partial class Util { /// /// Cleans the local by removing any invalid filename characters. /// /// New string without any invalid characters. public static string CleanFileName(string fileName) { Span result = stackalloc char[fileName.Length]; int ctr = GetCleanFileName(fileName, result); if (ctr == fileName.Length) return fileName; return new string(result[..ctr]); } private static int GetCleanFileName(ReadOnlySpan input, Span output) { ReadOnlySpan invalid = Path.GetInvalidFileNameChars(); int ctr = 0; foreach (var c in input) { if (!invalid.Contains(c)) output[ctr++] = c; } return ctr; } }