From a20c91ccc344d8eceb40a63046e88ba68cf1f0b2 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 21 Sep 2017 15:52:50 +1000 Subject: [PATCH] Get rid of duplication FastColour.Parse and FastColour.TryParse --- ClassicalSharp/2D/Utils/FastColour.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/ClassicalSharp/2D/Utils/FastColour.cs b/ClassicalSharp/2D/Utils/FastColour.cs index 5fe113c21..0fff43e32 100644 --- a/ClassicalSharp/2D/Utils/FastColour.cs +++ b/ClassicalSharp/2D/Utils/FastColour.cs @@ -192,16 +192,11 @@ namespace ClassicalSharp { if (input == null || input.Length < 6) return false; try { - int i = input.Length > 6 ? 1 : 0; - if (input.Length > 6 && (input[0] != '#' || input.Length > 7)) - return false; - - int r = Utils.ParseHex(input[i + 0]) * 16 + Utils.ParseHex(input[i + 1]); - int g = Utils.ParseHex(input[i + 2]) * 16 + Utils.ParseHex(input[i + 3]); - int b = Utils.ParseHex(input[i + 4]) * 16 + Utils.ParseHex(input[i + 5]); - value = new FastColour(r, g, b); + if (input.Length > 6 && (input[0] != '#' || input.Length > 7)) return false; + value = Parse(input); return true; } catch (FormatException) { + value = default(FastColour); return false; } }