diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2020-07-30 04:25:07 -0400 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2020-09-01 02:07:35 -0400 |
commit | a6ff389a5525826dee146ba5345d9306f4bd9790 (patch) | |
tree | aefb904848e7860088cd6fdc6b9a9939dae45537 /modules/mono | |
parent | ecd6a893b49953d57bffd963bb35ff79066b62db (diff) |
Simplify html_is_valid and allow it to work with 3 and 4 hex digits
Diffstat (limited to 'modules/mono')
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs index 238f10aaf1..3700a6194f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs @@ -827,46 +827,24 @@ namespace Godot if (color[0] == '#') { - color = color.Substring(1, color.Length - 1); + color = color.Substring(1); } - bool alpha; - - switch (color.Length) + // Check if the amount of hex digits is valid. + int len = color.Length; + if (!(len == 3 || len == 4 || len == 6 || len == 8)) { - case 8: - alpha = true; - break; - case 6: - alpha = false; - break; - default: - return false; + return false; } - if (alpha) - { - if (ParseCol8(color, 0) < 0) + // Check if each hex digit is valid. + for (int i = 0; i < len; i++) { + if (ParseCol4(color, i) == -1) { return false; } } - int from = alpha ? 2 : 0; - - if (ParseCol8(color, from + 0) < 0) - { - return false; - } - if (ParseCol8(color, from + 2) < 0) - { - return false; - } - if (ParseCol8(color, from + 4) < 0) - { - return false; - } - return true; } |