From: Ian Jackson Date: Sun, 15 May 2022 11:36:50 +0000 (+0100) Subject: subst: Demote PerhapsSubst X-Git-Tag: otter-1.1.0~127 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f4b842aac4fb4039fcaad65ec3bc79085da2becd;p=otter.git 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 --- 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)>