using System.Runtime.ExceptionServices;

namespace skyscraper5.Skyscraper
{
	public static class StringExtensions
	{
		public static bool IsNaturalNumeric(this string str)
		{
			char[] charArray = str.ToCharArray();
			foreach (char c in charArray)
			{
				if (!char.IsDigit(c))
					return false;
			}

			return true;
		}

		public static string SanitizeFileName(this string str)
		{
			char[] invalidPathChars = Path.GetInvalidPathChars();
			char[] invalidFileNameChars = Path.GetInvalidFileNameChars();

			char[] charArray = str.ToCharArray();
			for (int i = 0; i < charArray.Length; i++)
			{
				if (invalidPathChars.Contains(charArray[i]))
				{
					charArray[i] = '_';
				}

				if (invalidFileNameChars.Contains(charArray[i]))
				{
					charArray[i] = '_';
				}
			}

			return new string(charArray);
		}
	}
}
