From 5ea6a13ead2a5cab0f578c8af5f0e0be88c3a08c Mon Sep 17 00:00:00 2001 From: gennyble Date: Wed, 18 Dec 2024 00:27:34 -0600 Subject: Ahhhhh --- src/tag.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) mode change 100644 => 100755 src/tag.rs (limited to 'src/tag.rs') diff --git a/src/tag.rs b/src/tag.rs old mode 100644 new mode 100755 index 0a97061..43c4e0c --- a/src/tag.rs +++ b/src/tag.rs @@ -1,4 +1,5 @@ use core::fmt; +use std::{iter::Peekable, str::CharIndices}; use crate::Node; @@ -208,6 +209,8 @@ impl<'a> Iterator for TagIteratorMut<'a> { mod test { use crate::Tag; + use super::peek_skip_while; + #[test] fn tag_finds_boolen_attribute() { let tag = Tag { @@ -240,4 +243,54 @@ mod test { }; assert!(tag.get_attribute("contenteditable").is_some()); } + + // yes, this is a bad name. + #[test] + fn peek_skip_while_works() { + let str = "\t no whitespace"; + let mut chari = str.char_indices().peekable(); + + peek_skip_while(&mut chari, |c| c.is_whitespace()); + + let next_idx = chari.next().unwrap().0; + assert_eq!(&str[next_idx..], "no whitespace"); + } +} + +struct Attribute<'body> { + name: &'body str, + content: Option<&'body str>, + start: usize, + len: usize, +} + +fn find_attribute<'body>(body: &'body str, attribute: &str) -> Option> { + let mut chari = body.char_indices().peekable(); + + 'big: loop { + // skip whitespace + peek_skip_while(&mut chari, |c| c.is_whitespace()); + + let key_start = chari.next().unwrap(); + // find end of key + peek_skip_while(&mut chari, |c| c.is_alphanumeric()); + + let key_after = chari.next().unwrap(); + } + + todo!() +} + +fn peek_skip_while

(iter: &mut Peekable, mut predicate: P) +where + P: FnMut(&char) -> bool, +{ + loop { + match iter.peek() { + Some((_, c)) if predicate(c) => { + iter.next(); + } + _ => break, + } + } } -- cgit 1.4.1-3-g733a5