diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-02-11 19:20:24 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-11 21:38:27 +0100 |
commit | 44b64cb8b01c0712b3262e578934ac0f134353d1 (patch) | |
tree | 673fe39c6d5d2364985049a55cc0a35dd7dfa1f4 /Userland/Libraries/LibWeb | |
parent | ab440b3e5010d08e6e88bd10813a311f46507dd0 (diff) | |
download | serenity-44b64cb8b01c0712b3262e578934ac0f134353d1.zip |
LibWeb: Make SVG AttributeParser::parse_path_data() static
This is mostly a style thing, but it matches the other APIs.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/AttributeParser.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/AttributeParser.h | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp | 2 |
3 files changed, 14 insertions, 12 deletions
diff --git a/Userland/Libraries/LibWeb/SVG/AttributeParser.cpp b/Userland/Libraries/LibWeb/SVG/AttributeParser.cpp index fcefba110c..1a4da9a857 100644 --- a/Userland/Libraries/LibWeb/SVG/AttributeParser.cpp +++ b/Userland/Libraries/LibWeb/SVG/AttributeParser.cpp @@ -16,14 +16,17 @@ AttributeParser::AttributeParser(StringView source) { } -Vector<PathInstruction> AttributeParser::parse_path_data() +Vector<PathInstruction> AttributeParser::parse_path_data(StringView input) { - parse_whitespace(); - while (!done()) - parse_drawto(); - if (!m_instructions.is_empty() && m_instructions[0].type != PathInstructionType::Move) - VERIFY_NOT_REACHED(); - return m_instructions; + AttributeParser parser { input }; + parser.parse_whitespace(); + while (!parser.done()) + parser.parse_drawto(); + if (!parser.m_instructions.is_empty() && parser.m_instructions[0].type != PathInstructionType::Move) { + // Invalid. "A path data segment (if there is one) must begin with a "moveto" command." + return {}; + } + return parser.m_instructions; } Optional<float> AttributeParser::parse_coordinate(StringView input) diff --git a/Userland/Libraries/LibWeb/SVG/AttributeParser.h b/Userland/Libraries/LibWeb/SVG/AttributeParser.h index 55b152750c..d276a2c9bc 100644 --- a/Userland/Libraries/LibWeb/SVG/AttributeParser.h +++ b/Userland/Libraries/LibWeb/SVG/AttributeParser.h @@ -35,19 +35,18 @@ struct PathInstruction { class AttributeParser final { public: - AttributeParser(StringView source); ~AttributeParser() = default; - Vector<PathInstruction> parse_path_data(); - static Optional<float> parse_coordinate(StringView input); static Optional<float> parse_length(StringView input); static Optional<float> parse_positive_length(StringView input); static Vector<Gfx::FloatPoint> parse_points(StringView input); + static Vector<PathInstruction> parse_path_data(StringView input); private: - void parse_drawto(); + AttributeParser(StringView source); + void parse_drawto(); void parse_moveto(); void parse_closepath(); void parse_lineto(); diff --git a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp index bf64a60271..8387f031b2 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp @@ -93,7 +93,7 @@ void SVGPathElement::parse_attribute(const FlyString& name, const String& value) SVGGeometryElement::parse_attribute(name, value); if (name == "d") - m_instructions = AttributeParser(value).parse_path_data(); + m_instructions = AttributeParser::parse_path_data(value); } Gfx::Path& SVGPathElement::get_path() |