Fix handling capitalization in macro names.
This commit is contained in:
parent
9bdec391f1
commit
f07d041eb9
1
org_mode_samples/object/macro/capitalize.org
Normal file
1
org_mode_samples/object/macro/capitalize.org
Normal file
@ -0,0 +1 @@
|
||||
{{{Foo(Bar,Baz)}}}
|
@ -3077,20 +3077,20 @@ fn compare_org_macro<'b, 's>(
|
||||
rust,
|
||||
(
|
||||
EmacsField::Required(":key"),
|
||||
|r| Some(r.macro_name),
|
||||
|r| Some(r.get_key()),
|
||||
compare_property_quoted_string
|
||||
),
|
||||
(
|
||||
EmacsField::Required(":value"),
|
||||
|r| Some(r.macro_value),
|
||||
|r| Some(r.value),
|
||||
compare_property_quoted_string
|
||||
),
|
||||
(
|
||||
EmacsField::Required(":args"),
|
||||
|r| if r.macro_args.is_empty() {
|
||||
|r| if r.args.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(r.get_macro_args())
|
||||
Some(r.get_args())
|
||||
},
|
||||
compare_property_list_of_quoted_string
|
||||
)
|
||||
|
@ -37,13 +37,13 @@ pub(crate) fn org_macro<'b, 'g, 'r, 's>(
|
||||
remaining,
|
||||
OrgMacro {
|
||||
source: source.into(),
|
||||
macro_name: macro_name.into(),
|
||||
macro_args: macro_args
|
||||
key: macro_name.into(),
|
||||
args: macro_args
|
||||
.unwrap_or_else(|| Vec::with_capacity(0))
|
||||
.into_iter()
|
||||
.map(|arg| arg.into())
|
||||
.collect(),
|
||||
macro_value: Into::<&str>::into(macro_value),
|
||||
value: Into::<&str>::into(macro_value),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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::*;
|
||||
|
Loading…
Reference in New Issue
Block a user