[Style] Unroll regex (thanks to edc for the code)

This commit is contained in:
Matt Nadareski
2017-03-17 10:14:22 -07:00
parent ca9821aea0
commit e5db964712

View File

@@ -71,6 +71,24 @@ namespace SabreTools.Helper.Tools
hash = (String.IsNullOrEmpty(hash) ? "" : hash.PadLeft(padding, '0')); hash = (String.IsNullOrEmpty(hash) ? "" : hash.PadLeft(padding, '0'));
hash = hash.ToLowerInvariant(); hash = hash.ToLowerInvariant();
// If the hash still isn't the right length, blank it out
if (hash.Length != padding)
{
hash = "";
}
// Otherwise, make sure that every character is a proper match
else
{
for (int i = 0; i < hash.Length; i++)
{
if ((hash[i] < '0' || hash[i] > '9') && (hash[i] < 'a' || hash[i] > 'f'))
{
hash = "";
break;
}
}
}
// Then make sure that it has the correct characters // Then make sure that it has the correct characters
if (!Regex.IsMatch(hash, "[0-9a-f]{" + padding + "}")) if (!Regex.IsMatch(hash, "[0-9a-f]{" + padding + "}"))
{ {