using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace SabreTools.Core.Tools { public static class Sanitizer { /// /// Get a sanitized size from an input string /// /// String to get value from /// Size as a long?, if possible public static long? CleanLong(string input) { long? size = null; if (input != null && input.Contains("0x")) size = Convert.ToInt64(input, 16); else if (input != null) { if (Int64.TryParse(input, out long longSize)) size = longSize; } return size; } /// /// Remove all chars that are considered path unsafe /// /// Input string to clean /// Cleaned string public static string RemovePathUnsafeCharacters(string s) { List invalidPath = Path.GetInvalidPathChars().ToList(); return new string(s.Where(c => !invalidPath.Contains(c)).ToArray()); } } }