Reuse XFL wire scalar parsers

This commit is contained in:
Dylan M. Taylor
2026-11-15 02:46:16 +00:00
parent bb0c1c52ce
commit 01815214d6
3 changed files with 5 additions and 21 deletions
+3 -3
View File
@@ -93,15 +93,15 @@ impl Matrix {
pub const IDENTITY: Matrix = Matrix { a: 1.0, b: 0.0, c: 0.0, d: 1.0, tx: 0.0, ty: 0.0 };
}
fn number(element: &impl XflElement, name: &str) -> Option<f32> {
pub(crate) fn number(element: &impl XflElement, name: &str) -> Option<f32> {
element.attr(name)?.trim().parse::<f32>().ok().filter(|value| value.is_finite())
}
fn integer(element: &impl XflElement, name: &str) -> Option<u32> {
pub(crate) fn integer(element: &impl XflElement, name: &str) -> Option<u32> {
element.attr(name)?.trim().parse::<u32>().ok()
}
fn boolean(element: &impl XflElement, name: &str) -> Option<bool> {
pub(crate) fn boolean(element: &impl XflElement, name: &str) -> Option<bool> {
element.attr(name).map(|value| value.trim() == "true")
}
+1 -9
View File
@@ -3,7 +3,7 @@
//! These parse the native point encodings and hint ordering. Snapping points onto consumer
//! geometry and pairing start/end keyframes remain application responsibilities.
use crate::shape::XflElement;
use crate::shape::{XflElement, integer, number};
/// A native XFL point in document coordinates.
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -77,14 +77,6 @@ fn read_point(element: &impl XflElement, joined: &str, x: &str, y: &str) -> Opti
(point.x.is_finite() && point.y.is_finite()).then_some(point)
}
fn number(element: &impl XflElement, name: &str) -> Option<f32> {
element.attr(name)?.trim().parse::<f32>().ok().filter(|value| value.is_finite())
}
fn integer(element: &impl XflElement, name: &str) -> Option<u32> {
element.attr(name)?.trim().parse::<u32>().ok()
}
#[cfg(test)]
mod tests {
use super::*;
+1 -9
View File
@@ -3,7 +3,7 @@
//! This parses the native attributes and point lists. Interpreting easing curves and applying
//! them to an application's timeline model remain consumer responsibilities.
use crate::shape::XflElement;
use crate::shape::{XflElement, boolean, number};
/// Native motion/shape tween settings on a `DOMFrame`.
#[derive(Clone, Copy, Debug)]
@@ -78,14 +78,6 @@ impl<E: XflElement> EasePoint<'_, E> {
}
}
fn number(element: &impl XflElement, name: &str) -> Option<f32> {
element.attr(name)?.trim().parse::<f32>().ok().filter(|value| value.is_finite())
}
fn boolean(element: &impl XflElement, name: &str) -> Option<bool> {
element.attr(name).map(|value| value.trim() == "true")
}
#[cfg(test)]
mod tests {
use super::*;