1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 16:47:42 +00:00

LibWeb: Make SVG AttributeParser::parse_path_data() static

This is mostly a style thing, but it matches the other APIs.
This commit is contained in:
Sam Atkins 2022-02-11 19:20:24 +00:00 committed by Andreas Kling
parent ab440b3e50
commit 44b64cb8b0
3 changed files with 14 additions and 12 deletions

View file

@ -16,14 +16,17 @@ AttributeParser::AttributeParser(StringView source)
{ {
} }
Vector<PathInstruction> AttributeParser::parse_path_data() Vector<PathInstruction> AttributeParser::parse_path_data(StringView input)
{ {
parse_whitespace(); AttributeParser parser { input };
while (!done()) parser.parse_whitespace();
parse_drawto(); while (!parser.done())
if (!m_instructions.is_empty() && m_instructions[0].type != PathInstructionType::Move) parser.parse_drawto();
VERIFY_NOT_REACHED(); if (!parser.m_instructions.is_empty() && parser.m_instructions[0].type != PathInstructionType::Move) {
return m_instructions; // 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) Optional<float> AttributeParser::parse_coordinate(StringView input)

View file

@ -35,19 +35,18 @@ struct PathInstruction {
class AttributeParser final { class AttributeParser final {
public: public:
AttributeParser(StringView source);
~AttributeParser() = default; ~AttributeParser() = default;
Vector<PathInstruction> parse_path_data();
static Optional<float> parse_coordinate(StringView input); static Optional<float> parse_coordinate(StringView input);
static Optional<float> parse_length(StringView input); static Optional<float> parse_length(StringView input);
static Optional<float> parse_positive_length(StringView input); static Optional<float> parse_positive_length(StringView input);
static Vector<Gfx::FloatPoint> parse_points(StringView input); static Vector<Gfx::FloatPoint> parse_points(StringView input);
static Vector<PathInstruction> parse_path_data(StringView input);
private: private:
void parse_drawto(); AttributeParser(StringView source);
void parse_drawto();
void parse_moveto(); void parse_moveto();
void parse_closepath(); void parse_closepath();
void parse_lineto(); void parse_lineto();

View file

@ -93,7 +93,7 @@ void SVGPathElement::parse_attribute(const FlyString& name, const String& value)
SVGGeometryElement::parse_attribute(name, value); SVGGeometryElement::parse_attribute(name, value);
if (name == "d") if (name == "d")
m_instructions = AttributeParser(value).parse_path_data(); m_instructions = AttributeParser::parse_path_data(value);
} }
Gfx::Path& SVGPathElement::get_path() Gfx::Path& SVGPathElement::get_path()