From e5db964712c7bf93e87e5e9bb7cb88abb21ced56 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 17 Mar 2017 10:14:22 -0700 Subject: [PATCH] [Style] Unroll regex (thanks to edc for the code) --- SabreTools.Helper/Tools/Style.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/SabreTools.Helper/Tools/Style.cs b/SabreTools.Helper/Tools/Style.cs index c2e6021d..66d93610 100644 --- a/SabreTools.Helper/Tools/Style.cs +++ b/SabreTools.Helper/Tools/Style.cs @@ -71,6 +71,24 @@ namespace SabreTools.Helper.Tools hash = (String.IsNullOrEmpty(hash) ? "" : hash.PadLeft(padding, '0')); 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 if (!Regex.IsMatch(hash, "[0-9a-f]{" + padding + "}")) {