1use crate::attribute::{find_opening_tag, get_attribute};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct SvgPath {
5 pub data: String,
6}
7
8impl SvgPath {
9 #[must_use]
10 pub fn new(data: impl Into<String>) -> Self {
11 Self { data: data.into() }
12 }
13}
14
15#[must_use]
16pub fn extract_paths(input: &str) -> Vec<SvgPath> {
17 extract_path_data(input)
18 .into_iter()
19 .map(SvgPath::new)
20 .collect()
21}
22
23#[must_use]
24pub fn extract_path_data(input: &str) -> Vec<String> {
25 let cleaned = crate::normalize::strip_comments(input);
26 let mut values = Vec::new();
27 let mut index = 0;
28
29 while let Some((start, end)) = find_opening_tag(cleaned.as_str(), "path", index) {
30 let tag = &cleaned[start..end];
31 if let Some(value) = get_attribute(tag, "d") {
32 values.push(value);
33 }
34 index = end;
35 }
36
37 values
38}