From 5b308ea76f06218ff3bd1cb835b05cb1103d72f0 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 4 Oct 2023 21:12:06 -0400 Subject: [PATCH] Implement a function to read the name from the affiliated keywords. --- .../affiliated_keyword/case_insensitive.org | 8 ++++++++ src/parser/util.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 org_mode_samples/affiliated_keyword/case_insensitive.org diff --git a/org_mode_samples/affiliated_keyword/case_insensitive.org b/org_mode_samples/affiliated_keyword/case_insensitive.org new file mode 100644 index 0000000..33ea9e2 --- /dev/null +++ b/org_mode_samples/affiliated_keyword/case_insensitive.org @@ -0,0 +1,8 @@ +#+NAME: foo +bar + +#+NaMe: baz +cat + +#+name: lorem +ipsum diff --git a/src/parser/util.rs b/src/parser/util.rs index 7c5d733..8f63eaf 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -22,6 +22,7 @@ use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::types::IndentationLevel; +use crate::types::Keyword; pub(crate) const WORD_CONSTITUENT_CHARACTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; @@ -275,3 +276,14 @@ pub(crate) fn indentation_level<'b, 'g, 'r, 's>( .sum(); Ok((remaining, (indentation_level, leading_whitespace))) } + +pub(crate) fn get_name<'s>(affiliated_keywords: &Vec>) -> 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) +}