Crates.io | svg-path-cst |
lib.rs | svg-path-cst |
version | |
source | src |
created_at | 2023-11-01 02:49:55.229034+00 |
updated_at | 2025-01-20 18:53:14.131783+00 |
description | CST SVG path parser. |
homepage | |
repository | https://github.com/mondeja/svg-path-cst |
max_upload_size | |
id | 1020592 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Concrete Syntax Tree parser for SVG v1.1 paths.
cargo add svg-path-cst
use svg_path_cst::{
svg_path_cst,
SVGPathCSTNode,
SVGPathSegment,
SVGPathCommand,
WSP,
Sign,
SyntaxError,
};
let cst: Result<Vec<SVGPathCSTNode>, SyntaxError> = svg_path_cst(b"m0 0 L1,-1");
let expected_cst: Vec<SVGPathCSTNode> = vec![
SVGPathCSTNode::Segment(SVGPathSegment{
command: &SVGPathCommand::MovetoLower,
args: vec![0.0, 0.0],
start: 0,
end: 4,
chained: false,
chain_start: 0,
chain_end: 4,
cst: vec![
SVGPathCSTNode::Command(&SVGPathCommand::MovetoLower),
SVGPathCSTNode::Number{
raw_number: "0".to_string(),
value: 0.0,
start: 1,
end: 2,
},
SVGPathCSTNode::Whitespace{
wsp: &WSP::Space,
start: 2,
end: 3,
},
SVGPathCSTNode::Number{
raw_number: "0".to_string(),
value: 0.0,
start: 3,
end: 4,
},
],
}),
SVGPathCSTNode::Whitespace{
wsp: &WSP::Space,
start: 4,
end: 5,
},
SVGPathCSTNode::Segment(SVGPathSegment{
command: &SVGPathCommand::LinetoUpper,
args: vec![1.0, -1.0],
start: 5,
end: 10,
chained: false,
chain_start: 5,
chain_end: 10,
cst: vec![
SVGPathCSTNode::Command(&SVGPathCommand::LinetoUpper),
SVGPathCSTNode::Number{
raw_number: "1".to_string(),
value: 1.0,
start: 6,
end: 7,
},
SVGPathCSTNode::Comma{ start: 7 },
SVGPathCSTNode::Sign{ sign: &Sign::Minus, start: 8 },
SVGPathCSTNode::Number{
raw_number: "1".to_string(),
value: 1.0,
start: 9,
end: 10,
},
],
}),
];
assert_eq!(cst, Ok(expected_cst));
This crate is compatible with SVG v1.1 paths, as defined in the W3C SVG 1.1
and no_std
environments.
Minimum Supported Rust Version: 1.61.0
tracing
Add tracing
support. See the tracing
example to learn how to use it.
strict
Enable strict mode. The differences between strict and non-strict modes are:
b""
), non-strict mode returns an empty vector, while
strict mode returns a SyntaxError::UnexpectedEnding
error.b"none"
, non-strict mode returns a SVGPathCSTNode::None
node, while strict mode returns a SyntaxError::ExpectedMovetoCommand
error.
The "none"
input is defined
by the SVG specification.SyntaxError::ExpectedMovetoCommand
error.