Browse Source

LibGfx: Make parse_rgba_color use the new double parser

Since this is used by LibWeb when parsing CSS colors we should not use
strtod here.
davidot 2 years ago
parent
commit
051134a21e
1 changed files with 7 additions and 1 deletions
  1. 7 1
      Userland/Libraries/LibGfx/Color.cpp

+ 7 - 1
Userland/Libraries/LibGfx/Color.cpp

@@ -5,6 +5,7 @@
  */
  */
 
 
 #include <AK/Assertions.h>
 #include <AK/Assertions.h>
+#include <AK/FloatingPointStringConversions.h>
 #include <AK/Optional.h>
 #include <AK/Optional.h>
 #include <AK/String.h>
 #include <AK/String.h>
 #include <AK/Vector.h>
 #include <AK/Vector.h>
@@ -63,7 +64,12 @@ static Optional<Color> parse_rgba_color(StringView string)
     auto g = parts[1].to_int().value_or(256);
     auto g = parts[1].to_int().value_or(256);
     auto b = parts[2].to_int().value_or(256);
     auto b = parts[2].to_int().value_or(256);
 
 
-    double alpha = strtod(parts[3].to_string().characters(), nullptr);
+    double alpha = 0;
+    char const* start = parts[3].characters_without_null_termination();
+    auto alpha_result = parse_first_floating_point(start, start + parts[3].length());
+    if (alpha_result.parsed_value())
+        alpha = alpha_result.value;
+
     unsigned a = alpha * 255;
     unsigned a = alpha * 255;
 
 
     if (r > 255 || g > 255 || b > 255 || a > 255)
     if (r > 255 || g > 255 || b > 255 || a > 255)