Empty the rest of Santizer into Utilities

This commit is contained in:
Matt Nadareski
2020-12-09 22:33:49 -08:00
parent 7e86b6914d
commit d4dce53906
24 changed files with 107 additions and 114 deletions

View File

@@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace SabreTools.Core.Tools
{
@@ -59,6 +62,26 @@ namespace SabreTools.Core.Tools
}
}
/// <summary>
/// Get a sanitized size from an input string
/// </summary>
/// <param name="input">String to get value from</param>
/// <returns>Size as a long?, if possible</returns>
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;
}
/// <summary>
/// Convert .NET DateTime to MS-DOS date format
/// </summary>
@@ -102,5 +125,16 @@ namespace SabreTools.Core.Tools
{
return (array == null || array.Length == 0);
}
/// <summary>
/// Remove all chars that are considered path unsafe
/// </summary>
/// <param name="s">Input string to clean</param>
/// <returns>Cleaned string</returns>
public static string RemovePathUnsafeCharacters(string s)
{
List<char> invalidPath = Path.GetInvalidPathChars().ToList();
return new string(s.Where(c => !invalidPath.Contains(c)).ToArray());
}
}
}