Implement a function to read the name from the affiliated keywords.

This commit is contained in:
Tom Alexander 2023-10-04 21:12:06 -04:00
parent ab4a0c1224
commit 5b308ea76f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,8 @@
#+NAME: foo
bar
#+NaMe: baz
cat
#+name: lorem
ipsum

View File

@ -22,6 +22,7 @@ use crate::error::CustomError;
use crate::error::MyError; use crate::error::MyError;
use crate::error::Res; use crate::error::Res;
use crate::types::IndentationLevel; use crate::types::IndentationLevel;
use crate::types::Keyword;
pub(crate) const WORD_CONSTITUENT_CHARACTERS: &str = pub(crate) const WORD_CONSTITUENT_CHARACTERS: &str =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
@ -275,3 +276,14 @@ pub(crate) fn indentation_level<'b, 'g, 'r, 's>(
.sum(); .sum();
Ok((remaining, (indentation_level, leading_whitespace))) Ok((remaining, (indentation_level, leading_whitespace)))
} }
pub(crate) fn get_name<'s>(affiliated_keywords: &Vec<Keyword<'s>>) -> Option<&'s str> {
let name_keyword = affiliated_keywords
.iter()
.filter(|kw| match kw.name {
Some(name) if name.eq_ignore_ascii_case("name") => true,
_ => false,
})
.last();
name_keyword.map(|kw| kw.value)
}