svg_path/transform/parse

SVG transform attribute parser.

This module parses SVG transform lists such as translate(10 20)rotate(30)scale(2). Commas are accepted where SVG allows separators, and adjacent signed numbers such as translate(10-20) are handled.

Types

Errors returned while parsing an SVG transform attribute.

pub type Error {
  ParseError(reason: ErrorReason, remaining: String)
}

Constructors

  • ParseError(reason: ErrorReason, remaining: String)

    Parsing failed for reason at the start of remaining.

    remaining is the exact suffix of the original input beginning at the failure location. It is empty when the failure is at end of input. A UTF-8 byte offset can be recovered by subtracting the byte size of remaining from the byte size of the original input.

The reason SVG transform parsing failed.

pub type ErrorReason {
  ExpectedClose
  ExpectedOpen
  ExpectedTransform
  InvalidArgumentCount(String, Int)
  InvalidNumber(String)
  UnexpectedToken(String)
  UnknownTransform(String)
}

Constructors

  • ExpectedClose

    A closing parenthesis was expected.

  • ExpectedOpen

    An opening parenthesis was expected.

  • ExpectedTransform

    A transform function name was expected.

  • InvalidArgumentCount(String, Int)

    A transform function received the wrong number of arguments.

  • InvalidNumber(String)

    A numeric token could not be parsed as a float.

  • UnexpectedToken(String)

    A token appeared where it is not valid.

  • UnknownTransform(String)

    The transform function is not part of SVG’s supported transform set.

Values

pub fn attribute(
  input: String,
) -> Result(transform.Matrix, Error)

Parse an SVG transform attribute into a matrix.

Empty strings parse as the identity matrix.

Search Document