diff options
author | gennyble <gen@nyble.dev> | 2024-12-18 00:27:34 -0600 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2024-12-18 00:27:34 -0600 |
commit | 5ea6a13ead2a5cab0f578c8af5f0e0be88c3a08c (patch) | |
tree | f8ab97a0abeb03142da4c7a8ed859d6a408cd16a /src/tag.rs | |
parent | f6b441fe53dd75af5933c4456d92070ccb7bd8af (diff) | |
download | cutie-main.tar.gz cutie-main.zip |
Diffstat (limited to 'src/tag.rs')
-rwxr-xr-x[-rw-r--r--] | src/tag.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/tag.rs b/src/tag.rs index 0a97061..43c4e0c 100644..100755 --- 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<Attribute<'body>> { + 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<P>(iter: &mut Peekable<CharIndices>, mut predicate: P) +where + P: FnMut(&char) -> bool, +{ + loop { + match iter.peek() { + Some((_, c)) if predicate(c) => { + iter.next(); + } + _ => break, + } + } } |