From f4b842aac4fb4039fcaad65ec3bc79085da2becd Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 15 May 2022 12:36:50 +0100 Subject: [PATCH] subst: Demote PerhapsSubst Reverts subst: Promote PerhapsSubst We shouldn't do this for anything but colour specs. And, really, we ought to do it only for the item name and not for the other things, or the ${$} de-escaping is very confusing. Signed-off-by: Ian Jackson --- src/shapelib.rs | 60 ++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/shapelib.rs b/src/shapelib.rs index 9fa1c9c4..ce657ce4 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -1189,36 +1189,6 @@ fn format_item_name(mformat: materials_format::Version, ) } -#[derive(Debug,From,Clone)] -enum PerhapsSubst<'i> { - Y(Substituting<'i>), - N(&'i str), -} -impl<'i> From<&'i String> for PerhapsSubst<'i> { - fn from(s: &'i String) -> Self { (&**s).into() } -} - -impl<'i> PerhapsSubst<'i> { - #[throws(SubstError)] - pub fn finish(self) -> String { match self { - PerhapsSubst::N(s) => s.to_owned(), - PerhapsSubst::Y(s) => s.finish()?, - } } - #[throws(SubstError)] - pub fn nest(self) -> String { match self { - PerhapsSubst::N(s) => s.to_owned(), - PerhapsSubst::Y(s) => s.nest()?, - } } - pub fn mky( - self, - mformat: materials_format::Version, - dollars: Dollars, - ) -> Substituting<'i> { match self { - PerhapsSubst::N(s) => Substituting::new(mformat, dollars, s), - PerhapsSubst::Y(s) => s, - } } -} - #[throws(LibraryLoadError)] fn process_files_entry( src: &mut dyn LibrarySvgNoter, l: &mut Catalogue, @@ -1270,6 +1240,36 @@ fn process_files_entry( }, }; + #[derive(Debug,From,Clone)] + enum PerhapsSubst<'i> { + Y(Substituting<'i>), + N(&'i str), + } + impl<'i> From<&'i String> for PerhapsSubst<'i> { + fn from(s: &'i String) -> Self { (&**s).into() } + } + + impl<'i> PerhapsSubst<'i> { + #[throws(SubstError)] + pub fn finish(self) -> String { match self { + PerhapsSubst::N(s) => s.to_owned(), + PerhapsSubst::Y(s) => s.finish()?, + } } + #[throws(SubstError)] + pub fn nest(self) -> String { match self { + PerhapsSubst::N(s) => s.to_owned(), + PerhapsSubst::Y(s) => s.nest()?, + } } + pub fn mky( + self, + mformat: materials_format::Version, + dollars: Dollars, + ) -> Substituting<'i> { match self { + PerhapsSubst::N(s) => Substituting::new(mformat, dollars, s), + PerhapsSubst::Y(s) => s, + } } + } + fn colour_subst_1<'s, S>( mformat: materials_format::Version, subst: S, kv: Option<(&'static str, &'s str)> -- 2.30.2