Fix handling capitalization in macro names.
All checks were successful
rust-build Build rust-build has succeeded
rust-test Build rust-test has succeeded
rust-foreign-document-test Build rust-foreign-document-test has succeeded

This commit is contained in:
Tom Alexander
2023-10-08 16:51:44 -04:00
parent 9bdec391f1
commit f07d041eb9
5 changed files with 34 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ use super::util::coalesce_whitespace_escaped;
use super::util::coalesce_whitespace_if_line_break;
use super::util::remove_line_break;
use super::util::remove_whitespace_if_line_break;
use super::util::to_lowercase;
use super::GetStandardProperties;
use super::StandardProperties;
@@ -149,12 +150,18 @@ pub struct AngleLink<'s> {
#[derive(Debug, PartialEq)]
pub struct OrgMacro<'s> {
pub source: &'s str,
pub macro_name: &'s str,
/// The macro args from the source.
/// The key from the source.
///
/// This does not take into account the post-processing that you would get from the upstream emacs org-mode AST. Use `get_macro_args` for an equivalent value.
pub macro_args: Vec<&'s str>,
pub macro_value: &'s str,
/// This does not take into account the post-processing that you would get from the upstream emacs org-mode AST. Use `get_key` for an equivalent value.
pub key: &'s str,
/// The args from the source.
///
/// This does not take into account the post-processing that you would get from the upstream emacs org-mode AST. Use `get_args` for an equivalent value.
pub args: Vec<&'s str>,
pub value: &'s str,
}
#[derive(Debug, PartialEq)]
@@ -739,8 +746,12 @@ impl<'s> AngleLink<'s> {
}
impl<'s> OrgMacro<'s> {
pub fn get_macro_args<'b>(&'b self) -> impl Iterator<Item = Cow<'s, str>> + 'b {
self.macro_args
pub fn get_key<'b>(&'b self) -> Cow<'s, str> {
to_lowercase(self.key)
}
pub fn get_args<'b>(&'b self) -> impl Iterator<Item = Cow<'s, str>> + 'b {
self.args
.iter()
.map(|arg| coalesce_whitespace_escaped('\\', |c| ",".contains(c))(*arg))
}

View File

@@ -451,6 +451,14 @@ enum CoalesceWhitespaceEscaped {
},
}
pub(crate) fn to_lowercase<'s>(input: &'s str) -> Cow<'s, str> {
if input.chars().any(|c| !c.is_lowercase()) {
Cow::Owned(input.to_lowercase())
} else {
Cow::Borrowed(input)
}
}
#[cfg(test)]
mod tests {
use super::*;